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

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

Issue 2407283002: Extract a DataSource interface for items shown in a status card. (Closed)
Patch Set: blergh 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/StatusCardViewHolder.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/StatusCardViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/StatusCardViewHolder.java
index 7b745d78993c48371fce45bf0ca3864054ce2c08..cf561cc26dad44d2e3c6a629590c6310c5264c6a 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/StatusCardViewHolder.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/StatusCardViewHolder.java
@@ -4,6 +4,9 @@
package org.chromium.chrome.browser.ntp.cards;
+import android.content.Context;
+import android.support.annotation.IntegerRes;
+import android.support.annotation.StringRes;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@@ -26,14 +29,46 @@ public class StatusCardViewHolder extends CardViewHolder {
mActionView = (Button) itemView.findViewById(R.id.status_action_button);
}
- public void onBindViewHolder(final StatusItem item) {
+ /**
+ * Interface for data items that will be shown in this card.
+ */
+ public interface DataSource {
+ /**
+ * @return Resource ID for the header string.
+ */
+ @StringRes
+ int getHeader();
+
+ /**
+ * @return Resource ID for the description string.
+ */
+ @StringRes
+ int getDescription();
+
+ /**
+ * @return Resource ID for the action label string, or 0 if the card does not have a label.
+ */
+ @StringRes
+ int getActionLabel();
+
+ /**
+ * Called when the user clicks on the action button.
+ *
+ * @param context The context to execute the action in.
+ */
+ void performAction(Context context);
+ }
+
+ public void onBindViewHolder(final DataSource item) {
super.onBindViewHolder();
mTitleView.setText(item.getHeader());
mBodyView.setText(item.getDescription());
- if (item.hasAction()) {
- mActionView.setText(item.getActionLabel());
+ @IntegerRes
+ int actionLabel = item.getActionLabel();
+ if (actionLabel != 0) {
+ mActionView.setText(actionLabel);
mActionView.setOnClickListener(new View.OnClickListener() {
@Override

Powered by Google App Engine
This is Rietveld 408576698