diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java index a1701d9e..ffc05634 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java @@ -211,12 +211,14 @@ public class MainActivity extends SyncthingActivity * Updates the ViewPager to show tabs depending on the service state. */ private void updateViewPager() { + Boolean isServiceActive = mSyncthingServiceState == SyncthingService.State.ACTIVE; + final int numPages = (isServiceActive ? 3 : 1); FragmentStatePagerAdapter mSectionsPagerAdapter = new FragmentStatePagerAdapter(getSupportFragmentManager()) { @Override public Fragment getItem(int position) { - if (mSyncthingServiceState == SyncthingService.State.ACTIVE) { + if (isServiceActive) { switch (position) { case 0: return mFolderListFragment; @@ -244,12 +246,12 @@ public class MainActivity extends SyncthingActivity @Override public int getCount() { - return mSyncthingServiceState == SyncthingService.State.ACTIVE ? 3 : 1; + return numPages; } @Override public CharSequence getPageTitle(int position) { - if (mSyncthingServiceState == SyncthingService.State.ACTIVE) { + if (isServiceActive) { switch (position) { case 0: return getResources().getString(R.string.folders_fragment_title); @@ -286,6 +288,7 @@ public class MainActivity extends SyncthingActivity .setPositiveButton(android.R.string.ok, (dialog, which) -> {}) .show(); } + mViewPager.setOffscreenPageLimit(numPages); TabLayout tabLayout = findViewById(R.id.tabContainer); tabLayout.setupWithViewPager(mViewPager); }