Search in sources :

Example 1 with ScrollAwareFABBehavior

use of eu.davidea.utils.ScrollAwareFABBehavior in project FlexibleAdapter by davideas.

the class MainActivity method onNavigationItemSelected.

/* =======================================
	 * NAVIGATION DRAWER & FRAGMENT MANAGEMENT
	 * ======================================= */
/**
	 * IMPORTANT!! READ THE COMMENT FOR THE FRAGMENT REPLACE
	 */
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    hideFabSilently();
    CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) mFab.getLayoutParams();
    ScrollAwareFABBehavior fabBehavior = ((ScrollAwareFABBehavior) layoutParams.getBehavior());
    fabBehavior.setEnabled(false);
    // Handle navigation view item clicks
    int id = item.getItemId();
    if (id == R.id.nav_overall) {
        mFragment = FragmentOverall.newInstance(2);
    } else if (id == R.id.nav_selection_modes) {
        mFragment = FragmentSelectionModes.newInstance(2);
    } else if (id == R.id.nav_filter) {
        mFragment = FragmentAsyncFilter.newInstance(true);
    } else if (id == R.id.nav_animator) {
        mFragment = FragmentAnimators.newInstance();
    } else if (id == R.id.nav_endless_scrolling) {
        mFragment = FragmentEndlessScrolling.newInstance(2);
    } else if (id == R.id.nav_instagram_headers) {
        mFragment = FragmentInstagramHeaders.newInstance();
    } else if (id == R.id.nav_headers_and_sections) {
        mFragment = FragmentHeadersSections.newInstance(2);
        fabBehavior.setEnabled(true);
    } else if (id == R.id.nav_multi_level_expandable) {
        mFragment = FragmentExpandableMultiLevel.newInstance(2);
    } else if (id == R.id.nav_expandable_sections) {
        mFragment = FragmentExpandableSections.newInstance(3);
    } else if (id == R.id.nav_staggered) {
        mFragment = FragmentStaggeredLayout.newInstance(2);
    } else if (id == R.id.nav_model_holders) {
        mFragment = FragmentHolderSections.newInstance();
    } else if (id == R.id.nav_viewpager) {
        Intent intent = new Intent(this, ViewPagerActivity.class);
        ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeBasic();
        ActivityCompat.startActivity(this, intent, activityOptionsCompat.toBundle());
        // Close drawer
        mRecyclerView.post(new Runnable() {

            @Override
            public void run() {
                mDrawer.closeDrawer(GravityCompat.START);
            }
        });
        return true;
    } else if (id == R.id.nav_about) {
        MessageDialog.newInstance(R.drawable.ic_info_grey600_24dp, getString(R.string.about_title), getString(R.string.about_body, Utils.getVersionName(this), Integer.toString(Utils.getVersionCode(this)))).show(getFragmentManager(), MessageDialog.TAG);
        return true;
    } else if (id == R.id.nav_github) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("https://github.com/davideas/FlexibleAdapter"));
        startActivity(Intent.createChooser(intent, getString(R.string.intent_chooser)));
        return true;
    }
    // Insert the fragment by replacing any existing fragment
    if (mFragment != null) {
        // Highlight the selected item has been done by NavigationView
        item.setChecked(true);
        // THIS IS VERY IMPORTANT. Because you are going to inflate a new RecyclerView, its
        // Adapter will be null, therefore the following method cannot be called automatically!
        // If your StickyHeaderContainer is in the main view, you must call this method to clean
        // the previous sticky view. Alternatively you can move the <include> of StickyHeaderLayout
        // in the Fragment view.
        mAdapter.onDetachedFromRecyclerView(mRecyclerView);
        // Inflate the new Fragment with the new RecyclerView and a new Adapter
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.recycler_view_container, mFragment).commit();
        // Close drawer
        mRecyclerView.post(new Runnable() {

            @Override
            public void run() {
                mDrawer.closeDrawer(GravityCompat.START);
            }
        });
        //mToolbar.setSubtitle(item.getTitle());
        mHeaderView.bindTo(getString(R.string.app_name), item.getTitle());
        return true;
    }
    return false;
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) FragmentManager(android.support.v4.app.FragmentManager) Intent(android.content.Intent) ScrollAwareFABBehavior(eu.davidea.utils.ScrollAwareFABBehavior) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat)

Aggregations

Intent (android.content.Intent)1 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)1 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)1 FragmentManager (android.support.v4.app.FragmentManager)1 ScrollAwareFABBehavior (eu.davidea.utils.ScrollAwareFABBehavior)1