Search in sources :

Example 1 with DeviceListFragment

use of com.nutomic.syncthingandroid.fragments.DeviceListFragment in project syncthing-android by syncthing.

the class MainActivity method onCreate.

/**
 * Initializes tab navigation.
 */
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((SyncthingApp) getApplication()).component().inject(this);
    setContentView(R.layout.activity_main);
    mDrawerLayout = findViewById(R.id.drawer_layout);
    FragmentManager fm = getSupportFragmentManager();
    if (savedInstanceState != null) {
        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();
        }
        mBatteryOptimizationDialogDismissed = savedInstanceState.getBoolean(BATTERY_DIALOG_DISMISSED);
        if (savedInstanceState.getBoolean(IS_QRCODE_DIALOG_DISPLAYED)) {
            showQrCodeDialog(savedInstanceState.getString(DEVICEID_KEY), savedInstanceState.getParcelable(QRCODE_BITMAP_KEY));
        }
    }
    fm.beginTransaction().replace(R.id.drawer, mDrawerFragment).commit();
    mDrawerToggle = new Toggle(this, mDrawerLayout);
    mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    setOptimalDrawerWidth(findViewById(R.id.drawer));
    // SyncthingService needs to be started from this activity as the user
    // can directly launch this activity from the recent activity switcher.
    Intent serviceIntent = new Intent(this, SyncthingService.class);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        startForegroundService(serviceIntent);
    } else {
        startService(serviceIntent);
    }
    onNewIntent(getIntent());
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) DrawerFragment(com.nutomic.syncthingandroid.fragments.DrawerFragment) TabLayout(com.google.android.material.tabs.TabLayout) FolderListFragment(com.nutomic.syncthingandroid.fragments.FolderListFragment) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) DeviceListFragment(com.nutomic.syncthingandroid.fragments.DeviceListFragment) Intent(android.content.Intent)

Aggregations

Intent (android.content.Intent)1 ActionBarDrawerToggle (androidx.appcompat.app.ActionBarDrawerToggle)1 FragmentManager (androidx.fragment.app.FragmentManager)1 TabLayout (com.google.android.material.tabs.TabLayout)1 DeviceListFragment (com.nutomic.syncthingandroid.fragments.DeviceListFragment)1 DrawerFragment (com.nutomic.syncthingandroid.fragments.DrawerFragment)1 FolderListFragment (com.nutomic.syncthingandroid.fragments.FolderListFragment)1