mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Remember last opened screen on app startup (Nearby or Contributions) (#4881)
* added required changes * Fixed #4808 : Added the feature of opening last opened screen between Contribution & NearBy * removed the unnecessary commits * removed the unnecessary commits * removed the unnecessary commits * removed the unnecessary commits * added test * comments added
This commit is contained in:
parent
332a69fe5c
commit
7bc78f67ff
2 changed files with 42 additions and 3 deletions
|
|
@ -74,6 +74,7 @@ public class MainActivity extends BaseActivity
|
|||
private BookmarkFragment bookmarkFragment;
|
||||
public ActiveFragment activeFragment;
|
||||
private MediaDetailPagerFragment mediaDetailPagerFragment;
|
||||
private NavTabLayout.OnNavigationItemSelectedListener navListener;
|
||||
|
||||
@Inject
|
||||
public LocationServiceManager locationManager;
|
||||
|
|
@ -130,8 +131,15 @@ public class MainActivity extends BaseActivity
|
|||
} else {
|
||||
if(savedInstanceState == null){
|
||||
//starting a fresh fragment.
|
||||
setTitle(getString(R.string.contributions_fragment));
|
||||
loadFragment(ContributionsFragment.newInstance(),false);
|
||||
// Open Last opened screen if it is Contributions or Nearby, otherwise Contributions
|
||||
if(applicationKvStore.getBoolean("last_opened_nearby")){
|
||||
setTitle(getString(R.string.nearby_fragment));
|
||||
showNearby();
|
||||
loadFragment(NearbyParentFragment.newInstance(),false);
|
||||
}else{
|
||||
setTitle(getString(R.string.contributions_fragment));
|
||||
loadFragment(ContributionsFragment.newInstance(),false);
|
||||
}
|
||||
}
|
||||
setUpPager();
|
||||
}
|
||||
|
|
@ -142,11 +150,14 @@ public class MainActivity extends BaseActivity
|
|||
}
|
||||
|
||||
private void setUpPager() {
|
||||
tabLayout.setOnNavigationItemSelectedListener(item -> {
|
||||
tabLayout.setOnNavigationItemSelectedListener(navListener = (item) -> {
|
||||
if (!item.getTitle().equals(getString(R.string.more))) {
|
||||
// do not change title for more fragment
|
||||
setTitle(item.getTitle());
|
||||
}
|
||||
// set last_opened_nearby true if item is nearby screen else set false
|
||||
applicationKvStore.putBoolean("last_opened_nearby",
|
||||
item.getTitle().equals(getString(R.string.nearby_fragment)));
|
||||
final Fragment fragment = NavTab.of(item.getOrder()).newInstance();
|
||||
return loadFragment(fragment, true);
|
||||
});
|
||||
|
|
@ -404,4 +415,8 @@ public class MainActivity extends BaseActivity
|
|||
final SettingsFragment settingsFragment = new SettingsFragment();
|
||||
settingsFragment.setLocale(this, language);
|
||||
}
|
||||
|
||||
public NavTabLayout.OnNavigationItemSelectedListener getNavListener(){
|
||||
return navListener;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue