Fixes #4571 - Nearby: Save last known location and show it immediately without waiting for GPS (#4721)

* save last location feature

* fix lat lng exchange

* removed unnecessary space

Co-authored-by: Pratham2305 <Pratham2305@users.noreply.github.com>
This commit is contained in:
Pratham Pahariya 2021-12-23 13:47:30 +05:30 committed by GitHub
parent 8a2c30120d
commit 8a0d5580b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -328,10 +328,20 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
nearbyParentFragmentInstanceReadyCallback.onReady();
}
performMapReadyActions();
final CameraPosition cameraPosition = new CameraPosition.Builder()
final CameraPosition cameraPosition;
if(applicationKvStore.getString("LastLocation")!=null) { // Checking for last searched location
String[] locationLatLng = applicationKvStore.getString("LastLocation").split(",");
cameraPosition = new CameraPosition.Builder()
.target(new LatLng(Double.valueOf(locationLatLng[0]),
Double.valueOf(locationLatLng[1])))
.zoom(ZOOM_LEVEL)
.build();
}else {
cameraPosition = new CameraPosition.Builder()
.target(new LatLng(51.50550, -0.07520))
.zoom(ZOOM_OUT)
.build();
}
mapBoxMap.setCameraPosition(cameraPosition);
final ScaleBarPlugin scaleBarPlugin = new ScaleBarPlugin(mapView, mapBoxMap);
@ -345,6 +355,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
.setMarginLeft(R.dimen.tiny_padding)
.setTextBarMargin(R.dimen.tiny_padding);
scaleBarPlugin.create(scaleBarOptions);
onResume();
});
});
@ -485,17 +496,27 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
mapView.onStart();
applicationKvStore.putBoolean("doNotAskForLocationPermission", true);
lastKnownLocation = new fr.free.nrw.commons.location.LatLng(51.50550,-0.07520,1f);
final CameraPosition position = new CameraPosition.Builder()
.target(LocationUtils.commonsLatLngToMapBoxLatLng(lastKnownLocation))
.zoom(ZOOM_OUT)
.build();
final CameraPosition position;
if(applicationKvStore.getString("LastLocation")!=null) { // Checking for last searched location
String[] locationLatLng = applicationKvStore.getString("LastLocation").split(",");
lastKnownLocation = new fr.free.nrw.commons.location.LatLng(Double.valueOf(locationLatLng[0]), Double.valueOf(locationLatLng[1]), 1f);
position = new CameraPosition.Builder()
.target(LocationUtils.commonsLatLngToMapBoxLatLng(lastKnownLocation))
.zoom(ZOOM_LEVEL)
.build();
}else {
lastKnownLocation = new fr.free.nrw.commons.location.LatLng(51.50550,-0.07520,1f);
position = new CameraPosition.Builder()
.target(LocationUtils.commonsLatLngToMapBoxLatLng(lastKnownLocation))
.zoom(ZOOM_OUT)
.build();
}
if(mapBox != null){
mapBox.moveCamera(CameraUpdateFactory.newCameraPosition(position));
addOnCameraMoveListener();
presenter.onMapReady();
removeCurrentLocationMarker();
}
presenter.onMapReady();
removeCurrentLocationMarker();
}
private void registerNetworkReceiver() {
@ -1076,6 +1097,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
if (nearbyPlacesInfo.placeList == null || nearbyPlacesInfo.placeList.isEmpty()) {
showErrorMessage(getString(R.string.no_nearby_places_around));
} else {
// Updating last searched location
applicationKvStore.putString("LastLocation", searchLatLng.getLatitude() + "," + searchLatLng.getLongitude());
updateMapMarkers(nearbyPlacesInfo, false);
lastFocusLocation = searchLatLng;
}