mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Made Split to Nearby Query into a fast query for coordinates + a details query for each pin (#5731)
* Splitted the query * Made changes to the query * Improvised query * Improvised query by dividing in the batches * Fixed failing tests * Improved batches * Improved sorting * Fixes issue caused by search this area button * Fixed failing tests * Fixed unnecessary reloads on onResume * Fixed few pins not loading on changing apps * Improved zoom level and fixed the pins not loading from the center * Removed toggle chips and changed pin's color * Fixed wikidata url * Fixed unit tests * Implemented retry with delay of 5000ms * Fixed exception issue and pins issue * Added change color icon to pin * Improved pin clicking * Removed search this area button * Implemented caching of places * Fixed unit test * Factorized methods * Changed primary key from location to entity id * Fixed tests * Fixed conflicts * Fixed unit test * Fixed unit test * Fixed the bug * Fixed issue with pin loading on the first launch * Updated javadocs * Temporary commit - only for testing * Replaced Temporary commit * Temporary commit - Added jcenter * Made minor changes * Fixed unit tests * Fixed unit tests * Fixed minor bug
This commit is contained in:
parent
ba6c8fe8d0
commit
2d63f351ed
39 changed files with 1147 additions and 814 deletions
|
|
@ -84,9 +84,10 @@ fun place(
|
|||
category: String = "category",
|
||||
siteLinks: Sitelinks? = null,
|
||||
pic: String = "pic",
|
||||
exists: Boolean = false
|
||||
exists: Boolean = false,
|
||||
entityID: String = "entityID"
|
||||
): Place {
|
||||
return Place(lang, name, label, longDescription, latLng, category, siteLinks, pic, exists)
|
||||
return Place(lang, name, label, longDescription, latLng, category, siteLinks, pic, exists, entityID)
|
||||
}
|
||||
|
||||
fun entityId(wikiBaseEntityValue: WikiBaseEntityValue = wikiBaseEntityValue()) =
|
||||
|
|
|
|||
|
|
@ -27,19 +27,19 @@ import org.robolectric.annotation.Config
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class BookMarkLocationDaoTest {
|
||||
private val columns = arrayOf(COLUMN_NAME,
|
||||
COLUMN_LANGUAGE,
|
||||
COLUMN_DESCRIPTION,
|
||||
COLUMN_CATEGORY,
|
||||
COLUMN_LABEL_TEXT,
|
||||
COLUMN_LABEL_ICON,
|
||||
COLUMN_IMAGE_URL,
|
||||
COLUMN_WIKIPEDIA_LINK,
|
||||
COLUMN_WIKIDATA_LINK,
|
||||
COLUMN_COMMONS_LINK,
|
||||
COLUMN_LAT,
|
||||
COLUMN_LONG,
|
||||
COLUMN_PIC,
|
||||
COLUMN_EXISTS)
|
||||
COLUMN_LANGUAGE,
|
||||
COLUMN_DESCRIPTION,
|
||||
COLUMN_CATEGORY,
|
||||
COLUMN_LABEL_TEXT,
|
||||
COLUMN_LABEL_ICON,
|
||||
COLUMN_IMAGE_URL,
|
||||
COLUMN_WIKIPEDIA_LINK,
|
||||
COLUMN_WIKIDATA_LINK,
|
||||
COLUMN_COMMONS_LINK,
|
||||
COLUMN_LAT,
|
||||
COLUMN_LONG,
|
||||
COLUMN_PIC,
|
||||
COLUMN_EXISTS)
|
||||
private val client: ContentProviderClient = mock()
|
||||
private val database: SQLiteDatabase = mock()
|
||||
private val captor = argumentCaptor<ContentValues>()
|
||||
|
|
@ -64,7 +64,7 @@ class BookMarkLocationDaoTest {
|
|||
|
||||
|
||||
examplePlaceBookmark = Place("en", "placeName", exampleLabel, "placeDescription"
|
||||
, exampleLocation, "placeCategory", builder.build(),"picName",false)
|
||||
, exampleLocation, "placeCategory", builder.build(),"picName",false)
|
||||
testObject = BookmarkLocationsDao { client }
|
||||
}
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ class BookMarkLocationDaoTest {
|
|||
assertEquals(builder.build().wikipediaLink, it.siteLinks.wikipediaLink)
|
||||
assertEquals(builder.build().wikidataLink, it.siteLinks.wikidataLink)
|
||||
assertEquals(builder.build().commonsLink, it.siteLinks.commonsLink)
|
||||
assertEquals("picName",it.pic)
|
||||
assertEquals("picName", it.pic)
|
||||
assertEquals(false, it.exists)
|
||||
}
|
||||
}
|
||||
|
|
@ -110,8 +110,7 @@ class BookMarkLocationDaoTest {
|
|||
|
||||
var result = testObject.allBookmarksLocations
|
||||
|
||||
assertEquals(14,(result.size))
|
||||
|
||||
assertEquals(14, result.size)
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException::class)
|
||||
|
|
@ -143,7 +142,6 @@ class BookMarkLocationDaoTest {
|
|||
verify(mockCursor).close()
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun updateNewLocationBookmark() {
|
||||
whenever(client.insert(any(), any())).thenReturn(Uri.EMPTY)
|
||||
|
|
@ -163,7 +161,7 @@ class BookMarkLocationDaoTest {
|
|||
assertEquals(examplePlaceBookmark.siteLinks.wikipediaLink.toString(), cv.getAsString(COLUMN_WIKIPEDIA_LINK))
|
||||
assertEquals(examplePlaceBookmark.siteLinks.wikidataLink.toString(), cv.getAsString(COLUMN_WIKIDATA_LINK))
|
||||
assertEquals(examplePlaceBookmark.siteLinks.commonsLink.toString(), cv.getAsString(COLUMN_COMMONS_LINK))
|
||||
assertEquals(examplePlaceBookmark.pic.toString(), cv.getAsString(COLUMN_PIC))
|
||||
assertEquals(examplePlaceBookmark.pic, cv.getAsString(COLUMN_PIC))
|
||||
assertEquals(examplePlaceBookmark.exists.toString(), cv.getAsString(COLUMN_EXISTS))
|
||||
}
|
||||
}
|
||||
|
|
@ -204,7 +202,7 @@ class BookMarkLocationDaoTest {
|
|||
@Test
|
||||
fun cursorsAreClosedAfterFindLocationBookmarkQuery() {
|
||||
val mockCursor: Cursor = mock()
|
||||
whenever(client.query(any(), any(), any(), any(), anyOrNull())).thenReturn(mockCursor)
|
||||
whenever(client.query(any(), any(), anyOrNull(), any(), anyOrNull())).thenReturn(mockCursor)
|
||||
whenever(mockCursor.moveToFirst()).thenReturn(false)
|
||||
|
||||
testObject.findBookmarkLocation(examplePlaceBookmark)
|
||||
|
|
@ -215,14 +213,14 @@ class BookMarkLocationDaoTest {
|
|||
@Test
|
||||
fun migrateTableVersionFrom_v1_to_v2() {
|
||||
onUpdate(database, 1, 2)
|
||||
// Table didnt exist before v5
|
||||
// Table didn't exist before v5
|
||||
verifyNoInteractions(database)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun migrateTableVersionFrom_v2_to_v3() {
|
||||
onUpdate(database, 2, 3)
|
||||
// Table didnt exist before v5
|
||||
// Table didn't exist before v5
|
||||
verifyNoInteractions(database)
|
||||
}
|
||||
|
||||
|
|
@ -278,13 +276,26 @@ class BookMarkLocationDaoTest {
|
|||
verify(database).execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_exists STRING;")
|
||||
}
|
||||
|
||||
|
||||
private fun createCursor(rowCount: Int) = MatrixCursor(columns, rowCount).apply {
|
||||
|
||||
for (i in 0 until rowCount) {
|
||||
addRow(listOf("placeName", "en", "placeDescription", "placeCategory", exampleLabel.text, exampleLabel.icon,
|
||||
exampleUri, builder.build().wikipediaLink, builder.build().wikidataLink, builder.build().commonsLink,
|
||||
exampleLocation.latitude, exampleLocation.longitude, "picName", "placeExists"))
|
||||
private fun createCursor(rows: Int): Cursor {
|
||||
return MatrixCursor(columns, rows).apply {
|
||||
repeat(rows) {
|
||||
newRow().apply {
|
||||
add("placeName")
|
||||
add("en")
|
||||
add("placeDescription")
|
||||
add("placeCategory")
|
||||
add(Label.FOREST.text)
|
||||
add(Label.FOREST.icon)
|
||||
add("placeImage")
|
||||
add("wikipediaLink")
|
||||
add("wikidataLink")
|
||||
add("commonsLink")
|
||||
add(40.0)
|
||||
add(51.4)
|
||||
add("picName")
|
||||
add(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class BookmarkLocationControllerTest {
|
|||
val list = ArrayList<Place>()
|
||||
list.add(
|
||||
Place(
|
||||
"en", "a place", null, "a description", null, "a cat", null, null, true)
|
||||
"en", "a place", null, "a description", null, "a cat", null, null, true, "entityID")
|
||||
)
|
||||
list.add(
|
||||
Place(
|
||||
|
|
@ -44,7 +44,8 @@ class BookmarkLocationControllerTest {
|
|||
"another cat",
|
||||
null,
|
||||
null,
|
||||
true
|
||||
true,
|
||||
"entityID"
|
||||
)
|
||||
)
|
||||
return list
|
||||
|
|
|
|||
|
|
@ -86,7 +86,8 @@ class BookmarkLocationFragmentUnitTests {
|
|||
"a cat",
|
||||
null,
|
||||
null,
|
||||
true)
|
||||
true,
|
||||
"entityID")
|
||||
)
|
||||
return list
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,7 +132,8 @@ class NearbyControllerTest {
|
|||
"placeCategory",
|
||||
Sitelinks.Builder().build(),
|
||||
"picName",
|
||||
false
|
||||
false,
|
||||
"entityID"
|
||||
)
|
||||
val place2 = Place(
|
||||
"en",
|
||||
|
|
@ -143,7 +144,8 @@ class NearbyControllerTest {
|
|||
"placeCategory",
|
||||
Sitelinks.Builder().build(),
|
||||
"picName",
|
||||
false
|
||||
false,
|
||||
"entityID"
|
||||
)
|
||||
`when`(
|
||||
nearbyPlaces.radiusExpander(
|
||||
|
|
@ -183,7 +185,8 @@ class NearbyControllerTest {
|
|||
"placeCategory",
|
||||
Sitelinks.Builder().build(),
|
||||
"picName",
|
||||
false
|
||||
false,
|
||||
"entityID"
|
||||
)
|
||||
val place2 = Place(
|
||||
"en",
|
||||
|
|
@ -194,7 +197,8 @@ class NearbyControllerTest {
|
|||
"placeCategory",
|
||||
Sitelinks.Builder().build(),
|
||||
"picName",
|
||||
false
|
||||
false,
|
||||
"entityID"
|
||||
)
|
||||
`when`(
|
||||
nearbyPlaces.radiusExpander(
|
||||
|
|
@ -224,7 +228,8 @@ class NearbyControllerTest {
|
|||
"placeCategory",
|
||||
Sitelinks.Builder().build(),
|
||||
"picName",
|
||||
false
|
||||
false,
|
||||
"entityID"
|
||||
)
|
||||
val place2 = Place(
|
||||
"en",
|
||||
|
|
@ -235,7 +240,8 @@ class NearbyControllerTest {
|
|||
"placeCategory",
|
||||
Sitelinks.Builder().build(),
|
||||
"picName",
|
||||
false
|
||||
false,
|
||||
"entityID"
|
||||
)
|
||||
`when`(
|
||||
nearbyPlaces.radiusExpander(
|
||||
|
|
@ -275,7 +281,8 @@ class NearbyControllerTest {
|
|||
"placeCategory",
|
||||
Sitelinks.Builder().build(),
|
||||
"picName",
|
||||
false
|
||||
false,
|
||||
"entityID"
|
||||
)
|
||||
place.isMonument = true
|
||||
`when`(currentLatLng.latitude).thenReturn(0.0)
|
||||
|
|
@ -299,7 +306,8 @@ class NearbyControllerTest {
|
|||
"placeCategory",
|
||||
Sitelinks.Builder().build(),
|
||||
"picName",
|
||||
false
|
||||
false,
|
||||
"entityID"
|
||||
)
|
||||
place.isMonument = false
|
||||
`when`(currentLatLng.latitude).thenReturn(0.0)
|
||||
|
|
@ -323,7 +331,8 @@ class NearbyControllerTest {
|
|||
"placeCategory",
|
||||
Sitelinks.Builder().build(),
|
||||
"",
|
||||
false
|
||||
false,
|
||||
"entityID"
|
||||
)
|
||||
place.isMonument = false
|
||||
`when`(currentLatLng.latitude).thenReturn(0.0)
|
||||
|
|
@ -347,7 +356,8 @@ class NearbyControllerTest {
|
|||
"placeCategory",
|
||||
Sitelinks.Builder().build(),
|
||||
"",
|
||||
true
|
||||
true,
|
||||
"entityID"
|
||||
)
|
||||
place.isMonument = false
|
||||
`when`(currentLatLng.latitude).thenReturn(0.0)
|
||||
|
|
|
|||
|
|
@ -100,7 +100,6 @@ class NearbyParentFragmentPresenterTest {
|
|||
nearbyPresenter.lockUnlockNearby(true)
|
||||
nearbyPresenter.updateMapAndList(null)
|
||||
verify(nearbyParentFragmentView).disableFABRecenter()
|
||||
verifyNoMoreInteractions(nearbyParentFragmentView)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -114,7 +113,6 @@ class NearbyParentFragmentPresenterTest {
|
|||
nearbyPresenter.updateMapAndList(null)
|
||||
verify(nearbyParentFragmentView).enableFABRecenter()
|
||||
verify(nearbyParentFragmentView).isNetworkConnectionEstablished()
|
||||
verifyNoMoreInteractions(nearbyParentFragmentView)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -130,7 +128,6 @@ class NearbyParentFragmentPresenterTest {
|
|||
verify(nearbyParentFragmentView).isNetworkConnectionEstablished
|
||||
verify(nearbyParentFragmentView).lastMapFocus
|
||||
verify(nearbyParentFragmentView).mapCenter
|
||||
verifyNoMoreInteractions(nearbyParentFragmentView)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -206,22 +203,6 @@ class NearbyParentFragmentPresenterTest {
|
|||
verify(nearbyParentFragmentView).isNetworkConnectionEstablished()
|
||||
verify(nearbyParentFragmentView).getLastMapFocus()
|
||||
verify(nearbyParentFragmentView).getMapCenter()
|
||||
verifyNoMoreInteractions(nearbyParentFragmentView)
|
||||
}
|
||||
|
||||
/**
|
||||
* Test search this area button became visible after user moved the camera target to far
|
||||
* away from current target. Distance between these two point is 111.19 km, so our camera target
|
||||
* is at outside of previously searched region if we set latestSearchRadius below 111.19. Thus,
|
||||
* setSearchThisAreaButtonVisibility(true) should be verified.
|
||||
*/
|
||||
@Test @Ignore
|
||||
fun testSearchThisAreaButtonVisibleWhenMoveToFarPosition() {
|
||||
NearbyController.latestSearchLocation = Mockito.spy(LatLng(2.0, 1.0, 0.0F))
|
||||
// Distance between these two point is 111.19 km
|
||||
NearbyController.latestSearchRadius = 111.19 * 1000 // To meter
|
||||
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(true)
|
||||
verify(nearbyParentFragmentView).setSearchThisAreaButtonVisibility(true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -267,9 +248,6 @@ class NearbyParentFragmentPresenterTest {
|
|||
verify(nearbyParentFragmentView).filterMarkersByLabels(
|
||||
ArgumentMatchers.anyList(),
|
||||
ArgumentMatchers.anyBoolean(),
|
||||
ArgumentMatchers.anyBoolean(),
|
||||
ArgumentMatchers.anyBoolean(),
|
||||
ArgumentMatchers.anyBoolean(),
|
||||
ArgumentMatchers.anyBoolean()
|
||||
);
|
||||
verify(nearbyParentFragmentView).setRecyclerViewAdapterAllSelected()
|
||||
|
|
@ -285,9 +263,6 @@ class NearbyParentFragmentPresenterTest {
|
|||
verify(nearbyParentFragmentView).filterMarkersByLabels(
|
||||
any(),
|
||||
anyBoolean(),
|
||||
anyBoolean(),
|
||||
anyBoolean(),
|
||||
anyBoolean(),
|
||||
anyBoolean()
|
||||
);
|
||||
verifyNoMoreInteractions(nearbyParentFragmentView)
|
||||
|
|
@ -482,7 +457,7 @@ class NearbyParentFragmentPresenterTest {
|
|||
nearbyPlacesInfo.placeList = null
|
||||
|
||||
whenever(bookmarkLocationsDao.allBookmarksLocations).thenReturn(Collections.emptyList())
|
||||
nearbyPresenter.updateMapMarkers(nearbyPlacesInfo, true)
|
||||
nearbyPresenter.updateMapMarkers(nearbyPlacesInfo.placeList, latestLocation, true)
|
||||
Mockito.verify(nearbyParentFragmentView).updateMapMarkers(any())
|
||||
Mockito.verify(nearbyParentFragmentView).setProgressBarVisibility(false)
|
||||
Mockito.verify(nearbyParentFragmentView).updateListFragment(nearbyPlacesInfo.placeList)
|
||||
|
|
|
|||
|
|
@ -234,48 +234,6 @@ class NearbyParentFragmentUnitTest {
|
|||
verify(presenter, times(1)).onMapReady()
|
||||
}
|
||||
|
||||
@Test @Ignore
|
||||
@Throws(Exception::class)
|
||||
fun `test getIconFor bookmarked place in light theme`() {
|
||||
val place = mock(Place::class.java).apply {
|
||||
`when`(isMonument()).thenReturn(false)
|
||||
`when`(pic).thenReturn("")
|
||||
`when`(exists).thenReturn(true)
|
||||
}
|
||||
|
||||
val icon = Whitebox.invokeMethod<Int>(fragment, "getIconFor", place, true, false)
|
||||
Assert.assertEquals(R.drawable.ic_custom_map_marker_blue_bookmarked_dark, icon)
|
||||
}
|
||||
|
||||
@Test @Ignore
|
||||
@Throws(Exception::class)
|
||||
fun `test getIconFor non-bookmarked monument place`() {
|
||||
val place = mock(Place::class.java).apply {
|
||||
`when`(isMonument()).thenReturn(true)
|
||||
}
|
||||
|
||||
val icon = Whitebox.invokeMethod<Int>(fragment, "getIconFor", place, false, false)
|
||||
Assert.assertEquals(R.drawable.ic_custom_map_marker_monuments, icon)
|
||||
}
|
||||
|
||||
@Test @Ignore
|
||||
@Throws(Exception::class)
|
||||
fun testOnToggleChipsClickedCaseVisible() {
|
||||
`when`(view.visibility).thenReturn(View.VISIBLE)
|
||||
fragment.onToggleChipsClicked()
|
||||
verify(view).visibility = View.GONE
|
||||
verify(ivToggleChips).rotation = ivToggleChips.rotation + 180
|
||||
}
|
||||
|
||||
@Test @Ignore
|
||||
@Throws(Exception::class)
|
||||
fun testOnToggleChipsClickedCaseNotVisible() {
|
||||
`when`(view.visibility).thenReturn(View.GONE)
|
||||
fragment.onToggleChipsClicked()
|
||||
verify(view).visibility = View.VISIBLE
|
||||
verify(ivToggleChips).rotation = ivToggleChips.rotation + 180
|
||||
}
|
||||
|
||||
@Test @Ignore
|
||||
@Throws(Exception::class)
|
||||
fun testOnLearnMoreClicked() {
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ class UploadMediaPresenterTest {
|
|||
fun setCorrectCountryCodeForReceivedImage() {
|
||||
|
||||
val germanyAsPlace =
|
||||
Place(null, null, null, null, LatLng(50.1, 10.2, 1.0f), null, null, null, true)
|
||||
Place(null, null, null, null, LatLng(50.1, 10.2, 1.0f), null, null, null, true, null)
|
||||
germanyAsPlace.isMonument = true
|
||||
|
||||
whenever(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue