mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Show user current location (#4825)
This commit is contained in:
parent
27e3f20ba2
commit
755b216507
2 changed files with 35 additions and 4 deletions
|
|
@ -80,6 +80,7 @@ import fr.free.nrw.commons.description.DescriptionEditHelper;
|
|||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.explore.depictions.WikidataItemDetailsActivity;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.location.LocationServiceManager;
|
||||
import fr.free.nrw.commons.nearby.Label;
|
||||
import fr.free.nrw.commons.profile.ProfileActivity;
|
||||
import fr.free.nrw.commons.ui.widget.HtmlTextView;
|
||||
|
|
@ -117,6 +118,9 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
private boolean isWikipediaButtonDisplayed;
|
||||
private Callback callback;
|
||||
|
||||
@Inject
|
||||
LocationServiceManager locationManager;
|
||||
|
||||
|
||||
public static MediaDetailFragment forMedia(int index, boolean editable, boolean isCategoryImage, boolean isWikipediaButtonDisplayed) {
|
||||
MediaDetailFragment mf = new MediaDetailFragment();
|
||||
|
|
@ -826,9 +830,14 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
defaultLatitude = media.getCoordinates().getLatitude();
|
||||
defaultLongitude = media.getCoordinates().getLongitude();
|
||||
} else {
|
||||
String[] lastLocation = applicationKvStore.getString(LAST_LOCATION,(defaultLatitude + "," + defaultLongitude)).split(",");
|
||||
defaultLatitude = Double.parseDouble(lastLocation[0]);
|
||||
defaultLongitude = Double.parseDouble(lastLocation[1]);
|
||||
if(locationManager.getLastLocation()!=null) {
|
||||
defaultLatitude = locationManager.getLastLocation().getLatitude();
|
||||
defaultLongitude = locationManager.getLastLocation().getLongitude();
|
||||
} else {
|
||||
String[] lastLocation = applicationKvStore.getString(LAST_LOCATION,(defaultLatitude + "," + defaultLongitude)).split(",");
|
||||
defaultLatitude = Double.parseDouble(lastLocation[0]);
|
||||
defaultLongitude = Double.parseDouble(lastLocation[1]);
|
||||
}
|
||||
}
|
||||
|
||||
startActivityForResult(new LocationPicker.IntentBuilder()
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import fr.free.nrw.commons.category.CategoryEditSearchRecyclerViewAdapter
|
|||
import fr.free.nrw.commons.explore.SearchActivity
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.location.LatLng
|
||||
import fr.free.nrw.commons.location.LocationServiceManager
|
||||
import fr.free.nrw.commons.ui.widget.HtmlTextView
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
|
|
@ -66,6 +67,9 @@ class MediaDetailFragmentUnitTests {
|
|||
private lateinit var view: View
|
||||
private lateinit var context: Context
|
||||
|
||||
@Mock
|
||||
private lateinit var locationManager: LocationServiceManager
|
||||
|
||||
@Mock
|
||||
private lateinit var categoryEditSearchRecyclerViewAdapter: CategoryEditSearchRecyclerViewAdapter
|
||||
|
||||
|
|
@ -180,6 +184,7 @@ class MediaDetailFragmentUnitTests {
|
|||
Whitebox.setInternalState(fragment, "categoryContainer", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "categorySearchView", searchView)
|
||||
Whitebox.setInternalState(fragment, "mediaDiscussion", textView)
|
||||
Whitebox.setInternalState(fragment, "locationManager", locationManager)
|
||||
Whitebox.setInternalState(
|
||||
fragment,
|
||||
"categoryEditSearchRecyclerViewAdapter",
|
||||
|
|
@ -239,11 +244,13 @@ class MediaDetailFragmentUnitTests {
|
|||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnUpdateCoordinatesClicked() {
|
||||
fun testOnUpdateCoordinatesClickedCurrentLocationNull() {
|
||||
`when`(media.coordinates).thenReturn(null)
|
||||
`when`(locationManager.lastLocation).thenReturn(null)
|
||||
`when`(applicationKvStore.getString(LAST_LOCATION)).thenReturn("37.773972,-122.431297")
|
||||
fragment.onUpdateCoordinatesClicked()
|
||||
Mockito.verify(media, Mockito.times(1)).coordinates
|
||||
Mockito.verify(locationManager, Mockito.times(1)).lastLocation
|
||||
val shadowActivity: ShadowActivity = shadowOf(activity)
|
||||
val startedIntent = shadowActivity.nextStartedActivity
|
||||
val shadowIntent: ShadowIntent = shadowOf(startedIntent)
|
||||
|
|
@ -263,6 +270,21 @@ class MediaDetailFragmentUnitTests {
|
|||
Assert.assertEquals(shadowIntent.intentClass, LocationPickerActivity::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnUpdateCoordinatesClickedCurrentLocationNotNull() {
|
||||
`when`(media.coordinates).thenReturn(null)
|
||||
`when`(locationManager.lastLocation).thenReturn(LatLng(-0.000001, -0.999999, 0f))
|
||||
`when`(applicationKvStore.getString(LAST_LOCATION)).thenReturn("37.773972,-122.431297")
|
||||
|
||||
fragment.onUpdateCoordinatesClicked()
|
||||
Mockito.verify(locationManager, Mockito.times(3)).lastLocation
|
||||
val shadowActivity: ShadowActivity = shadowOf(activity)
|
||||
val startedIntent = shadowActivity.nextStartedActivity
|
||||
val shadowIntent: ShadowIntent = shadowOf(startedIntent)
|
||||
Assert.assertEquals(shadowIntent.intentClass, LocationPickerActivity::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnResume() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue