mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Add same retain settings to list fragment also
This commit is contained in:
parent
6284307826
commit
8fd55538b1
1 changed files with 39 additions and 9 deletions
|
|
@ -7,7 +7,6 @@ import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.BottomSheetBehavior;
|
import android.support.design.widget.BottomSheetBehavior;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
|
@ -97,6 +96,11 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
|
||||||
// load data from a data source or perform any calculation
|
// load data from a data source or perform any calculation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nearbyListFragment = getListFragment();
|
||||||
|
if (nearbyListFragment == null) {
|
||||||
|
setListFragment();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initBottomSheetBehaviour() {
|
private void initBottomSheetBehaviour() {
|
||||||
|
|
@ -296,7 +300,8 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
|
||||||
if(isFinishing()) {
|
if(isFinishing()) {
|
||||||
// we will not need this fragment anymore, this may also be a good place to signal
|
// we will not need this fragment anymore, this may also be a good place to signal
|
||||||
// to the retained fragment object to perform its own cleanup.
|
// to the retained fragment object to perform its own cleanup.
|
||||||
removeFragment();
|
removeMapFragment();
|
||||||
|
removeListFragment();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -371,15 +376,25 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
|
||||||
bundle.putString("BoundaryCoord", gsonBoundaryCoordinates);
|
bundle.putString("BoundaryCoord", gsonBoundaryCoordinates);
|
||||||
|
|
||||||
// First time to init fragments
|
// First time to init fragments
|
||||||
if (getMapFragment() == null){
|
if (nearbyMapFragment == null) {
|
||||||
lockNearbyView(true);
|
lockNearbyView(true);
|
||||||
setMapFragment();
|
setMapFragment();
|
||||||
setListFragment();
|
|
||||||
|
|
||||||
hideProgressBar();
|
hideProgressBar();
|
||||||
lockNearbyView(false);
|
lockNearbyView(false);
|
||||||
} else { // There are fragments, just update the map and list
|
} else { // There are fragments, just update the map and list
|
||||||
updateMapFragment(false);
|
updateMapFragment(false);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nearbyListFragment == null) {
|
||||||
|
lockNearbyView(true);
|
||||||
|
setListFragment();
|
||||||
|
lockNearbyView(false);
|
||||||
|
} else {
|
||||||
|
updateListFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -403,16 +418,27 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
|
||||||
}
|
}
|
||||||
|
|
||||||
private NearbyMapFragment getMapFragment() {
|
private NearbyMapFragment getMapFragment() {
|
||||||
return (NearbyMapFragment) getSupportFragmentManager().findFragmentByTag(NearbyMapFragment.class.getName());
|
return (NearbyMapFragment) getSupportFragmentManager().findFragmentByTag(TAG_RETAINED_MAP_FRAGMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeFragment() {
|
private void removeMapFragment() {
|
||||||
if (nearbyMapFragment != null) {
|
if (nearbyMapFragment != null) {
|
||||||
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
|
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
|
||||||
fm.beginTransaction().remove(nearbyMapFragment).commit();
|
fm.beginTransaction().remove(nearbyMapFragment).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private NearbyListFragment getListFragment() {
|
||||||
|
return (NearbyListFragment) getSupportFragmentManager().findFragmentByTag(TAG_RETAINED_LIST_FRAGMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeListFragment() {
|
||||||
|
if (nearbyListFragment != null) {
|
||||||
|
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
|
||||||
|
fm.beginTransaction().remove(nearbyListFragment).commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateMapFragment(boolean isSlightUpdate) {
|
private void updateMapFragment(boolean isSlightUpdate) {
|
||||||
/*
|
/*
|
||||||
* Significant update means updating nearby place markers. Slightly update means only
|
* Significant update means updating nearby place markers. Slightly update means only
|
||||||
|
|
@ -464,6 +490,10 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateListFragment() {
|
||||||
|
nearbyListFragment.updateNearbyListSignificantly();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls fragment for map view.
|
* Calls fragment for map view.
|
||||||
*/
|
*/
|
||||||
|
|
@ -480,9 +510,9 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
|
||||||
*/
|
*/
|
||||||
private void setListFragment() {
|
private void setListFragment() {
|
||||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||||
Fragment fragment = new NearbyListFragment();
|
nearbyListFragment = new NearbyListFragment();
|
||||||
fragment.setArguments(bundle);
|
nearbyListFragment.setArguments(bundle);
|
||||||
fragmentTransaction.replace(R.id.container_sheet, fragment, fragment.getClass().getSimpleName());
|
fragmentTransaction.replace(R.id.container_sheet, nearbyListFragment, TAG_RETAINED_LIST_FRAGMENT);
|
||||||
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
||||||
fragmentTransaction.commitAllowingStateLoss();
|
fragmentTransaction.commitAllowingStateLoss();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue