123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package eu.kanade.mangafeed.ui.activity;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.support.v4.app.FragmentTransaction;
- import android.support.v7.widget.Toolbar;
- import android.widget.FrameLayout;
- import com.mikepenz.materialdrawer.Drawer;
- import com.mikepenz.materialdrawer.DrawerBuilder;
- import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
- import butterknife.Bind;
- import butterknife.ButterKnife;
- import eu.kanade.mangafeed.R;
- import eu.kanade.mangafeed.ui.fragment.LibraryFragment;
- import rx.subscriptions.CompositeSubscription;
- public class MainActivity extends BaseActivity {
- @Bind(R.id.toolbar)
- Toolbar toolbar;
- @Bind(R.id.drawer_container)
- FrameLayout container;
- private Drawer drawer;
- private CompositeSubscription mSubscriptions;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ButterKnife.bind(this);
- mSubscriptions = new CompositeSubscription();
- setupToolbar(toolbar);
- drawer = new DrawerBuilder()
- .withActivity(this)
- .withRootView(container)
- .withToolbar(toolbar)
- .withActionBarDrawerToggleAnimated(true)
- .addDrawerItems(
- new PrimaryDrawerItem()
- .withName(R.string.library_title)
- .withIdentifier(R.id.nav_drawer_library),
- new PrimaryDrawerItem()
- .withName(R.string.recent_updates_title)
- .withIdentifier(R.id.nav_drawer_recent_updates),
- new PrimaryDrawerItem()
- .withName(R.string.catalogues_title)
- .withIdentifier(R.id.nav_drawer_catalogues),
- new PrimaryDrawerItem()
- .withName(R.string.settings_title)
- .withIdentifier(R.id.nav_drawer_settings)
- )
- .withSavedInstance(savedInstanceState)
- .withOnDrawerItemClickListener(
- (view, position, drawerItem) -> {
- if (drawerItem != null) {
- int identifier = drawerItem.getIdentifier();
- switch (identifier) {
- case R.id.nav_drawer_library:
- setFragment(LibraryFragment.newInstance());
- break;
- case R.id.nav_drawer_catalogues:
- case R.id.nav_drawer_recent_updates:
- case R.id.nav_drawer_settings:
- break;
- }
- }
- return false;
- }
- )
- .build();
- drawer.setSelection(R.id.nav_drawer_library);
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mSubscriptions.unsubscribe();
- }
- private void setFragment(Fragment fragment) {
- try {
- if (fragment != null && getSupportFragmentManager() != null) {
- FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
- if (ft != null) {
- ft.replace(R.id.content_layout, fragment);
- ft.commit();
- }
- }
- } catch (Exception e) {
- }
- }
- public void setToolbarTitle(int titleResource) {
- getSupportActionBar().setTitle(getString(titleResource));
- }
- }
|