1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2025-01-08 11:11:34 +00:00

Follow-Up to issue 108 "IllegalStateEx" workaround (fixes #108) (#113)

* MainActivity updateViewPager - Add isServiceActive

* Add numPages, setOffscreenPageLimit (fixes #108)

* Fix numPages
This commit is contained in:
Catfriend1 2018-10-26 17:23:25 +02:00 committed by GitHub
parent 6712ca657d
commit 39e1329f41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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