Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetContentController.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetContentController.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetContentController.java |
| index ea7871d00a51d3cdf8d40aed4e1f7cac25e0de95..ae5351672488ef7a221a216b6aed9bd4336a3e86 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetContentController.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetContentController.java |
| @@ -6,6 +6,7 @@ package org.chromium.chrome.browser.widget.bottomsheet; |
| import android.app.Activity; |
| import android.content.Context; |
| +import android.content.res.ColorStateList; |
| import android.content.res.Resources; |
| import android.support.annotation.IntDef; |
| import android.support.design.internal.BottomNavigationItemView; |
| @@ -18,15 +19,20 @@ import android.view.View; |
| import android.view.ViewGroup; |
| import org.chromium.base.ActivityState; |
| +import org.chromium.base.ApiCompatibilityUtils; |
| import org.chromium.base.ApplicationStatus; |
| import org.chromium.base.ApplicationStatus.ActivityStateListener; |
| import org.chromium.base.VisibleForTesting; |
| import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.ChromeActivity; |
| import org.chromium.chrome.browser.bookmarks.BookmarkSheetContent; |
| import org.chromium.chrome.browser.download.DownloadSheetContent; |
| import org.chromium.chrome.browser.history.HistorySheetContent; |
| +import org.chromium.chrome.browser.ntp.IncognitoBottomSheetContent; |
| import org.chromium.chrome.browser.snackbar.SnackbarManager; |
| import org.chromium.chrome.browser.suggestions.SuggestionsBottomSheetContent; |
| +import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; |
| +import org.chromium.chrome.browser.tabmodel.TabModel; |
| import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| import org.chromium.chrome.browser.util.MathUtils; |
| import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.BottomSheetContent; |
| @@ -46,13 +52,16 @@ import java.util.Map.Entry; |
| public class BottomSheetContentController extends BottomNavigationView |
| implements OnNavigationItemSelectedListener { |
| /** The different types of content that may be displayed in the bottom sheet. */ |
| - @IntDef({TYPE_SUGGESTIONS, TYPE_DOWNLOADS, TYPE_BOOKMARKS, TYPE_HISTORY}) |
| + @IntDef({TYPE_SUGGESTIONS, TYPE_DOWNLOADS, TYPE_BOOKMARKS, TYPE_HISTORY, TYPE_INCOGNITO_HOME}) |
| @Retention(RetentionPolicy.SOURCE) |
| public @interface ContentType {} |
| public static final int TYPE_SUGGESTIONS = 0; |
| public static final int TYPE_DOWNLOADS = 1; |
| public static final int TYPE_BOOKMARKS = 2; |
| public static final int TYPE_HISTORY = 3; |
| + public static final int TYPE_INCOGNITO_HOME = 4; |
| + |
| + private static final int INCOGNITO_HOME_ID = -1; |
|
dgn
2017/04/15 12:37:04
nit: maybe document how the -1 value was selected?
Theresa
2017/04/17 15:38:08
Done.
|
| private final Map<Integer, BottomSheetContent> mBottomSheetContents = new HashMap<>(); |
| @@ -76,21 +85,24 @@ public class BottomSheetContentController extends BottomNavigationView |
| @Override |
| public void onSheetClosed() { |
| + if (mSelectedItemId != 0 && mSelectedItemId != R.id.action_home) { |
| + showBottomSheetContent(R.id.action_home); |
| + } |
| + |
| Iterator<Entry<Integer, BottomSheetContent>> contentIterator = |
| mBottomSheetContents.entrySet().iterator(); |
| while (contentIterator.hasNext()) { |
| Entry<Integer, BottomSheetContent> entry = contentIterator.next(); |
| - if (entry.getKey() == R.id.action_home) continue; |
| + if (entry.getKey() == R.id.action_home || entry.getKey() == INCOGNITO_HOME_ID) { |
| + continue; |
| + } |
| entry.getValue().destroy(); |
| contentIterator.remove(); |
| } |
| + |
| // TODO(twellington): determine a policy for destroying the |
| // SuggestionsBottomSheetContent. |
| - |
| - if (mSelectedItemId == 0 || mSelectedItemId == R.id.action_home) return; |
| - |
| - showBottomSheetContent(R.id.action_home); |
| } |
| }; |
| @@ -117,6 +129,16 @@ public class BottomSheetContentController extends BottomNavigationView |
| mBottomSheet = bottomSheet; |
| mBottomSheet.addObserver(mBottomSheetObserver); |
| mTabModelSelector = tabModelSelector; |
| + mTabModelSelector.addObserver(new EmptyTabModelSelectorObserver() { |
| + @Override |
| + public void onTabModelSelected(TabModel newModel, TabModel oldModel) { |
| + updateVisuals(newModel.isIncognito()); |
| + showBottomSheetContent(R.id.action_home); |
| + |
| + // Release incognito bottom sheet content so that it can be garbage collected. |
| + if (!newModel.isIncognito()) mBottomSheetContents.remove(INCOGNITO_HOME_ID); |
|
Theresa
2017/04/13 23:51:15
I still need to call mBottomSheetContengs.get(INCO
Theresa
2017/04/17 15:38:08
Done.
|
| + } |
| + }); |
| Resources res = getContext().getResources(); |
| mDistanceBelowToolbarPx = controlContainerHeight |
| @@ -178,22 +200,27 @@ public class BottomSheetContentController extends BottomNavigationView |
| } |
| private BottomSheetContent getSheetContentForId(int navItemId) { |
| + if (mTabModelSelector.isIncognitoSelected() && navItemId == R.id.action_home) { |
| + navItemId = INCOGNITO_HOME_ID; |
| + } |
| + |
| BottomSheetContent content = mBottomSheetContents.get(navItemId); |
| if (content != null) return content; |
| + ChromeActivity activity = mTabModelSelector.getCurrentTab().getActivity(); |
| + |
| if (navItemId == R.id.action_home) { |
| content = new SuggestionsBottomSheetContent( |
| - mTabModelSelector.getCurrentTab().getActivity(), mBottomSheet, |
| - mTabModelSelector, mSnackbarManager); |
| + activity, mBottomSheet, mTabModelSelector, mSnackbarManager); |
| } else if (navItemId == R.id.action_downloads) { |
| - content = new DownloadSheetContent(mTabModelSelector.getCurrentTab().getActivity(), |
| - mTabModelSelector.getCurrentModel().isIncognito(), mSnackbarManager); |
| + content = new DownloadSheetContent( |
| + activity, mTabModelSelector.getCurrentModel().isIncognito(), mSnackbarManager); |
| } else if (navItemId == R.id.action_bookmarks) { |
| - content = new BookmarkSheetContent( |
| - mTabModelSelector.getCurrentTab().getActivity(), mSnackbarManager); |
| + content = new BookmarkSheetContent(activity, mSnackbarManager); |
| } else if (navItemId == R.id.action_history) { |
| - content = new HistorySheetContent( |
| - mTabModelSelector.getCurrentTab().getActivity(), mSnackbarManager); |
| + content = new HistorySheetContent(activity, mSnackbarManager); |
| + } else if (navItemId == INCOGNITO_HOME_ID) { |
| + content = new IncognitoBottomSheetContent(activity); |
| } |
| mBottomSheetContents.put(navItemId, content); |
| return content; |
| @@ -210,6 +237,17 @@ public class BottomSheetContentController extends BottomNavigationView |
| mBottomSheet.showContent(getSheetContentForId(mSelectedItemId)); |
| } |
| + private void updateVisuals(boolean isIncognitoTabModelSelected) { |
| + setBackgroundResource(isIncognitoTabModelSelected ? R.color.incognito_primary_color |
| + : R.color.appbar_background); |
| + |
| + ColorStateList tint = ApiCompatibilityUtils.getColorStateList(getResources(), |
| + isIncognitoTabModelSelected ? R.color.bottom_nav_tint_incognito |
| + : R.color.bottom_nav_tint); |
| + setItemIconTintList(tint); |
| + setItemTextColor(tint); |
| + } |
| + |
| /** |
| * @param itemId The id of the MenuItem to select. |
| */ |