Chromium Code Reviews| 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 615d70c487ee0acd0ec7ef2bf321cf02a96c0c63..08ae06d8f8d46b36640ca8829533e596521cc457 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; |
| @@ -24,6 +25,13 @@ |
| * should be enabled, etc. |
| */ |
| 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 StatusActionDelegate { void onButtonTapped(); } |
|
Bernhard Bauer
2016/08/17 20:38:03
You could maybe remove the "Status" from here, as
dgn
2016/08/18 09:52:57
Done.
|
| + |
| /** |
| * ViewHolder for an item of type {@link #VIEW_TYPE_STATUS}. |
| */ |
| @@ -64,20 +72,37 @@ public void onClick(View v) { |
| } |
| } |
| + private static class NoBookmarks extends StatusItem { |
| + public NoBookmarks() { |
| + super(R.string.ntp_status_card_done_for_now, 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 StatusActionDelegate mActionDelegate; |
| - public NoSnippets(NewTabPageAdapter adapter) { |
| + public NoSnippets(StatusActionDelegate actionDelegate) { |
| super(R.string.ntp_status_card_title_empty, |
| R.string.ntp_status_card_body_empty, |
| 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(); |
| } |
| } |
| @@ -101,14 +126,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 StatusActionDelegate 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(); |