@Override public void onNavigationDrawerItemSelected(int position) { if (mSearchView.getVisibility() == View.VISIBLE) { hideSearchView(); } FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager .beginTransaction() .replace(R.id.container, HomeFragment.newInstance(position)) .commit(); navigationDepth = 0; isResultListFragmentOpened = false; }
@Override public void onBackPressed() { if (isSearchFilerShowing()) { findViewById(R.id.blankLayout).setVisibility(View.GONE); filterLayout.setVisibility(View.GONE); return; } if (mSearchView.getVisibility() == View.VISIBLE) { hideSearchView(); return; } switch (navigationDepth) { case 1: fragmentManager = getSupportFragmentManager(); fragmentManager .beginTransaction() .replace(R.id.container, HomeFragment.newInstance(0)) .commit(); if (navigationDepth > 0) { navigationDepth--; } isResultListFragmentOpened = false; break; case 2: // if (TextUtils.isEmpty(SubCategoryFragment.catId)) { // SubCategoryFragment.catId = "1"; // } // fragmentManager = getSupportFragmentManager(); // fragmentManager.beginTransaction() // .replace(R.id.container, // SubCategoryFragment.newInstance(SubCategoryFragment.catId)) // .commit(); // if (navigationDepth > 0) // navigationDepth--; // if (subCategoryTitle != null) // getSupportActionBar().setTitle(subCategoryTitle); break; case 3: if (TextUtils.isEmpty(ResultListFragment.catId)) { ResultListFragment.catId = "1"; } fragmentManager = getSupportFragmentManager(); fragmentManager .beginTransaction() .replace(R.id.container, ResultListFragment.newInstance(ResultListFragment.catId)) .commit(); if (navigationDepth > 0) navigationDepth--; if (resultListTitle != null) break; case 4: fragmentManager = getSupportFragmentManager(); fragmentManager .beginTransaction() .replace(R.id.container, HomeFragment.newInstance(0)) .commit(); navigationDepth = 0; isResultListFragmentOpened = false; break; case 5: fragmentManager = getSupportFragmentManager(); fragmentManager .beginTransaction() .replace( R.id.container, ResultListFragment.newInstance("", ResultListFragment.searchTerm)) .commit(); if (navigationDepth > 0) navigationDepth--; break; default: super.onBackPressed(); } }