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

Create or restore fragments before setAdapter (fixes #1162)

This commit is contained in:
Catfriend1 2018-06-20 22:16:34 +02:00 committed by Audrius Butkevicius
parent 31d3aba636
commit bea4bc3d01

View file

@ -218,20 +218,25 @@ public class MainActivity extends StateDialogActivity
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
mDrawerLayout = findViewById(R.id.drawer_layout); mDrawerLayout = findViewById(R.id.drawer_layout);
mViewPager = findViewById(R.id.pager); FragmentManager fm = getSupportFragmentManager();
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = findViewById(R.id.tabContainer);
tabLayout.setupWithViewPager(mViewPager);
if (savedInstanceState != null) { if (savedInstanceState != null) {
FragmentManager fm = getSupportFragmentManager();
mFolderListFragment = (FolderListFragment) fm.getFragment( mFolderListFragment = (FolderListFragment) fm.getFragment(
savedInstanceState, FolderListFragment.class.getName()); savedInstanceState, FolderListFragment.class.getName());
mDeviceListFragment = (DeviceListFragment) fm.getFragment( mDeviceListFragment = (DeviceListFragment) fm.getFragment(
savedInstanceState, DeviceListFragment.class.getName()); savedInstanceState, DeviceListFragment.class.getName());
mDrawerFragment = (DrawerFragment) fm.getFragment( mDrawerFragment = (DrawerFragment) fm.getFragment(
savedInstanceState, DrawerFragment.class.getName()); savedInstanceState, DrawerFragment.class.getName());
} else {
mFolderListFragment = new FolderListFragment();
mDeviceListFragment = new DeviceListFragment();
mDrawerFragment = new DrawerFragment();
}
mViewPager = findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = findViewById(R.id.tabContainer);
tabLayout.setupWithViewPager(mViewPager);
if (savedInstanceState != null) {
mViewPager.setCurrentItem(savedInstanceState.getInt("currentTab")); mViewPager.setCurrentItem(savedInstanceState.getInt("currentTab"));
if (savedInstanceState.getBoolean(IS_SHOWING_RESTART_DIALOG)){ if (savedInstanceState.getBoolean(IS_SHOWING_RESTART_DIALOG)){
showRestartDialog(); showRestartDialog();
@ -240,16 +245,9 @@ public class MainActivity extends StateDialogActivity
if(savedInstanceState.getBoolean(IS_QRCODE_DIALOG_DISPLAYED)) { if(savedInstanceState.getBoolean(IS_QRCODE_DIALOG_DISPLAYED)) {
showQrCodeDialog(savedInstanceState.getString(DEVICEID_KEY), savedInstanceState.getParcelable(QRCODE_BITMAP_KEY)); showQrCodeDialog(savedInstanceState.getString(DEVICEID_KEY), savedInstanceState.getParcelable(QRCODE_BITMAP_KEY));
} }
} else {
mFolderListFragment = new FolderListFragment();
mDeviceListFragment = new DeviceListFragment();
mDrawerFragment = new DrawerFragment();
} }
getSupportFragmentManager() fm.beginTransaction().replace(R.id.drawer, mDrawerFragment).commit();
.beginTransaction()
.replace(R.id.drawer, mDrawerFragment)
.commit();
mDrawerToggle = new Toggle(this, mDrawerLayout); mDrawerToggle = new Toggle(this, mDrawerLayout);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mDrawerLayout.addDrawerListener(mDrawerToggle); mDrawerLayout.addDrawerListener(mDrawerToggle);