mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 13:23:58 +01:00
Nearby: Read fragment arguments for Explore map data and update Nearby map if present
This commit is contained in:
parent
9d590fdee4
commit
e96ab2bd22
3 changed files with 63 additions and 7 deletions
|
|
@ -452,7 +452,6 @@ public class MainActivity extends BaseActivity
|
||||||
bundle.putDouble("prev_longitude", longitude);
|
bundle.putDouble("prev_longitude", longitude);
|
||||||
|
|
||||||
loadFragment(ExploreFragment.newInstance(), false, bundle);
|
loadFragment(ExploreFragment.newInstance(), false, bundle);
|
||||||
setSelectedItemId(NavTab.EXPLORE.code());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -470,7 +469,6 @@ public class MainActivity extends BaseActivity
|
||||||
bundle.putDouble("prev_longitude", longitude);
|
bundle.putDouble("prev_longitude", longitude);
|
||||||
|
|
||||||
loadFragment(NearbyParentFragment.newInstance(), false, bundle);
|
loadFragment(NearbyParentFragment.newInstance(), false, bundle);
|
||||||
setSelectedItemId(NavTab.NEARBY.code());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -198,6 +198,12 @@ public class ExploreFragment extends CommonsDaggerSupportFragment {
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
inflater.inflate(R.menu.explore_fragment_menu, menu);
|
inflater.inflate(R.menu.explore_fragment_menu, menu);
|
||||||
|
|
||||||
|
MenuItem others = menu.findItem(R.id.list_item_show_in_nearby);
|
||||||
|
|
||||||
|
if (binding.viewPager.getCurrentItem() == 2) {
|
||||||
|
others.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
// if on Map tab, show all menu options, else only show search
|
// if on Map tab, show all menu options, else only show search
|
||||||
binding.viewPager.addOnPageChangeListener(new OnPageChangeListener() {
|
binding.viewPager.addOnPageChangeListener(new OnPageChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -207,8 +213,7 @@ public class ExploreFragment extends CommonsDaggerSupportFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageSelected(int position) {
|
public void onPageSelected(int position) {
|
||||||
MenuItem other = menu.findItem(R.id.list_item_show_in_nearby);
|
others.setVisible((position == 2));
|
||||||
other.setVisible((position == 2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -233,6 +233,11 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
private Place nearestPlace;
|
private Place nearestPlace;
|
||||||
private volatile boolean stopQuery;
|
private volatile boolean stopQuery;
|
||||||
|
|
||||||
|
// Explore map data (for if we came from Explore)
|
||||||
|
private double prevZoom;
|
||||||
|
private double prevLatitude;
|
||||||
|
private double prevLongitude;
|
||||||
|
|
||||||
private final Handler searchHandler = new Handler();
|
private final Handler searchHandler = new Handler();
|
||||||
private Runnable searchRunnable;
|
private Runnable searchRunnable;
|
||||||
|
|
||||||
|
|
@ -338,6 +343,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
|
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
|
||||||
final Bundle savedInstanceState) {
|
final Bundle savedInstanceState) {
|
||||||
|
loadExploreMapData();
|
||||||
|
|
||||||
binding = FragmentNearbyParentBinding.inflate(inflater, container, false);
|
binding = FragmentNearbyParentBinding.inflate(inflater, container, false);
|
||||||
view = binding.getRoot();
|
view = binding.getRoot();
|
||||||
|
|
||||||
|
|
@ -481,6 +488,14 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
binding.map.getOverlays().add(scaleBarOverlay);
|
binding.map.getOverlays().add(scaleBarOverlay);
|
||||||
binding.map.getZoomController().setVisibility(Visibility.NEVER);
|
binding.map.getZoomController().setVisibility(Visibility.NEVER);
|
||||||
binding.map.getController().setZoom(ZOOM_LEVEL);
|
binding.map.getController().setZoom(ZOOM_LEVEL);
|
||||||
|
// if we came from Explore map using 'Show in Nearby', load Explore map camera position
|
||||||
|
if (isCameFromExploreMap()) {
|
||||||
|
moveCameraToPosition(
|
||||||
|
new GeoPoint(prevLatitude, prevLongitude),
|
||||||
|
prevZoom,
|
||||||
|
2L
|
||||||
|
);
|
||||||
|
}
|
||||||
binding.map.getOverlays().add(mapEventsOverlay);
|
binding.map.getOverlays().add(mapEventsOverlay);
|
||||||
|
|
||||||
binding.map.addMapListener(new MapListener() {
|
binding.map.addMapListener(new MapListener() {
|
||||||
|
|
@ -503,7 +518,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
}
|
}
|
||||||
initNearbyFilter();
|
initNearbyFilter();
|
||||||
addCheckBoxCallback();
|
addCheckBoxCallback();
|
||||||
|
if (!isCameFromExploreMap()) {
|
||||||
moveCameraToPosition(lastMapFocus);
|
moveCameraToPosition(lastMapFocus);
|
||||||
|
}
|
||||||
initRvNearbyList();
|
initRvNearbyList();
|
||||||
onResume();
|
onResume();
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
|
@ -560,6 +577,28 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch Explore map camera data from fragment arguments if any.
|
||||||
|
*/
|
||||||
|
public void loadExploreMapData() {
|
||||||
|
// get fragment arguments
|
||||||
|
if (getArguments() != null) {
|
||||||
|
prevZoom = getArguments().getDouble("prev_zoom");
|
||||||
|
prevLatitude = getArguments().getDouble("prev_latitude");
|
||||||
|
prevLongitude = getArguments().getDouble("prev_longitude");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if fragment arguments contain data from Explore map. if present, then the user
|
||||||
|
* navigated from Explore using 'Show in Nearby'.
|
||||||
|
*
|
||||||
|
* @return true if user navigated from Explore map
|
||||||
|
**/
|
||||||
|
public boolean isCameFromExploreMap() {
|
||||||
|
return prevZoom != 0.0 || prevLatitude != 0.0 || prevLongitude != 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise background based on theme, this should be doe ideally via styles, that would need
|
* Initialise background based on theme, this should be doe ideally via styles, that would need
|
||||||
* another refactor
|
* another refactor
|
||||||
|
|
@ -640,7 +679,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
mapCenter = targetP;
|
mapCenter = targetP;
|
||||||
binding.map.getController().setCenter(targetP);
|
binding.map.getController().setCenter(targetP);
|
||||||
recenterMarkerToPosition(targetP);
|
recenterMarkerToPosition(targetP);
|
||||||
|
if (!isCameFromExploreMap()) {
|
||||||
moveCameraToPosition(targetP);
|
moveCameraToPosition(targetP);
|
||||||
|
}
|
||||||
} else if (locationManager.isGPSProviderEnabled()
|
} else if (locationManager.isGPSProviderEnabled()
|
||||||
|| locationManager.isNetworkProviderEnabled()) {
|
|| locationManager.isNetworkProviderEnabled()) {
|
||||||
locationManager.requestLocationUpdatesFromProvider(LocationManager.NETWORK_PROVIDER);
|
locationManager.requestLocationUpdatesFromProvider(LocationManager.NETWORK_PROVIDER);
|
||||||
|
|
@ -684,7 +725,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
} else {
|
} else {
|
||||||
lastKnownLocation = MapUtils.getDefaultLatLng();
|
lastKnownLocation = MapUtils.getDefaultLatLng();
|
||||||
}
|
}
|
||||||
if (binding.map != null) {
|
if (binding.map != null && !isCameFromExploreMap()) {
|
||||||
moveCameraToPosition(
|
moveCameraToPosition(
|
||||||
new GeoPoint(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude()));
|
new GeoPoint(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude()));
|
||||||
}
|
}
|
||||||
|
|
@ -2313,6 +2354,18 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
binding.map.getController().animateTo(geoPoint);
|
binding.map.getController().animateTo(geoPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the camera of the map view to the specified GeoPoint at specified zoom level and speed
|
||||||
|
* using an animation.
|
||||||
|
*
|
||||||
|
* @param geoPoint The GeoPoint representing the new camera position for the map.
|
||||||
|
* @param zoom Zoom level of the map camera
|
||||||
|
* @param speed Speed of animation
|
||||||
|
*/
|
||||||
|
private void moveCameraToPosition(GeoPoint geoPoint, double zoom, long speed) {
|
||||||
|
binding.map.getController().animateTo(geoPoint, zoom, speed);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBottomSheetItemClick(@Nullable View view, int position) {
|
public void onBottomSheetItemClick(@Nullable View view, int position) {
|
||||||
BottomSheetItem item = dataList.get(position);
|
BottomSheetItem item = dataList.get(position);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue