mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-30 22:34:02 +01:00
Feat: Make it smoother to switch between nearby and explore maps (#6164)
* Nearby: Add 'Show in Explore' 3-dots menu item * MainActivity: Add methods to pass extras between Nearby and Explore * MainActivity: Extend loadFragment() to support passing fragment arguments * Nearby: Add ability to navigate to Explore fragment on 'Show in Explore' click * Explore: Read fragment arguments for Nearby map data and update Explore map if present * Explore: Add 'Show in Nearby' 3-dots menu item. Only visible when Map tab is selected * Explore: On 'Show in Nearby' click, navigate to Nearby fragment, passing map data as fragment args * Nearby: Read fragment arguments for Explore map data and update Nearby map if present * MainActivity: Fix memory leaks when navigating between bottom nav destinations * Explore: Fix crashes caused by unattached map fragment * Refactor code to pass unit tests * Explore: Format javadocs --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
parent
9dc9a3b8ab
commit
7b291535e0
10 changed files with 510 additions and 152 deletions
|
|
@ -207,6 +207,9 @@ public class MainActivity extends BaseActivity
|
|||
private boolean loadFragment(Fragment fragment, boolean showBottom) {
|
||||
//showBottom so that we do not show the bottom tray again when constructing
|
||||
//from the saved instance state.
|
||||
|
||||
freeUpFragments();
|
||||
|
||||
if (fragment instanceof ContributionsFragment) {
|
||||
if (activeFragment == ActiveFragment.CONTRIBUTIONS) {
|
||||
// scroll to top if already on the Contributions tab
|
||||
|
|
@ -256,6 +259,31 @@ public class MainActivity extends BaseActivity
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* loadFragment() overload that supports passing extras to fragments
|
||||
**/
|
||||
private boolean loadFragment(Fragment fragment, boolean showBottom, Bundle args) {
|
||||
if (fragment != null && args != null) {
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
|
||||
return loadFragment(fragment, showBottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Old implementation of loadFragment() was causing memory leaks, due to MainActivity holding
|
||||
* references to cleared fragments. This function frees up all fragment references.
|
||||
* <p>
|
||||
* Called in loadFragment() before doing the actual loading.
|
||||
**/
|
||||
public void freeUpFragments() {
|
||||
// free all fragments except contributionsFragment because several tests depend on it.
|
||||
// hence, contributionsFragment is probably still a leak
|
||||
nearbyParentFragment = null;
|
||||
exploreFragment = null;
|
||||
bookmarkFragment = null;
|
||||
}
|
||||
|
||||
public void hideTabs() {
|
||||
binding.fragmentMainNavTabLayout.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
@ -432,6 +460,42 @@ public class MainActivity extends BaseActivity
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the Explore fragment from Nearby fragment. This method is called when a user clicks
|
||||
* the 'Show in Explore' option in the 3-dots menu in Nearby.
|
||||
*
|
||||
* @param zoom current zoom of Nearby map
|
||||
* @param latitude current latitude of Nearby map
|
||||
* @param longitude current longitude of Nearby map
|
||||
**/
|
||||
public void loadExploreMapFromNearby(double zoom, double latitude, double longitude) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putDouble("prev_zoom", zoom);
|
||||
bundle.putDouble("prev_latitude", latitude);
|
||||
bundle.putDouble("prev_longitude", longitude);
|
||||
|
||||
loadFragment(ExploreFragment.newInstance(), false, bundle);
|
||||
setSelectedItemId(NavTab.EXPLORE.code());
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the Nearby fragment from Explore fragment. This method is called when a user clicks
|
||||
* the 'Show in Nearby' option in the 3-dots menu in Explore.
|
||||
*
|
||||
* @param zoom current zoom of Explore map
|
||||
* @param latitude current latitude of Explore map
|
||||
* @param longitude current longitude of Explore map
|
||||
**/
|
||||
public void loadNearbyMapFromExplore(double zoom, double latitude, double longitude) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putDouble("prev_zoom", zoom);
|
||||
bundle.putDouble("prev_latitude", latitude);
|
||||
bundle.putDouble("prev_longitude", longitude);
|
||||
|
||||
loadFragment(NearbyParentFragment.newInstance(), false, bundle);
|
||||
setSelectedItemId(NavTab.NEARBY.code());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue