mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-07 10:42:07 +00:00
* MainActivity updateViewPager - Add isServiceActive * Add numPages, setOffscreenPageLimit (fixes #108) * Fix numPages
This commit is contained in:
parent
6712ca657d
commit
39e1329f41
1 changed files with 6 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue