| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/StatusItem.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/StatusItem.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/StatusItem.java
|
| index df6fd9631313dd75e560b885d633c5cfc8428c06..b412d7756979addd742647c9e78536de58e19dd4 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/StatusItem.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/StatusItem.java
|
| @@ -5,17 +5,107 @@
|
| package org.chromium.chrome.browser.ntp.cards;
|
|
|
| import android.content.Context;
|
| +import android.support.annotation.Nullable;
|
|
|
| +import org.chromium.base.Log;
|
| import org.chromium.chrome.R;
|
| +import org.chromium.chrome.browser.ntp.snippets.CategoryStatus;
|
| +import org.chromium.chrome.browser.ntp.snippets.CategoryStatus.CategoryStatusEnum;
|
|
|
| /**
|
| * Card that is shown when the user needs to be made aware of some information about their
|
| - * configuration that affects the NTP suggestions.
|
| + * configuration about the NTP suggestions: there is no more available suggested content, sync
|
| + * should be enabled, etc.
|
| */
|
| -public class StatusItem implements NewTabPageItem {
|
| +public abstract class StatusItem implements NewTabPageItem {
|
| + /**
|
| + * Delegate to provide the status cards a way to interact with the rest of the system: tap
|
| + * handler, etc.
|
| + */
|
| + public interface ActionDelegate { void onButtonTapped(); }
|
| +
|
| + private static class NoBookmarks extends StatusItem {
|
| + public NoBookmarks() {
|
| + super(R.string.ntp_status_card_title_no_bookmarks,
|
| + R.string.ntp_status_card_no_bookmarks, 0);
|
| + Log.d(TAG, "Registering card for status: No Bookmarks");
|
| + }
|
| +
|
| + @Override
|
| + protected void performAction(Context context) {
|
| + assert false; // not reached.
|
| + }
|
| +
|
| + @Override
|
| + protected boolean hasAction() {
|
| + return false;
|
| + }
|
| + }
|
| +
|
| + private static class NoSnippets extends StatusItem {
|
| + private final ActionDelegate mActionDelegate;
|
| +
|
| + public NoSnippets(ActionDelegate actionDelegate) {
|
| + super(R.string.ntp_status_card_title_no_articles, R.string.ntp_status_card_no_articles,
|
| + R.string.reload);
|
| + mActionDelegate = actionDelegate;
|
| + Log.d(TAG, "Registering card for status: No Snippets");
|
| + }
|
| +
|
| + @Override
|
| + protected void performAction(Context context) {
|
| + mActionDelegate.onButtonTapped();
|
| + }
|
| + }
|
| +
|
| + private static final String TAG = "NtpCards";
|
| +
|
| private final int mHeaderStringId;
|
| private final int mDescriptionStringId;
|
| private final int mActionStringId;
|
| +
|
| + public static StatusItem create(
|
| + @CategoryStatusEnum int categoryStatus, @Nullable ActionDelegate actionDelegate) {
|
| + switch (categoryStatus) {
|
| + case CategoryStatus.SIGNED_OUT:
|
| + // Fall through. Sign out is a transitive state that we just use to clear content.
|
| + case CategoryStatus.AVAILABLE:
|
| + case CategoryStatus.AVAILABLE_LOADING:
|
| + case CategoryStatus.INITIALIZING:
|
| + // TODO(dgn): rewrite this whole thing? Get one card and change its state instead
|
| + // of recreating it. It would be more flexible in terms of adapting the content
|
| + // to different usages.
|
| + return actionDelegate == null ? new NoBookmarks() : new NoSnippets(actionDelegate);
|
| +
|
| + case CategoryStatus.ALL_SUGGESTIONS_EXPLICITLY_DISABLED:
|
| + Log.wtf(TAG, "Attempted to create a status card while the feature should be off.");
|
| + return null;
|
| +
|
| + case CategoryStatus.CATEGORY_EXPLICITLY_DISABLED:
|
| + // In this case, the entire section should have been cleared off the UI.
|
| + Log.wtf(TAG, "Attempted to create a status card for content suggestions "
|
| + + " when the category status is CATEGORY_EXPLICITLY_DISABLED.");
|
| + return null;
|
| +
|
| + case CategoryStatus.NOT_PROVIDED:
|
| + // In this case, the UI should remain as it is and also keep the previous category
|
| + // status, so the NOT_PROVIDED should never reach here.
|
| + Log.wtf(TAG, "Attempted to create a status card for content suggestions "
|
| + + " when the category is NOT_PROVIDED.");
|
| + return null;
|
| +
|
| + case CategoryStatus.LOADING_ERROR:
|
| + // In this case, the entire section should have been cleared off the UI.
|
| + Log.wtf(TAG, "Attempted to create a status card for content suggestions "
|
| + + " when the category is LOADING_ERROR.");
|
| + return null;
|
| +
|
| + default:
|
| + Log.wtf(TAG, "Attempted to create a status card for an unknown value: %d",
|
| + categoryStatus);
|
| + return null;
|
| + }
|
| + }
|
|
|
| protected StatusItem(int headerStringId, int descriptionStringId, int actionStringId) {
|
| mHeaderStringId = headerStringId;
|
| @@ -23,15 +113,10 @@
|
| mActionStringId = actionStringId;
|
| }
|
|
|
| - public static StatusItem createNoSuggestionsItem(SuggestionsCategoryInfo categoryInfo) {
|
| - return new StatusItem(R.string.ntp_status_card_title_no_suggestions,
|
| - categoryInfo.getNoSuggestionDescription(), 0);
|
| - }
|
| -
|
| - protected void performAction(Context context) {}
|
| + protected abstract void performAction(Context context);
|
|
|
| protected boolean hasAction() {
|
| - return mActionStringId != 0;
|
| + return true;
|
| }
|
|
|
| @Override
|
|
|