Niedzielski has uploaded a new change for review.

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

Change subject: Hygiene: make feed cards branch polymorphically
......................................................................

Hygiene: make feed cards branch polymorphically

Feed card types were encapsulated in a few large switches. This works
well enough but since similar functionality is expected of each
specialization, formalizing differences in a custom CardType seems less
error prone and more flexible.

Change-Id: I5e9480a8c5cd11485f068719bff689e6abb03366
---
M app/src/main/java/org/wikipedia/analytics/FeedFunnel.java
M app/src/main/java/org/wikipedia/feed/FeedFragment.java
M app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadCard.java
M 
app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadItemCard.java
M app/src/main/java/org/wikipedia/feed/continuereading/ContinueReadingCard.java
M app/src/main/java/org/wikipedia/feed/featured/FeaturedArticleCard.java
M app/src/main/java/org/wikipedia/feed/image/FeaturedImageCard.java
M app/src/main/java/org/wikipedia/feed/mainpage/MainPageCard.java
M app/src/main/java/org/wikipedia/feed/model/Card.java
A app/src/main/java/org/wikipedia/feed/model/CardType.java
M app/src/main/java/org/wikipedia/feed/mostread/MostReadItemCard.java
M app/src/main/java/org/wikipedia/feed/mostread/MostReadListCard.java
M app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java
M app/src/main/java/org/wikipedia/feed/news/NewsListCard.java
M app/src/main/java/org/wikipedia/feed/progress/ProgressCard.java
M app/src/main/java/org/wikipedia/feed/random/RandomCard.java
M app/src/main/java/org/wikipedia/feed/searchbar/SearchCard.java
M app/src/main/java/org/wikipedia/feed/view/FeedAdapter.java
M app/src/main/java/org/wikipedia/news/NewsLinkCard.java
19 files changed, 186 insertions(+), 71 deletions(-)


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

diff --git a/app/src/main/java/org/wikipedia/analytics/FeedFunnel.java 
b/app/src/main/java/org/wikipedia/analytics/FeedFunnel.java
index 9870231..b3fb63e 100644
--- a/app/src/main/java/org/wikipedia/analytics/FeedFunnel.java
+++ b/app/src/main/java/org/wikipedia/analytics/FeedFunnel.java
@@ -1,6 +1,9 @@
 package org.wikipedia.analytics;
 
+import android.support.annotation.NonNull;
+
 import org.wikipedia.WikipediaApp;
+import org.wikipedia.feed.model.CardType;
 
 public class FeedFunnel extends Funnel {
     private static final String SCHEMA_NAME = "MobileWikiAppFeed";
@@ -24,10 +27,10 @@
         );
     }
 
-    public void dismissCard(int cardType, int position) {
+    public void dismissCard(@NonNull CardType cardType, int position) {
         log(
                 "action", "dismiss",
-                "cardType", cardType,
+                "cardType", cardType.code(),
                 "position", position
         );
     }
diff --git a/app/src/main/java/org/wikipedia/feed/FeedFragment.java 
b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
index 472e094..83cedd1 100644
--- a/app/src/main/java/org/wikipedia/feed/FeedFragment.java
+++ b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
@@ -239,7 +239,7 @@
         @Override
         public boolean onRequestDismissCard(@NonNull Card card) {
             int position = coordinator.dismissCard(card);
-            funnel.dismissCard(FeedAdapter.getCardType(card), position);
+            funnel.dismissCard(card.type(), position);
             showDismissCardUndoSnackbar(card, position);
             return true;
         }
diff --git 
a/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadCard.java 
b/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadCard.java
index a980dab..fcf926b 100644
--- 
a/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadCard.java
+++ 
b/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadCard.java
@@ -7,6 +7,7 @@
 
 import org.wikipedia.R;
 import org.wikipedia.WikipediaApp;
+import org.wikipedia.feed.model.CardType;
 import org.wikipedia.feed.model.ListCard;
 import org.wikipedia.history.HistoryEntry;
 import org.wikipedia.page.PageTitle;
@@ -35,6 +36,10 @@
         return TextUtils.isEmpty(entry.getTitle().getThumbUrl()) ? null : 
Uri.parse(entry.getTitle().getThumbUrl());
     }
 
+    @NonNull @Override public CardType type() {
+        return CardType.BECAUSE_YOU_READ_LIST;
+    }
+
     public String pageTitle() {
         return entry.getTitle().getDisplayText();
     }
diff --git 
a/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadItemCard.java
 
b/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadItemCard.java
index dfe3580..1c67709 100644
--- 
a/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadItemCard.java
+++ 
b/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadItemCard.java
@@ -6,6 +6,7 @@
 import android.text.TextUtils;
 
 import org.wikipedia.feed.model.Card;
+import org.wikipedia.feed.model.CardType;
 import org.wikipedia.page.PageTitle;
 
 public class BecauseYouReadItemCard extends Card {
@@ -34,4 +35,8 @@
     @Override public Uri image() {
         return TextUtils.isEmpty(title.getThumbUrl()) ? null : 
Uri.parse(title.getThumbUrl());
     }
-}
+
+    @NonNull @Override public CardType type() {
+        return CardType.BECAUSE_YOU_READ_ITEM;
+    }
+}
\ No newline at end of file
diff --git 
a/app/src/main/java/org/wikipedia/feed/continuereading/ContinueReadingCard.java 
b/app/src/main/java/org/wikipedia/feed/continuereading/ContinueReadingCard.java
index 54840d6..6ed182c 100644
--- 
a/app/src/main/java/org/wikipedia/feed/continuereading/ContinueReadingCard.java
+++ 
b/app/src/main/java/org/wikipedia/feed/continuereading/ContinueReadingCard.java
@@ -6,6 +6,7 @@
 import android.text.TextUtils;
 
 import org.wikipedia.feed.model.Card;
+import org.wikipedia.feed.model.CardType;
 import org.wikipedia.history.HistoryEntry;
 import org.wikipedia.page.PageTitle;
 
@@ -30,6 +31,10 @@
         return TextUtils.isEmpty(entry.getTitle().getThumbUrl()) ? null : 
Uri.parse(entry.getTitle().getThumbUrl());
     }
 
+    @NonNull @Override public CardType type() {
+        return CardType.CONTINUE_READING;
+    }
+
     @NonNull public PageTitle pageTitle() {
         return entry.getTitle();
     }
diff --git 
a/app/src/main/java/org/wikipedia/feed/featured/FeaturedArticleCard.java 
b/app/src/main/java/org/wikipedia/feed/featured/FeaturedArticleCard.java
index 65c0c99..e5c2a52 100644
--- a/app/src/main/java/org/wikipedia/feed/featured/FeaturedArticleCard.java
+++ b/app/src/main/java/org/wikipedia/feed/featured/FeaturedArticleCard.java
@@ -7,6 +7,7 @@
 import org.wikipedia.R;
 import org.wikipedia.Site;
 import org.wikipedia.WikipediaApp;
+import org.wikipedia.feed.model.CardType;
 import org.wikipedia.feed.model.UtcDate;
 import org.wikipedia.feed.model.Card;
 import org.wikipedia.feed.model.CardPageItem;
@@ -66,6 +67,10 @@
         return page.extract();
     }
 
+    @NonNull @Override public CardType type() {
+        return CardType.FEATURED_ARTICLE;
+    }
+
     @NonNull
     public HistoryEntry historyEntry(int source) {
         PageTitle title = new PageTitle(articleTitle(), site());
diff --git a/app/src/main/java/org/wikipedia/feed/image/FeaturedImageCard.java 
b/app/src/main/java/org/wikipedia/feed/image/FeaturedImageCard.java
index 120a5c5..1e95b09 100644
--- a/app/src/main/java/org/wikipedia/feed/image/FeaturedImageCard.java
+++ b/app/src/main/java/org/wikipedia/feed/image/FeaturedImageCard.java
@@ -8,6 +8,7 @@
 import org.wikipedia.Site;
 import org.wikipedia.WikipediaApp;
 import org.wikipedia.feed.model.Card;
+import org.wikipedia.feed.model.CardType;
 import org.wikipedia.feed.model.UtcDate;
 import org.wikipedia.util.DateUtil;
 
@@ -60,6 +61,10 @@
         return featuredImage.thumbnail().source();
     }
 
+    @NonNull @Override public CardType type() {
+        return CardType.FEATURED_IMAGE;
+    }
+
     @Nullable
     public String description() {
         return featuredImage.description();
diff --git a/app/src/main/java/org/wikipedia/feed/mainpage/MainPageCard.java 
b/app/src/main/java/org/wikipedia/feed/mainpage/MainPageCard.java
index d312461..a455e9d 100644
--- a/app/src/main/java/org/wikipedia/feed/mainpage/MainPageCard.java
+++ b/app/src/main/java/org/wikipedia/feed/mainpage/MainPageCard.java
@@ -4,6 +4,7 @@
 
 import org.wikipedia.Site;
 import org.wikipedia.feed.model.Card;
+import org.wikipedia.feed.model.CardType;
 
 public class MainPageCard extends Card {
     @NonNull private Site site;
@@ -16,6 +17,10 @@
         return "";
     }
 
+    @NonNull @Override public CardType type() {
+        return CardType.MAIN_PAGE;
+    }
+
     public Site site() {
         return site;
     }
diff --git a/app/src/main/java/org/wikipedia/feed/model/Card.java 
b/app/src/main/java/org/wikipedia/feed/model/Card.java
index e360f60..3234382 100644
--- a/app/src/main/java/org/wikipedia/feed/model/Card.java
+++ b/app/src/main/java/org/wikipedia/feed/model/Card.java
@@ -4,7 +4,6 @@
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 
-import org.wikipedia.feed.view.FeedAdapter;
 import org.wikipedia.model.BaseModel;
 
 public abstract class Card extends BaseModel {
@@ -22,8 +21,10 @@
         return null;
     }
 
+    @NonNull public abstract CardType type();
+
     public String getHideKey() {
-        return Long.toString(FeedAdapter.getCardType(this) + 
dismissHashCode());
+        return Long.toString(type().code() + dismissHashCode());
     }
 
     protected int dismissHashCode() {
diff --git a/app/src/main/java/org/wikipedia/feed/model/CardType.java 
b/app/src/main/java/org/wikipedia/feed/model/CardType.java
new file mode 100644
index 0000000..b8a463a
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/feed/model/CardType.java
@@ -0,0 +1,94 @@
+package org.wikipedia.feed.model;
+
+import android.content.Context;
+import android.support.annotation.NonNull;
+import android.view.View;
+
+import org.wikipedia.feed.becauseyouread.BecauseYouReadCardView;
+import org.wikipedia.feed.continuereading.ContinueReadingCardView;
+import org.wikipedia.feed.featured.FeaturedArticleCardView;
+import org.wikipedia.feed.image.FeaturedImageCardView;
+import org.wikipedia.feed.mainpage.MainPageCardView;
+import org.wikipedia.feed.mostread.MostReadCardView;
+import org.wikipedia.feed.news.NewsListCardView;
+import org.wikipedia.feed.progress.ProgressCardView;
+import org.wikipedia.feed.random.RandomCardView;
+import org.wikipedia.feed.searchbar.SearchCardView;
+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) {
+            return new SearchCardView(ctx);
+        }
+    },
+    CONTINUE_READING(1) {
+        @NonNull @Override public View newView(@NonNull Context ctx) {
+            return new ContinueReadingCardView(ctx);
+        }
+    },
+    BECAUSE_YOU_READ_LIST(2) {
+        @NonNull @Override public View newView(@NonNull Context ctx) {
+            return new BecauseYouReadCardView(ctx);
+        }
+    },
+    MOST_READ_LIST(3) {
+        @NonNull @Override public View newView(@NonNull Context ctx) {
+            return new MostReadCardView(ctx);
+        }
+    },
+    FEATURED_ARTICLE(4) {
+        @NonNull @Override public View newView(@NonNull Context ctx) {
+            return new FeaturedArticleCardView(ctx);
+        }
+    },
+    RANDOM(5) {
+        @NonNull @Override public View newView(@NonNull Context ctx) {
+            return new RandomCardView(ctx);
+        }
+    },
+    MAIN_PAGE(6) {
+        @NonNull @Override public View newView(@NonNull Context ctx) {
+            return new MainPageCardView(ctx);
+        }
+    },
+    NEWS_LIST(7) {
+        @NonNull @Override public View newView(@NonNull Context ctx) {
+            return new NewsListCardView(ctx);
+        }
+    },
+    FEATURED_IMAGE(8) {
+        @NonNull @Override public View newView(@NonNull Context ctx) {
+            return new FeaturedImageCardView(ctx);
+        }
+    },
+    BECAUSE_YOU_READ_ITEM(9),
+    MOST_READ_ITEM(10),
+    NEWS_ITEM(11),
+    NEWS_ITEM_LINK(12),
+    PROGRESS(99) {
+        @NonNull @Override public View newView(@NonNull Context ctx) {
+            return new ProgressCardView(ctx);
+        }
+    };
+
+    private static final EnumCodeMap<CardType> MAP = new 
EnumCodeMap<>(CardType.class);
+    private final int code;
+
+    @NonNull public static CardType of(int code) {
+        return MAP.get(code);
+    }
+
+    @NonNull public View newView(@NonNull Context ctx) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override public int code() {
+        return code;
+    }
+
+    CardType(int code) {
+        this.code = code;
+    }
+}
\ No newline at end of file
diff --git 
a/app/src/main/java/org/wikipedia/feed/mostread/MostReadItemCard.java 
b/app/src/main/java/org/wikipedia/feed/mostread/MostReadItemCard.java
index 096d9ca..0dfadf7 100644
--- a/app/src/main/java/org/wikipedia/feed/mostread/MostReadItemCard.java
+++ b/app/src/main/java/org/wikipedia/feed/mostread/MostReadItemCard.java
@@ -7,6 +7,7 @@
 
 import org.wikipedia.Site;
 import org.wikipedia.feed.model.Card;
+import org.wikipedia.feed.model.CardType;
 import org.wikipedia.page.PageTitle;
 
 public class MostReadItemCard extends Card {
@@ -30,6 +31,10 @@
         return article.thumbnail();
     }
 
+    @NonNull @Override public CardType type() {
+        return CardType.MOST_READ_ITEM;
+    }
+
     @NonNull public PageTitle pageTitle() {
         PageTitle title = new PageTitle(article.title(), site);
         if (article.thumbnail() != null) {
diff --git 
a/app/src/main/java/org/wikipedia/feed/mostread/MostReadListCard.java 
b/app/src/main/java/org/wikipedia/feed/mostread/MostReadListCard.java
index a2143db..4ddedf7 100644
--- a/app/src/main/java/org/wikipedia/feed/mostread/MostReadListCard.java
+++ b/app/src/main/java/org/wikipedia/feed/mostread/MostReadListCard.java
@@ -8,6 +8,7 @@
 import org.wikipedia.R;
 import org.wikipedia.Site;
 import org.wikipedia.WikipediaApp;
+import org.wikipedia.feed.model.CardType;
 import org.wikipedia.feed.model.ListCard;
 import org.wikipedia.util.DateUtil;
 
@@ -33,6 +34,10 @@
         return DateUtil.getFeedCardDateString(articles.date());
     }
 
+    @NonNull @Override public CardType type() {
+        return CardType.MOST_READ_LIST;
+    }
+
     @NonNull private static List<MostReadItemCard> toItems(@NonNull 
List<MostReadArticle> articles,
                                                            @NonNull Site site) 
{
         List<MostReadItemCard> cards = new ArrayList<>();
diff --git a/app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java 
b/app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java
index 9f29c0d..9f15740 100644
--- a/app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java
+++ b/app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java
@@ -11,6 +11,7 @@
 import org.wikipedia.Site;
 import org.wikipedia.feed.model.Card;
 import org.wikipedia.feed.model.CardPageItem;
+import org.wikipedia.feed.model.CardType;
 import org.wikipedia.richtext.RichTextUtil;
 import org.wikipedia.util.log.L;
 
@@ -41,6 +42,10 @@
         return newsItem.thumb();
     }
 
+    @NonNull @Override public CardType type() {
+        return CardType.NEWS_ITEM;
+    }
+
     @NonNull
     public CharSequence text() {
         return removeImageCaption(Html.fromHtml(newsItem.story()));
diff --git a/app/src/main/java/org/wikipedia/feed/news/NewsListCard.java 
b/app/src/main/java/org/wikipedia/feed/news/NewsListCard.java
index 267c9bc..1f174ae 100644
--- a/app/src/main/java/org/wikipedia/feed/news/NewsListCard.java
+++ b/app/src/main/java/org/wikipedia/feed/news/NewsListCard.java
@@ -3,6 +3,7 @@
 import android.support.annotation.NonNull;
 
 import org.wikipedia.Site;
+import org.wikipedia.feed.model.CardType;
 import org.wikipedia.feed.model.UtcDate;
 import org.wikipedia.feed.model.ListCard;
 
@@ -24,6 +25,10 @@
         return "";
     }
 
+    @NonNull @Override public CardType type() {
+        return CardType.NEWS_LIST;
+    }
+
     @NonNull
     public UtcDate age() {
         return age;
diff --git a/app/src/main/java/org/wikipedia/feed/progress/ProgressCard.java 
b/app/src/main/java/org/wikipedia/feed/progress/ProgressCard.java
index 1bdf797..3057b9d 100644
--- a/app/src/main/java/org/wikipedia/feed/progress/ProgressCard.java
+++ b/app/src/main/java/org/wikipedia/feed/progress/ProgressCard.java
@@ -3,10 +3,15 @@
 import android.support.annotation.NonNull;
 
 import org.wikipedia.feed.model.Card;
+import org.wikipedia.feed.model.CardType;
 
 public class ProgressCard extends Card {
     @Override @NonNull
     public String title() {
         return "";
     }
+
+    @NonNull @Override public CardType type() {
+        return CardType.PROGRESS;
+    }
 }
\ No newline at end of file
diff --git a/app/src/main/java/org/wikipedia/feed/random/RandomCard.java 
b/app/src/main/java/org/wikipedia/feed/random/RandomCard.java
index 7f1a8e3..9a8dd20 100644
--- a/app/src/main/java/org/wikipedia/feed/random/RandomCard.java
+++ b/app/src/main/java/org/wikipedia/feed/random/RandomCard.java
@@ -4,6 +4,7 @@
 
 import org.wikipedia.Site;
 import org.wikipedia.feed.model.Card;
+import org.wikipedia.feed.model.CardType;
 
 public class RandomCard extends Card {
     @NonNull private Site site;
@@ -18,6 +19,10 @@
         return "";
     }
 
+    @NonNull @Override public CardType type() {
+        return CardType.RANDOM;
+    }
+
     public Site site() {
         return site;
     }
diff --git a/app/src/main/java/org/wikipedia/feed/searchbar/SearchCard.java 
b/app/src/main/java/org/wikipedia/feed/searchbar/SearchCard.java
index 96aecba..402877a 100644
--- a/app/src/main/java/org/wikipedia/feed/searchbar/SearchCard.java
+++ b/app/src/main/java/org/wikipedia/feed/searchbar/SearchCard.java
@@ -3,10 +3,15 @@
 import android.support.annotation.NonNull;
 
 import org.wikipedia.feed.model.Card;
+import org.wikipedia.feed.model.CardType;
 
 public class SearchCard extends Card {
     @Override @NonNull
     public String title() {
         return "";
     }
+
+    @NonNull @Override public CardType type() {
+        return CardType.SEARCH_BAR;
+    }
 }
\ 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 862e9b7..2a251cd 100644
--- a/app/src/main/java/org/wikipedia/feed/view/FeedAdapter.java
+++ b/app/src/main/java/org/wikipedia/feed/view/FeedAdapter.java
@@ -13,17 +13,16 @@
 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.image.FeaturedImageCard;
-import org.wikipedia.feed.image.FeaturedImageCardView;
-import org.wikipedia.feed.progress.ProgressCard;
-import org.wikipedia.feed.progress.ProgressCardView;
 import org.wikipedia.feed.random.RandomCard;
 import org.wikipedia.feed.random.RandomCardView;
 import org.wikipedia.feed.searchbar.SearchCard;
@@ -32,45 +31,8 @@
 import org.wikipedia.views.DefaultViewHolder;
 
 public class FeedAdapter extends DefaultRecyclerAdapter<Card, View> {
-    private static final int VIEW_TYPE_SEARCH_BAR = 0;
-    private static final int VIEW_TYPE_CONTINUE_READING = 1;
-    private static final int VIEW_TYPE_BECAUSE_YOU_READ = 2;
-    private static final int VIEW_TYPE_MOST_READ = 3;
-    private static final int VIEW_TYPE_FEATURED_ARTICLE = 4;
-    private static final int VIEW_TYPE_RANDOM = 5;
-    private static final int VIEW_TYPE_MAIN_PAGE = 6;
-    private static final int VIEW_TYPE_NEWS = 7;
-    private static final int VIEW_TYPE_FEATURED_IMAGE = 8;
-    private static final int VIEW_TYPE_PROGRESS = 99;
-
     @NonNull private FeedCoordinatorBase coordinator;
     @Nullable private FeedViewCallback callback;
-
-    public static int getCardType(Card card) {
-        if (card instanceof ProgressCard) {
-            return VIEW_TYPE_PROGRESS;
-        } else if (card instanceof ContinueReadingCard) {
-            return VIEW_TYPE_CONTINUE_READING;
-        } else if (card instanceof BecauseYouReadCard) {
-            return VIEW_TYPE_BECAUSE_YOU_READ;
-        } else if (card instanceof SearchCard) {
-            return VIEW_TYPE_SEARCH_BAR;
-        } else if (card instanceof MostReadListCard) {
-            return VIEW_TYPE_MOST_READ;
-        } else if (card instanceof FeaturedArticleCard) {
-            return VIEW_TYPE_FEATURED_ARTICLE;
-        } else if (card instanceof RandomCard) {
-            return VIEW_TYPE_RANDOM;
-        } else if (card instanceof NewsListCard) {
-            return VIEW_TYPE_NEWS;
-        } else if (card instanceof MainPageCard) {
-            return VIEW_TYPE_MAIN_PAGE;
-        } else if (card instanceof FeaturedImageCard) {
-            return VIEW_TYPE_FEATURED_IMAGE;
-        } else {
-            throw new IllegalStateException("Unknown type=" + card.getClass());
-        }
-    }
 
     public FeedAdapter(@NonNull FeedCoordinatorBase coordinator, @Nullable 
FeedViewCallback callback) {
         super(coordinator.getCards());
@@ -120,34 +82,19 @@
     }
 
     @Override public int getItemViewType(int position) {
-        return getCardType(item(position));
+        return item(position).type().code();
     }
 
     @NonNull private View newView(@NonNull Context context, int viewType) {
-        switch(viewType) {
-            case VIEW_TYPE_PROGRESS:
-                return new ProgressCardView(context);
-            case VIEW_TYPE_CONTINUE_READING:
-                return new 
ContinueReadingCardView(context).setCallback(callback);
-            case VIEW_TYPE_BECAUSE_YOU_READ:
-                return new 
BecauseYouReadCardView(context).setCallback(callback);
-            case VIEW_TYPE_SEARCH_BAR:
-                return new SearchCardView(context).setCallback(callback);
-            case VIEW_TYPE_MOST_READ:
-                return new MostReadCardView(context).setCallback(callback);
-            case VIEW_TYPE_FEATURED_ARTICLE:
-                return new 
FeaturedArticleCardView(context).setCallback(callback);
-            case VIEW_TYPE_RANDOM:
-                return new RandomCardView(context).setCallback(callback);
-            case VIEW_TYPE_NEWS:
-                return new NewsListCardView(context).setCallback(callback);
-            case VIEW_TYPE_MAIN_PAGE:
-                return new MainPageCardView(context).setCallback(callback);
-            case VIEW_TYPE_FEATURED_IMAGE:
-                return new 
FeaturedImageCardView(context).setCallback(callback);
-            default:
-                throw new IllegalArgumentException("viewType=" + 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;
     }
 
     private boolean isCardAssociatedWithView(@NonNull View view, @NonNull Card 
card) {
diff --git a/app/src/main/java/org/wikipedia/news/NewsLinkCard.java 
b/app/src/main/java/org/wikipedia/news/NewsLinkCard.java
index cea913a..bca9c53 100644
--- a/app/src/main/java/org/wikipedia/news/NewsLinkCard.java
+++ b/app/src/main/java/org/wikipedia/news/NewsLinkCard.java
@@ -9,6 +9,7 @@
 import org.wikipedia.Site;
 import org.wikipedia.feed.model.Card;
 import org.wikipedia.feed.model.CardPageItem;
+import org.wikipedia.feed.model.CardType;
 import org.wikipedia.page.PageTitle;
 
 import static org.wikipedia.util.ImageUrlUtil.getUrlForSize;
@@ -35,6 +36,10 @@
         return image != null ? getUrlForSize(image, 
Constants.PREFERRED_THUMB_SIZE) : null;
     }
 
+    @NonNull @Override public CardType type() {
+        return CardType.NEWS_ITEM_LINK;
+    }
+
     @NonNull public PageTitle pageTitle() {
         PageTitle title = new PageTitle(page.title(), site);
         if (page.thumbnail() != null) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e9480a8c5cd11485f068719bff689e6abb03366
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