mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Handle orientation changes
This commit is contained in:
		
							parent
							
								
									81237e8267
								
							
						
					
					
						commit
						57c8ca646d
					
				
					 2 changed files with 32 additions and 0 deletions
				
			
		|  | @ -75,6 +75,8 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
|     private boolean lockNearbyView; //Determines if the nearby places needs to be refreshed | ||||
|     private BottomSheetBehavior bottomSheetBehavior; // Behavior for list bottom sheet | ||||
|     private BottomSheetBehavior bottomSheetBehaviorForDetails; // Behavior for details bottom sheet | ||||
|     private NearbyMapFragment nearbyMapFragment; | ||||
|     private static final String TAG_RETAINED_FRAGMENT = "RetainedFragment"; | ||||
| 
 | ||||
|     @Override | ||||
|     protected void onCreate(Bundle savedInstanceState) { | ||||
|  | @ -82,6 +84,7 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
|         sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | ||||
|         setContentView(R.layout.activity_nearby); | ||||
|         ButterKnife.bind(this); | ||||
|         resumeFragment(); | ||||
|         bundle = new Bundle(); | ||||
| 
 | ||||
|         initBottomSheetBehaviour(); | ||||
|  | @ -91,6 +94,21 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
|         initViewState(); | ||||
|     } | ||||
| 
 | ||||
|     private void resumeFragment() { | ||||
|         // find the retained fragment on activity restarts | ||||
|         android.support.v4.app.FragmentManager fm = getSupportFragmentManager(); | ||||
|         nearbyMapFragment = (NearbyMapFragment) fm.findFragmentByTag(TAG_RETAINED_FRAGMENT); | ||||
| 
 | ||||
|         // create the fragment and data the first time | ||||
|         if (nearbyMapFragment == null) { | ||||
|             // add the fragment | ||||
|             nearbyMapFragment = new NearbyMapFragment(); | ||||
|             fm.beginTransaction().add(nearbyMapFragment, TAG_RETAINED_FRAGMENT).commit(); | ||||
|             // load data from a data source or perform any calculation | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private void initViewState() { | ||||
|         if (sharedPreferences.getBoolean(MAP_LAST_USED_PREFERENCE, false)) { | ||||
|             viewMode = NearbyActivityMode.MAP; | ||||
|  | @ -307,6 +325,19 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
|         checkGps(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void onPause() { | ||||
|         super.onPause(); | ||||
|         // this means that this activity will not be recreated now, user is leaving it | ||||
|         // or the activity is otherwise finishing | ||||
|         if(isFinishing()) { | ||||
|             android.support.v4.app.FragmentManager fm = getSupportFragmentManager(); | ||||
|             // 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. | ||||
|             fm.beginTransaction().remove(nearbyMapFragment).commit(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|  |  | |||
|  | @ -92,6 +92,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
|         Mapbox.getInstance(getActivity(), | ||||
|                 getString(R.string.mapbox_commons_app_token)); | ||||
|         MapboxTelemetry.getInstance().setTelemetryEnabled(false); | ||||
|         setRetainInstance(true); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 neslihanturan
						neslihanturan