1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2025-01-09 03:31:46 +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);
mDrawerLayout = findViewById(R.id.drawer_layout);
mViewPager = findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = findViewById(R.id.tabContainer);
tabLayout.setupWithViewPager(mViewPager);
FragmentManager fm = getSupportFragmentManager();
if (savedInstanceState != null) {
FragmentManager fm = getSupportFragmentManager();
mFolderListFragment = (FolderListFragment) fm.getFragment(
savedInstanceState, FolderListFragment.class.getName());
mDeviceListFragment = (DeviceListFragment) fm.getFragment(
savedInstanceState, DeviceListFragment.class.getName());
mDrawerFragment = (DrawerFragment) fm.getFragment(
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"));
if (savedInstanceState.getBoolean(IS_SHOWING_RESTART_DIALOG)){
showRestartDialog();
@ -240,16 +245,9 @@ public class MainActivity extends StateDialogActivity
if(savedInstanceState.getBoolean(IS_QRCODE_DIALOG_DISPLAYED)) {
showQrCodeDialog(savedInstanceState.getString(DEVICEID_KEY), savedInstanceState.getParcelable(QRCODE_BITMAP_KEY));
}
} else {
mFolderListFragment = new FolderListFragment();
mDeviceListFragment = new DeviceListFragment();
mDrawerFragment = new DrawerFragment();
}
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.drawer, mDrawerFragment)
.commit();
fm.beginTransaction().replace(R.id.drawer, mDrawerFragment).commit();
mDrawerToggle = new Toggle(this, mDrawerLayout);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mDrawerLayout.addDrawerListener(mDrawerToggle);