1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2025-01-07 10:42:07 +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.
*/
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);
}