Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2910)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/StatusItem.java

Issue 2401643004: 📰 [Reland] Use the separate button style for the NoArticles status (Closed)
Patch Set: rebase 😠 Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 b412d7756979addd742647c9e78536de58e19dd4..df6fd9631313dd75e560b885d633c5cfc8428c06 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,118 +5,33 @@
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 about the NTP suggestions: there is no more available suggested content, sync
- * should be enabled, etc.
+ * configuration that affects the NTP suggestions.
*/
-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";
-
+public class StatusItem implements NewTabPageItem {
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;
mDescriptionStringId = descriptionStringId;
mActionStringId = actionStringId;
}
- protected abstract void performAction(Context context);
+ 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 boolean hasAction() {
- return true;
+ return mActionStringId != 0;
}
@Override

Powered by Google App Engine
This is Rietveld 408576698