Show user current location (#4825)

This commit is contained in:
Devarsh Mavani 2022-02-16 19:43:23 +05:30 committed by GitHub
parent 27e3f20ba2
commit 755b216507
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 4 deletions

View file

@ -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()