mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Looper
|
||||
import android.view.MenuItem
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.work.Configuration
|
||||
import androidx.work.testing.WorkManagerTestInitHelper
|
||||
|
|
@ -23,6 +24,7 @@ import org.junit.Before
|
|||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
|
@ -457,4 +459,26 @@ class MainActivityUnitTests {
|
|||
method.invoke(activity, bundle)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnSetUpPagerNearBy(){
|
||||
val item = Mockito.mock(MenuItem::class.java)
|
||||
`when`(item.title).thenReturn(activity.getString(R.string.nearby_fragment))
|
||||
activity.navListener.onNavigationItemSelected(item)
|
||||
verify(item, Mockito.times(3)).title
|
||||
verify(applicationKvStore,Mockito.times(1))
|
||||
.putBoolean("last_opened_nearby",true)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnSetUpPagerOtherThanNearBy(){
|
||||
val item = Mockito.mock(MenuItem::class.java)
|
||||
`when`(item.title).thenReturn(activity.getString(R.string.bookmarks))
|
||||
activity.navListener.onNavigationItemSelected(item)
|
||||
verify(item, Mockito.times(3)).title
|
||||
verify(applicationKvStore,Mockito.times(1))
|
||||
.putBoolean("last_opened_nearby",false)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue