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 e03b43906784a557246079bc7fc28a5a0f55c825..fa9ce9aa34f405914c33b6da253be7b21fba22a7 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,6 +5,7 @@ |
package org.chromium.chrome.browser.ntp.cards; |
import android.content.Context; |
+import android.support.annotation.Nullable; |
import android.view.View; |
import android.view.View.OnClickListener; |
import android.widget.Button; |
@@ -26,6 +27,12 @@ |
*/ |
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(); } |
+ |
+ /** |
* ViewHolder for an item of type {@link #VIEW_TYPE_STATUS}. |
*/ |
public static class ViewHolder extends CardViewHolder { |
@@ -65,20 +72,37 @@ public void onClick(View v) { |
} |
} |
+ 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 NewTabPageAdapter mNewTabPageAdapter; |
+ private final ActionDelegate mActionDelegate; |
- public NoSnippets(NewTabPageAdapter adapter) { |
- super(R.string.ntp_status_card_title_empty, |
- R.string.ntp_status_card_body_empty, |
+ public NoSnippets(ActionDelegate actionDelegate) { |
+ super(R.string.ntp_status_card_title_no_articles, R.string.ntp_status_card_no_articles, |
R.string.reload); |
- mNewTabPageAdapter = adapter; |
+ mActionDelegate = actionDelegate; |
Log.d(TAG, "Registering card for status: No Snippets"); |
} |
@Override |
protected void performAction(Context context) { |
- mNewTabPageAdapter.reloadSnippets(); |
+ mActionDelegate.onButtonTapped(); |
} |
} |
@@ -104,14 +128,16 @@ protected void performAction(Context context) { |
private final int mDescriptionStringId; |
private final int mActionStringId; |
- public static StatusItem create(@CategoryStatusEnum int categoryStatus, |
- NewTabPageAdapter adapter) { |
+ public static StatusItem create( |
+ @CategoryStatusEnum int categoryStatus, @Nullable ActionDelegate actionDelegate) { |
switch (categoryStatus) { |
- // TODO(dgn): AVAILABLE_LOADING and INITIALIZING should show a progress indicator. |
case CategoryStatus.AVAILABLE: |
case CategoryStatus.AVAILABLE_LOADING: |
case CategoryStatus.INITIALIZING: |
- return new NoSnippets(adapter); |
+ // 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.SIGNED_OUT: |
return new SignedOut(); |