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:
Arin Modi 2022-03-16 18:09:54 +05:30 committed by GitHub
parent 332a69fe5c
commit 7bc78f67ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 3 deletions

View file

@ -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;
}
}