Niedzielski has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311909

Change subject: Hygiene: unify feed card interface
......................................................................

Hygiene: unify feed card interface

Handle all feed cards in the same way. Also, use set/get prefixes to
avoid less obvious mistakes like calling super.card() instead of
super.card(Card) when overriding card(Card).

Change-Id: Icda23061f7d07b73cccebaa74fb7907f695d2786
---
M 
app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadCardView.java
M 
app/src/main/java/org/wikipedia/feed/continuereading/ContinueReadingCardView.java
M app/src/main/java/org/wikipedia/feed/featured/FeaturedArticleCardView.java
M app/src/main/java/org/wikipedia/feed/image/FeaturedImageCardView.java
M app/src/main/java/org/wikipedia/feed/mainpage/MainPageCardView.java
M app/src/main/java/org/wikipedia/feed/model/CardType.java
M app/src/main/java/org/wikipedia/feed/mostread/MostReadCardView.java
M app/src/main/java/org/wikipedia/feed/news/NewsListCardView.java
M app/src/main/java/org/wikipedia/feed/progress/ProgressCardView.java
M app/src/main/java/org/wikipedia/feed/random/RandomCardView.java
M app/src/main/java/org/wikipedia/feed/searchbar/SearchCardView.java
A app/src/main/java/org/wikipedia/feed/view/DefaultFeedCardView.java
M app/src/main/java/org/wikipedia/feed/view/FeedAdapter.java
M app/src/main/java/org/wikipedia/feed/view/FeedCardView.java
M app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java
M app/src/main/java/org/wikipedia/feed/view/ListCardView.java
M app/src/main/java/org/wikipedia/feed/view/StaticCardView.java
17 files changed, 134 insertions(+), 151 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/09/311909/1

diff --git 
a/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadCardView.java
 
b/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadCardView.java
index 5d1ed1a..7bb7fce 100644
--- 
a/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadCardView.java
+++ 
b/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadCardView.java
@@ -19,14 +19,15 @@
 
 import java.util.List;
 
-public class BecauseYouReadCardView extends ListCardView
+public class BecauseYouReadCardView extends ListCardView<BecauseYouReadCard>
         implements ItemTouchHelperSwipeAdapter.SwipeableView {
 
     public BecauseYouReadCardView(Context context) {
         super(context);
     }
 
-    public void set(@NonNull final BecauseYouReadCard card) {
+    @Override public void setCard(@NonNull BecauseYouReadCard card) {
+        super.setCard(card);
         header(card);
         set(new RecyclerAdapter(card.items(), getCallback()));
     }
diff --git 
a/app/src/main/java/org/wikipedia/feed/continuereading/ContinueReadingCardView.java
 
b/app/src/main/java/org/wikipedia/feed/continuereading/ContinueReadingCardView.java
index a5c8a63..d9e26ad 100644
--- 
a/app/src/main/java/org/wikipedia/feed/continuereading/ContinueReadingCardView.java
+++ 
b/app/src/main/java/org/wikipedia/feed/continuereading/ContinueReadingCardView.java
@@ -12,16 +12,14 @@
 import org.wikipedia.history.HistoryEntry;
 import org.wikipedia.views.ItemTouchHelperSwipeAdapter;
 
-public class ContinueReadingCardView extends ListCardView
+public class ContinueReadingCardView extends ListCardView<ContinueReadingCard>
         implements ItemTouchHelperSwipeAdapter.SwipeableView {
-    private ContinueReadingCard card;
-
     public ContinueReadingCardView(Context context) {
         super(context);
     }
 
-    public void set(@NonNull ContinueReadingCard card) {
-        this.card = card;
+    @Override public void setCard(@NonNull ContinueReadingCard card) {
+        super.setCard(card);
         header(card);
     }
 
@@ -46,9 +44,10 @@
     private class CardClickListener implements OnClickListener {
         @Override
         public void onClick(View v) {
-            if (getCallback() != null) {
-                getCallback().onSelectPage(new HistoryEntry(card.pageTitle(), 
HistoryEntry.SOURCE_FEED_CONTINUE_READING));
+            if (getCallback() != null && getCard() != null) {
+                getCallback().onSelectPage(new 
HistoryEntry(getCard().pageTitle(),
+                        HistoryEntry.SOURCE_FEED_CONTINUE_READING));
             }
         }
     }
-}
+}
\ No newline at end of file
diff --git 
a/app/src/main/java/org/wikipedia/feed/featured/FeaturedArticleCardView.java 
b/app/src/main/java/org/wikipedia/feed/featured/FeaturedArticleCardView.java
index 0748f0c..40e5531 100644
--- a/app/src/main/java/org/wikipedia/feed/featured/FeaturedArticleCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/featured/FeaturedArticleCardView.java
@@ -10,7 +10,7 @@
 import org.wikipedia.R;
 import org.wikipedia.feed.view.ActionFooterView;
 import org.wikipedia.feed.view.CardHeaderView;
-import org.wikipedia.feed.view.FeedCardView;
+import org.wikipedia.feed.view.DefaultFeedCardView;
 import org.wikipedia.history.HistoryEntry;
 import org.wikipedia.views.FaceAndColorDetectImageView;
 import org.wikipedia.views.GoneIfEmptyTextView;
@@ -20,7 +20,7 @@
 import butterknife.BindView;
 import butterknife.ButterKnife;
 
-public class FeaturedArticleCardView extends FeedCardView
+public class FeaturedArticleCardView extends 
DefaultFeedCardView<FeaturedArticleCard>
         implements ItemTouchHelperSwipeAdapter.SwipeableView {
     @BindView(R.id.view_featured_article_card_header) View headerView;
     @BindView(R.id.view_featured_article_card_footer) View footerView;
@@ -30,16 +30,15 @@
     @BindView(R.id.view_featured_article_card_extract) TextView extractView;
     @BindView(R.id.view_featured_article_card_text_container) View 
textContainerView;
 
-    private FeaturedArticleCard card;
-
     public FeaturedArticleCardView(Context context) {
         super(context);
         inflate(getContext(), R.layout.view_card_featured_article, this);
         ButterKnife.bind(this);
     }
 
-    public void set(@NonNull FeaturedArticleCard card) {
-        this.card = card;
+    @Override public void setCard(@NonNull FeaturedArticleCard card) {
+        super.setCard(card);
+
         String articleTitle = card.articleTitle();
         String articleSubtitle = card.articleSubtitle();
         String extract = card.extract();
@@ -114,8 +113,8 @@
     private class CardClickListener implements OnClickListener {
         @Override
         public void onClick(View v) {
-            if (getCallback() != null) {
-                
getCallback().onSelectPage(card.historyEntry(HistoryEntry.SOURCE_FEED_FEATURED));
+            if (getCallback() != null && getCard() != null) {
+                
getCallback().onSelectPage(getCard().historyEntry(HistoryEntry.SOURCE_FEED_FEATURED));
             }
         }
     }
@@ -123,8 +122,8 @@
     private class CardSaveListener implements OnClickListener {
         @Override
         public void onClick(View v) {
-            if (getCallback() != null) {
-                
getCallback().onAddPageToList(card.historyEntry(HistoryEntry.SOURCE_FEED_FEATURED));
+            if (getCallback() != null && getCard() != null) {
+                
getCallback().onAddPageToList(getCard().historyEntry(HistoryEntry.SOURCE_FEED_FEATURED));
             }
         }
     }
@@ -132,8 +131,8 @@
     private class CardShareListener implements OnClickListener {
         @Override
         public void onClick(View v) {
-            if (getCallback() != null) {
-                
getCallback().onSharePage(card.historyEntry(HistoryEntry.SOURCE_FEED_FEATURED));
+            if (getCallback() != null && getCard() != null) {
+                
getCallback().onSharePage(getCard().historyEntry(HistoryEntry.SOURCE_FEED_FEATURED));
             }
         }
     }
diff --git 
a/app/src/main/java/org/wikipedia/feed/image/FeaturedImageCardView.java 
b/app/src/main/java/org/wikipedia/feed/image/FeaturedImageCardView.java
index 8ded0d9..e233f4d 100644
--- a/app/src/main/java/org/wikipedia/feed/image/FeaturedImageCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/image/FeaturedImageCardView.java
@@ -3,14 +3,13 @@
 import android.content.Context;
 import android.net.Uri;
 import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
 import android.view.View;
 import android.widget.TextView;
 
 import org.wikipedia.R;
 import org.wikipedia.feed.view.ActionFooterView;
 import org.wikipedia.feed.view.CardHeaderView;
-import org.wikipedia.feed.view.FeedCardView;
+import org.wikipedia.feed.view.DefaultFeedCardView;
 import org.wikipedia.richtext.RichTextUtil;
 import org.wikipedia.util.StringUtil;
 import org.wikipedia.views.FaceAndColorDetectImageView;
@@ -20,9 +19,8 @@
 import butterknife.BindView;
 import butterknife.ButterKnife;
 
-public class FeaturedImageCardView extends FeedCardView
+public class FeaturedImageCardView extends 
DefaultFeedCardView<FeaturedImageCard>
         implements ItemTouchHelperSwipeAdapter.SwipeableView {
-    @Nullable private FeaturedImageCard card;
     @BindView(R.id.view_featured_image_card_header) View headerView;
     @BindView(R.id.view_featured_image_card_footer) View footerView;
     @BindView(R.id.view_featured_image_card_image) FaceAndColorDetectImageView 
imageView;
@@ -34,8 +32,8 @@
         ButterKnife.bind(this);
     }
 
-    public void set(@NonNull FeaturedImageCard card) {
-        this.card = card;
+    @Override public void setCard(@NonNull FeaturedImageCard card) {
+        super.setCard(card);
         // TODO: superimpose text onto image thumb
         image(card.image());
         description(StringUtil.defaultIfNull(card.description(), ""));  //Can 
check language before doing this if we want
@@ -88,8 +86,8 @@
     private class CardClickListener implements OnClickListener {
         @Override
         public void onClick(View v) {
-            if (getCallback() != null) {
-                getCallback().onFeaturedImageSelected(card);
+            if (getCallback() != null && getCard() != null) {
+                getCallback().onFeaturedImageSelected(getCard());
             }
         }
     }
@@ -97,8 +95,8 @@
     private class CardDownloadListener implements OnClickListener {
         @Override
         public void onClick(View v) {
-            if (getCallback() != null) {
-                getCallback().onDownloadImage(card.baseImage());
+            if (getCallback() != null && getCard() != null) {
+                getCallback().onDownloadImage(getCard().baseImage());
             }
         }
     }
@@ -106,8 +104,8 @@
     private class CardShareListener implements OnClickListener {
         @Override
         public void onClick(View v) {
-            if (getCallback() != null) {
-                getCallback().onShareImage(card);
+            if (getCallback() != null && getCard() != null) {
+                getCallback().onShareImage(getCard());
             }
         }
     }
diff --git 
a/app/src/main/java/org/wikipedia/feed/mainpage/MainPageCardView.java 
b/app/src/main/java/org/wikipedia/feed/mainpage/MainPageCardView.java
index 69a39bc..fb87390 100644
--- a/app/src/main/java/org/wikipedia/feed/mainpage/MainPageCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/mainpage/MainPageCardView.java
@@ -16,24 +16,22 @@
 import java.text.DateFormat;
 import java.util.Date;
 
-public class MainPageCardView extends StaticCardView {
-    @Nullable private FeedViewCallback callback;
-
+public class MainPageCardView extends StaticCardView<MainPageCard> {
     public MainPageCardView(@NonNull Context context) {
         super(context);
     }
 
-    public void set(@NonNull final MainPageCard card) {
+    @Override public void setCard(@NonNull final MainPageCard card) {
+        super.setCard(card);
         setTitle(getString(R.string.view_main_page_card_title));
         
setSubtitle(String.format(getString(R.string.view_main_page_card_subtitle),
                 DateFormat.getDateInstance().format(new Date())));
         setIcon(R.drawable.icon_feed_today);
-        setOnClickListener(new CallbackAdapter(callback));
     }
 
-    @NonNull public MainPageCardView setCallback(@Nullable FeedViewCallback 
callback) {
-        this.callback = callback;
-        return this;
+    @Override public void setCallback(@Nullable FeedViewCallback callback) {
+        super.setCallback(callback);
+        setOnClickListener(new CallbackAdapter(callback));
     }
 
     private static class CallbackAdapter implements OnClickListener {
diff --git a/app/src/main/java/org/wikipedia/feed/model/CardType.java 
b/app/src/main/java/org/wikipedia/feed/model/CardType.java
index b8a463a..983230c 100644
--- a/app/src/main/java/org/wikipedia/feed/model/CardType.java
+++ b/app/src/main/java/org/wikipedia/feed/model/CardType.java
@@ -14,52 +14,53 @@
 import org.wikipedia.feed.progress.ProgressCardView;
 import org.wikipedia.feed.random.RandomCardView;
 import org.wikipedia.feed.searchbar.SearchCardView;
+import org.wikipedia.feed.view.FeedCardView;
 import org.wikipedia.model.EnumCode;
 import org.wikipedia.model.EnumCodeMap;
 
 public enum CardType implements EnumCode {
     SEARCH_BAR(0) {
-        @NonNull @Override public View newView(@NonNull Context ctx) {
+        @NonNull @Override public FeedCardView<?> newView(@NonNull Context 
ctx) {
             return new SearchCardView(ctx);
         }
     },
     CONTINUE_READING(1) {
-        @NonNull @Override public View newView(@NonNull Context ctx) {
+        @NonNull @Override public FeedCardView<?> newView(@NonNull Context 
ctx) {
             return new ContinueReadingCardView(ctx);
         }
     },
     BECAUSE_YOU_READ_LIST(2) {
-        @NonNull @Override public View newView(@NonNull Context ctx) {
+        @NonNull @Override public FeedCardView<?> newView(@NonNull Context 
ctx) {
             return new BecauseYouReadCardView(ctx);
         }
     },
     MOST_READ_LIST(3) {
-        @NonNull @Override public View newView(@NonNull Context ctx) {
+        @NonNull @Override public FeedCardView<?> newView(@NonNull Context 
ctx) {
             return new MostReadCardView(ctx);
         }
     },
     FEATURED_ARTICLE(4) {
-        @NonNull @Override public View newView(@NonNull Context ctx) {
+        @NonNull @Override public FeedCardView<?> newView(@NonNull Context 
ctx) {
             return new FeaturedArticleCardView(ctx);
         }
     },
     RANDOM(5) {
-        @NonNull @Override public View newView(@NonNull Context ctx) {
+        @NonNull @Override public FeedCardView<?> newView(@NonNull Context 
ctx) {
             return new RandomCardView(ctx);
         }
     },
     MAIN_PAGE(6) {
-        @NonNull @Override public View newView(@NonNull Context ctx) {
+        @NonNull @Override public FeedCardView<?> newView(@NonNull Context 
ctx) {
             return new MainPageCardView(ctx);
         }
     },
     NEWS_LIST(7) {
-        @NonNull @Override public View newView(@NonNull Context ctx) {
+        @NonNull @Override public FeedCardView<?> newView(@NonNull Context 
ctx) {
             return new NewsListCardView(ctx);
         }
     },
     FEATURED_IMAGE(8) {
-        @NonNull @Override public View newView(@NonNull Context ctx) {
+        @NonNull @Override public FeedCardView<?> newView(@NonNull Context 
ctx) {
             return new FeaturedImageCardView(ctx);
         }
     },
@@ -68,7 +69,7 @@
     NEWS_ITEM(11),
     NEWS_ITEM_LINK(12),
     PROGRESS(99) {
-        @NonNull @Override public View newView(@NonNull Context ctx) {
+        @NonNull @Override public FeedCardView<?> newView(@NonNull Context 
ctx) {
             return new ProgressCardView(ctx);
         }
     };
@@ -80,7 +81,7 @@
         return MAP.get(code);
     }
 
-    @NonNull public View newView(@NonNull Context ctx) {
+    @NonNull public FeedCardView<?> newView(@NonNull Context ctx) {
         throw new UnsupportedOperationException();
     }
 
diff --git 
a/app/src/main/java/org/wikipedia/feed/mostread/MostReadCardView.java 
b/app/src/main/java/org/wikipedia/feed/mostread/MostReadCardView.java
index 18c1898..1fdba5f 100644
--- a/app/src/main/java/org/wikipedia/feed/mostread/MostReadCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/mostread/MostReadCardView.java
@@ -16,13 +16,14 @@
 
 import java.util.List;
 
-public class MostReadCardView extends ListCardView
+public class MostReadCardView extends ListCardView<MostReadListCard>
         implements ItemTouchHelperSwipeAdapter.SwipeableView {
     public MostReadCardView(Context context) {
         super(context);
     }
 
-    public void set(@NonNull MostReadListCard card) {
+    @Override public void setCard(@NonNull MostReadListCard card) {
+        super.setCard(card);
         header(card);
         set(new RecyclerAdapter(card.items(), getCallback()));
     }
diff --git a/app/src/main/java/org/wikipedia/feed/news/NewsListCardView.java 
b/app/src/main/java/org/wikipedia/feed/news/NewsListCardView.java
index d3e82e1..9787b65 100644
--- a/app/src/main/java/org/wikipedia/feed/news/NewsListCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/news/NewsListCardView.java
@@ -16,14 +16,15 @@
 
 import java.util.List;
 
-public class NewsListCardView extends HorizontalScrollingListCardView
+public class NewsListCardView extends 
HorizontalScrollingListCardView<NewsListCard>
         implements ItemTouchHelperSwipeAdapter.SwipeableView {
 
     public NewsListCardView(@NonNull Context context) {
         super(context);
     }
 
-    public void set(@NonNull NewsListCard card) {
+    @Override public void setCard(@NonNull NewsListCard card) {
+        super.setCard(card);
         header(card);
         set(new RecyclerAdapter(card.items(), getCallback()));
     }
diff --git 
a/app/src/main/java/org/wikipedia/feed/progress/ProgressCardView.java 
b/app/src/main/java/org/wikipedia/feed/progress/ProgressCardView.java
index 3b804da..c041574 100644
--- a/app/src/main/java/org/wikipedia/feed/progress/ProgressCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/progress/ProgressCardView.java
@@ -1,13 +1,21 @@
 package org.wikipedia.feed.progress;
 
 import android.content.Context;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 import android.widget.FrameLayout;
 
 import org.wikipedia.R;
+import org.wikipedia.feed.model.Card;
+import org.wikipedia.feed.view.FeedCardView;
+import org.wikipedia.feed.view.FeedViewCallback;
 
-public class ProgressCardView extends FrameLayout {
+public class ProgressCardView extends FrameLayout implements 
FeedCardView<Card> {
     public ProgressCardView(Context context) {
         super(context);
         inflate(getContext(), R.layout.view_card_progress, this);
     }
+
+    @Override public void setCard(@NonNull Card card) { }
+    @Override public void setCallback(@Nullable FeedViewCallback callback) { }
 }
\ No newline at end of file
diff --git a/app/src/main/java/org/wikipedia/feed/random/RandomCardView.java 
b/app/src/main/java/org/wikipedia/feed/random/RandomCardView.java
index 7e283ce..1cb941e 100644
--- a/app/src/main/java/org/wikipedia/feed/random/RandomCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/random/RandomCardView.java
@@ -13,37 +13,35 @@
 import org.wikipedia.random.RandomSummaryService;
 import org.wikipedia.util.log.L;
 
-public class RandomCardView extends StaticCardView {
-    @Nullable private FeedViewCallback callback;
-
+public class RandomCardView extends StaticCardView<RandomCard> {
     public RandomCardView(@NonNull Context context) {
         super(context);
     }
 
-    public void set(@NonNull final RandomCard card) {
+    @Override public void setCard(@NonNull RandomCard card) {
+        super.setCard(card);
         setTitle(getString(R.string.view_random_card_title));
         setSubtitle(getString(R.string.view_random_card_subtitle));
         setIcon(R.drawable.icon_feed_random);
-        setOnClickListener(new CallbackAdapter(card, callback));
     }
 
-    @NonNull public RandomCardView setCallback(@Nullable FeedViewCallback 
callback) {
-        this.callback = callback;
-        return this;
+    @Override public void setCallback(@Nullable FeedViewCallback callback) {
+        super.setCallback(callback);
+        setOnClickListener(new CallbackAdapter(callback));
     }
 
-    private static class CallbackAdapter implements OnClickListener {
-        @NonNull private final RandomCard card;
+    private class CallbackAdapter implements OnClickListener {
         @Nullable private final FeedViewCallback callback;
 
-        CallbackAdapter(@NonNull final RandomCard card, @Nullable 
FeedViewCallback callback) {
-            this.card = card;
+        CallbackAdapter(@Nullable FeedViewCallback callback) {
             this.callback = callback;
         }
 
         @Override
         public void onClick(View view) {
-            new RandomSummaryService(card.site(), serviceCallback).get();
+            if (callback != null && getCard() != null) {
+                new RandomSummaryService(getCard().site(), 
serviceCallback).get();
+            }
         }
 
         private RandomSummaryService.RandomSummaryCallback serviceCallback
@@ -61,4 +59,4 @@
             }
         };
     }
-}
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/wikipedia/feed/searchbar/SearchCardView.java 
b/app/src/main/java/org/wikipedia/feed/searchbar/SearchCardView.java
index d1ab1ca..6acf685 100644
--- a/app/src/main/java/org/wikipedia/feed/searchbar/SearchCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/searchbar/SearchCardView.java
@@ -1,17 +1,16 @@
 package org.wikipedia.feed.searchbar;
 
 import android.content.Context;
-import android.support.annotation.NonNull;
 import android.view.View;
 
 import org.wikipedia.R;
-import org.wikipedia.feed.view.FeedCardView;
+import org.wikipedia.feed.view.DefaultFeedCardView;
 import org.wikipedia.util.FeedbackUtil;
 
 import butterknife.BindView;
 import butterknife.ButterKnife;
 
-public class SearchCardView extends FeedCardView {
+public class SearchCardView extends DefaultFeedCardView<SearchCard> {
     @BindView(R.id.search_container) View searchContainer;
     @BindView(R.id.voice_search_button) View voiceSearchButton;
 
@@ -39,8 +38,5 @@
                 }
             }
         });
-    }
-
-    public void set(@NonNull SearchCard card) {
     }
 }
\ No newline at end of file
diff --git a/app/src/main/java/org/wikipedia/feed/view/DefaultFeedCardView.java 
b/app/src/main/java/org/wikipedia/feed/view/DefaultFeedCardView.java
new file mode 100644
index 0000000..67d88ab
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/feed/view/DefaultFeedCardView.java
@@ -0,0 +1,33 @@
+package org.wikipedia.feed.view;
+
+import android.content.Context;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v7.widget.CardView;
+
+import org.wikipedia.feed.model.Card;
+
+public abstract class DefaultFeedCardView<T extends Card> extends CardView 
implements FeedCardView<T> {
+    @Nullable private T card;
+    @Nullable private FeedViewCallback callback;
+
+    public DefaultFeedCardView(Context context) {
+        super(context);
+    }
+
+    @Override public void setCard(@NonNull T card) {
+        this.card = card;
+    }
+
+    @Override public void setCallback(@Nullable FeedViewCallback callback) {
+        this.callback = callback;
+    }
+
+    @Nullable protected T getCard() {
+        return card;
+    }
+
+    @Nullable protected FeedViewCallback getCallback() {
+        return callback;
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/wikipedia/feed/view/FeedAdapter.java 
b/app/src/main/java/org/wikipedia/feed/view/FeedAdapter.java
index 2a251cd..fa6c99d 100644
--- a/app/src/main/java/org/wikipedia/feed/view/FeedAdapter.java
+++ b/app/src/main/java/org/wikipedia/feed/view/FeedAdapter.java
@@ -7,30 +7,12 @@
 import android.view.ViewGroup;
 
 import org.wikipedia.feed.FeedCoordinatorBase;
-import org.wikipedia.feed.becauseyouread.BecauseYouReadCard;
-import org.wikipedia.feed.becauseyouread.BecauseYouReadCardView;
-import org.wikipedia.feed.continuereading.ContinueReadingCard;
-import org.wikipedia.feed.continuereading.ContinueReadingCardView;
-import org.wikipedia.feed.featured.FeaturedArticleCard;
-import org.wikipedia.feed.featured.FeaturedArticleCardView;
-import org.wikipedia.feed.image.FeaturedImageCard;
-import org.wikipedia.feed.image.FeaturedImageCardView;
-import org.wikipedia.feed.mainpage.MainPageCard;
-import org.wikipedia.feed.mainpage.MainPageCardView;
 import org.wikipedia.feed.model.Card;
 import org.wikipedia.feed.model.CardType;
-import org.wikipedia.feed.mostread.MostReadCardView;
-import org.wikipedia.feed.mostread.MostReadListCard;
-import org.wikipedia.feed.news.NewsListCard;
-import org.wikipedia.feed.news.NewsListCardView;
-import org.wikipedia.feed.random.RandomCard;
-import org.wikipedia.feed.random.RandomCardView;
-import org.wikipedia.feed.searchbar.SearchCard;
-import org.wikipedia.feed.searchbar.SearchCardView;
 import org.wikipedia.views.DefaultRecyclerAdapter;
 import org.wikipedia.views.DefaultViewHolder;
 
-public class FeedAdapter extends DefaultRecyclerAdapter<Card, View> {
+public class FeedAdapter<T extends View & FeedCardView<?>> extends 
DefaultRecyclerAdapter<Card, T> {
     @NonNull private FeedCoordinatorBase coordinator;
     @Nullable private FeedViewCallback callback;
 
@@ -40,13 +22,13 @@
         this.callback = callback;
     }
 
-    @Override public DefaultViewHolder<View> onCreateViewHolder(ViewGroup 
parent, int viewType) {
+    @Override public DefaultViewHolder<T> onCreateViewHolder(ViewGroup parent, 
int viewType) {
         return new DefaultViewHolder<>(newView(parent.getContext(), viewType));
     }
 
-    @Override public void onBindViewHolder(DefaultViewHolder<View> holder, int 
position) {
+    @Override public void onBindViewHolder(DefaultViewHolder<T> holder, int 
position) {
         Card item = item(position);
-        View view = holder.getView();
+        T view = holder.getView();
 
         if (coordinator.finished()
                 && position == getItemCount() - 1
@@ -60,41 +42,19 @@
         }
         associateCardWithView(view, item);
 
-        if (view instanceof ContinueReadingCardView) {
-            ((ContinueReadingCardView) view).set((ContinueReadingCard) item);
-        } else if (view instanceof BecauseYouReadCardView) {
-            ((BecauseYouReadCardView) view).set((BecauseYouReadCard) item);
-        } else if (view instanceof SearchCardView) {
-            ((SearchCardView) view).set((SearchCard) item);
-        } else if (view instanceof MostReadCardView) {
-            ((MostReadCardView) view).set((MostReadListCard) item);
-        } else if (view instanceof FeaturedArticleCardView) {
-            ((FeaturedArticleCardView) view).set((FeaturedArticleCard) item);
-        } else if (view instanceof RandomCardView) {
-            ((RandomCardView) view).set((RandomCard) item);
-        } else if (view instanceof NewsListCardView) {
-            ((NewsListCardView) view).set((NewsListCard) item);
-        } else if (view instanceof MainPageCardView) {
-            ((MainPageCardView) view).set((MainPageCard) item);
-        } else if (view instanceof FeaturedImageCardView) {
-            ((FeaturedImageCardView) view).set((FeaturedImageCard) item);
-        }
+        //noinspection unchecked
+        ((FeedCardView<Card>) view).setCard(item);
     }
 
     @Override public int getItemViewType(int position) {
         return item(position).type().code();
     }
 
-    @NonNull private View newView(@NonNull Context context, int viewType) {
-        View view = CardType.of(viewType).newView(context);
-        if (view instanceof FeedCardView) {
-            ((FeedCardView) view).setCallback(callback);
-        } else if (view instanceof RandomCardView) {
-            ((RandomCardView) view).setCallback(callback);
-        } else if (view instanceof MainPageCardView) {
-            ((MainPageCardView) view).setCallback(callback);
-        }
-        return view;
+    @NonNull private T newView(@NonNull Context context, int viewType) {
+        FeedCardView<?> view = CardType.of(viewType).newView(context);
+        view.setCallback(callback);
+        //noinspection unchecked
+        return (T) view;
     }
 
     private boolean isCardAssociatedWithView(@NonNull View view, @NonNull Card 
card) {
@@ -104,4 +64,4 @@
     private void associateCardWithView(@NonNull View view, @NonNull Card card) 
{
         view.setTag(card);
     }
-}
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/wikipedia/feed/view/FeedCardView.java 
b/app/src/main/java/org/wikipedia/feed/view/FeedCardView.java
index c03f20d..b07dde2 100644
--- a/app/src/main/java/org/wikipedia/feed/view/FeedCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/view/FeedCardView.java
@@ -1,23 +1,11 @@
 package org.wikipedia.feed.view;
 
-import android.content.Context;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
-import android.support.v7.widget.CardView;
 
-public class FeedCardView extends CardView {
-    @Nullable private FeedViewCallback callback;
+import org.wikipedia.feed.model.Card;
 
-    public FeedCardView(Context context) {
-        super(context);
-    }
-
-    @NonNull public FeedCardView setCallback(@Nullable FeedViewCallback 
callback) {
-        this.callback = callback;
-        return this;
-    }
-
-    @Nullable protected FeedViewCallback getCallback() {
-        return callback;
-    }
+public interface FeedCardView<T extends Card> {
+    void setCard(@NonNull T card);
+    void setCallback(@Nullable FeedViewCallback callback);
 }
\ No newline at end of file
diff --git 
a/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java
 
b/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java
index ce6bfaa..8f53e45 100644
--- 
a/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java
+++ 
b/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java
@@ -7,6 +7,7 @@
 import android.view.ViewGroup;
 
 import org.wikipedia.R;
+import org.wikipedia.feed.model.Card;
 import org.wikipedia.util.DimenUtil;
 import org.wikipedia.views.DefaultRecyclerAdapter;
 import org.wikipedia.views.DefaultViewHolder;
@@ -15,7 +16,7 @@
 
 import java.util.List;
 
-public abstract class HorizontalScrollingListCardView extends ListCardView {
+public abstract class HorizontalScrollingListCardView<T extends Card> extends 
ListCardView<T> {
     public HorizontalScrollingListCardView(@NonNull Context context) {
         super(context);
     }
diff --git a/app/src/main/java/org/wikipedia/feed/view/ListCardView.java 
b/app/src/main/java/org/wikipedia/feed/view/ListCardView.java
index 9e3f35c..369c141 100644
--- a/app/src/main/java/org/wikipedia/feed/view/ListCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/view/ListCardView.java
@@ -8,6 +8,7 @@
 import android.view.View;
 
 import org.wikipedia.R;
+import org.wikipedia.feed.model.Card;
 import org.wikipedia.util.ResourceUtil;
 import org.wikipedia.views.DrawableItemDecoration;
 import org.wikipedia.views.ViewUtil;
@@ -15,7 +16,7 @@
 import butterknife.BindView;
 import butterknife.ButterKnife;
 
-public abstract class ListCardView extends FeedCardView {
+public abstract class ListCardView<T extends Card> extends 
DefaultFeedCardView<T> {
     @BindView(R.id.view_list_card_header) View headerView;
     @BindView(R.id.view_list_card_large_header) View largeHeaderView;
     @BindView(R.id.view_list_card_list) RecyclerView recyclerView;
diff --git a/app/src/main/java/org/wikipedia/feed/view/StaticCardView.java 
b/app/src/main/java/org/wikipedia/feed/view/StaticCardView.java
index 2699536..7f9510a 100644
--- a/app/src/main/java/org/wikipedia/feed/view/StaticCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/view/StaticCardView.java
@@ -3,16 +3,16 @@
 import android.content.Context;
 import android.support.annotation.DrawableRes;
 import android.support.annotation.StringRes;
-import android.support.v7.widget.CardView;
 import android.widget.ImageView;
 import android.widget.TextView;
 
 import org.wikipedia.R;
+import org.wikipedia.feed.model.Card;
 
 import butterknife.BindView;
 import butterknife.ButterKnife;
 
-public abstract class StaticCardView extends CardView {
+public abstract class StaticCardView<T extends Card> extends 
DefaultFeedCardView<T> {
     @BindView(R.id.view_static_card_title) TextView title;
     @BindView(R.id.view_static_card_subtitle) TextView subtitle;
     @BindView(R.id.view_static_card_icon) ImageView icon;
@@ -39,4 +39,4 @@
     protected String getString(@StringRes int id) {
         return getResources().getString(id);
     }
-}
+}
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/311909
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icda23061f7d07b73cccebaa74fb7907f695d2786
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to