jenkins-bot has submitted this change and it was merged.

Change subject: Add interactivity to "because you read" card.
......................................................................


Add interactivity to "because you read" card.

- Added some more methods to the Callback provided by FeedFragment, so
  that when PageActivity overrides them, the desired behavior is achieved.
- Wove a callback mechanism into the View hierarchy of feed cards.
- Created PageTitleListCardView (a descendant of ListCardView) that takes
  a PageTitle as a data provider. This is inescapable, since the original
  PageTitle (including its language code, namespace, etc) needs to be
  preserved in order to navigate to the correct page upon clicking.
- Updated the fragment backstack logic and back-behavior in MainActivity.

Change-Id: I0663b26dd247f65a28655213b73e08e07078426b
---
M app/src/main/AndroidManifest.xml
M app/src/main/java/org/wikipedia/MainActivity.java
A app/src/main/java/org/wikipedia/MainActivityToolbarCoordinator.java
A app/src/main/java/org/wikipedia/MainActivityToolbarProvider.java
D app/src/main/java/org/wikipedia/feed/FeedActivity.java
M app/src/main/java/org/wikipedia/feed/FeedFragment.java
A app/src/main/java/org/wikipedia/feed/FeedViewCallback.java
M 
app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadCardView.java
M app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadClient.java
M 
app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadItemCard.java
M app/src/main/java/org/wikipedia/feed/view/FeedRecyclerAdapter.java
M app/src/main/java/org/wikipedia/feed/view/FeedView.java
M app/src/main/java/org/wikipedia/feed/view/ListCardItemView.java
M app/src/main/java/org/wikipedia/feed/view/ListCardView.java
A app/src/main/java/org/wikipedia/feed/view/PageTitleListCardItemView.java
A app/src/main/java/org/wikipedia/feed/view/PageTitleListCardView.java
M app/src/main/java/org/wikipedia/history/HistoryEntry.java
M app/src/main/java/org/wikipedia/history/HistoryFragment.java
M app/src/main/java/org/wikipedia/page/MwApiResultPage.java
M app/src/main/java/org/wikipedia/page/NavDrawerHelper.java
M app/src/main/java/org/wikipedia/page/PageFragment.java
M app/src/main/java/org/wikipedia/readinglist/AddToReadingListDialog.java
M app/src/main/java/org/wikipedia/readinglist/ReadingListsFragment.java
A app/src/main/res/drawable/ic_menu_white_24dp.xml
M app/src/main/res/layout/view_list_card_item.xml
25 files changed, 392 insertions(+), 154 deletions(-)

Approvals:
  BearND: Looks good to me, approved
  Mholloway: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 59f36f6..fb74ae3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -54,11 +54,6 @@
         <meta-data android:name="net.hockeyapp.android.appIdentifier"
             android:value="@string/hockeyapp_app_id" />
 
-        <activity android:name=".feed.FeedActivity"
-                  android:theme="@style/FeedTheme"
-                  android:label="@string/activity_feed_title"
-                  
android:configChanges="orientation|keyboardHidden|keyboard|screenSize" />
-
         <activity android:name=".MainActivity"
                   android:theme="@style/PageTheme"
                   android:windowSoftInputMode="stateHidden"
diff --git a/app/src/main/java/org/wikipedia/MainActivity.java 
b/app/src/main/java/org/wikipedia/MainActivity.java
index b05da0f..54ec68a 100644
--- a/app/src/main/java/org/wikipedia/MainActivity.java
+++ b/app/src/main/java/org/wikipedia/MainActivity.java
@@ -54,7 +54,7 @@
 import org.wikipedia.events.ChangeTextSizeEvent;
 import org.wikipedia.events.ThemeChangeEvent;
 import org.wikipedia.events.WikipediaZeroStateChangeEvent;
-import org.wikipedia.feed.FeedActivity;
+import org.wikipedia.feed.FeedFragment;
 import org.wikipedia.history.HistoryEntry;
 import org.wikipedia.interlanguage.LangLinksActivity;
 import org.wikipedia.login.LoginActivity;
@@ -91,7 +91,7 @@
 import static org.wikipedia.util.DeviceUtil.isBackKeyUp;
 import static org.wikipedia.util.UriUtil.visitInExternalBrowser;
 
-public class MainActivity extends ThemedActionBarActivity {
+public class MainActivity extends ThemedActionBarActivity implements 
FeedFragment.Callback {
 
     public enum TabPosition {
         CURRENT_TAB,
@@ -135,6 +135,7 @@
     private boolean navItemSelected;
     private WikipediaZeroUsageFunnel zeroFunnel;
     private ExclusiveBottomSheetPresenter bottomSheetPresenter = new 
ExclusiveBottomSheetPresenter(this);
+    private MainActivityToolbarCoordinator toolbarCoordinator;
 
     public View getContentView() {
         return fragmentContainerView;
@@ -209,10 +210,15 @@
         PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
         setContentView(R.layout.activity_page);
 
-        setSupportActionBar((Toolbar) findViewById(R.id.main_toolbar));
-        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
-
+        toolbarCoordinator = new MainActivityToolbarCoordinator(this, 
(Toolbar) findViewById(R.id.main_toolbar));
         toolbarContainer = findViewById(R.id.main_toolbar_container);
+        getSupportFragmentManager()
+                .addOnBackStackChangedListener(new 
FragmentManager.OnBackStackChangedListener() {
+                    @Override
+                    public void onBackStackChanged() {
+                        updateToolbarForFragment();
+                    }
+                });
 
         busMethods = new EventBusMethods();
         registerBus();
@@ -454,15 +460,10 @@
         } else if (intent.hasExtra(EXTRA_FEATURED_ARTICLE_FROM_WIDGET)) {
             new IntentFunnel(app).logFeaturedArticleWidgetTap();
             loadMainPageInForegroundTab();
-        } else if (Prefs.enableFeed() && 
TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - 
Prefs.pageLastShown()) > 0) {
-            launchFeedActivity();
-
-            // Uncommenting the following line gives the desired back button 
behavior but there's
-            // currently no way to open a page from the Feed. todo: uncomment 
once the Feed is
-            // interactive.
-            // finish();
-        } else {
+        } else if (!Prefs.enableFeed() || 
TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - 
Prefs.pageLastShown()) == 0) {
             loadMainPageIfNoTabs();
+        } else {
+            showFeed();
         }
     }
 
@@ -524,8 +525,21 @@
         drawerLayout.closeDrawer(GravityCompat.START);
     }
 
-    private void removeAllFragments() {
-        getSupportFragmentManager().popBackStackImmediate(null, 
FragmentManager.POP_BACK_STACK_INCLUSIVE);
+    public void showFeed() {
+        // pop fragments until we see a FeedFragment. If there's no 
FeedFragment, then add it.
+        while (getSupportFragmentManager().getBackStackEntryCount() > 0
+                && !(getTopFragment() instanceof FeedFragment)) {
+            getSupportFragmentManager().popBackStackImmediate();
+        }
+        pushFragment(new FeedFragment());
+    }
+
+    private void resetFragmentsToFeedOrPage() {
+        while (getSupportFragmentManager().getBackStackEntryCount() > 0
+                && !(getTopFragment() instanceof FeedFragment)
+                && !(getTopFragment() instanceof PageFragment)) {
+            getSupportFragmentManager().popBackStackImmediate();
+        }
     }
 
     /**
@@ -543,9 +557,7 @@
      * @param allowStateLoss Whether to allow state loss.
      */
     public void pushFragment(Fragment f, boolean allowStateLoss) {
-        closeNavDrawer();
-        searchBarHideHandler.setForceNoFade(false);
-        searchBarHideHandler.setFadeEnabled(false);
+        beforeFragmentChanged();
         // if the new fragment is the same class as the current topmost 
fragment,
         // then just keep the previous fragment there.
         // e.g. if the user selected History, and there's already a History 
fragment on top,
@@ -554,7 +566,7 @@
             return;
         }
 
-        removeAllFragments();
+        resetFragmentsToFeedOrPage();
         FragmentTransaction trans = 
getSupportFragmentManager().beginTransaction();
         trans.add(R.id.content_fragment_container, f);
         trans.addToBackStack(null);
@@ -563,17 +575,33 @@
         } else {
             trans.commit();
         }
+        afterFragmentChanged();
+    }
 
-        // and make sure the ActionBar is visible
+    public void resetAfterClearHistory() {
+        Prefs.clearTabs();
+        showFeed();
+    }
+
+    private void beforeFragmentChanged() {
+        closeNavDrawer();
+        searchBarHideHandler.setForceNoFade(false);
+        searchBarHideHandler.setFadeEnabled(false);
+    }
+
+    private void afterFragmentChanged() {
+        //make sure the ActionBar is visible
         showToolbar();
         //also make sure the progress bar is not showing
         updateProgressBar(false, true, 0);
     }
 
-    public void resetAfterClearHistory() {
-        removeAllFragments();
-        Prefs.clearTabs();
-        loadMainPageIfNoTabs();
+    private void updateToolbarForFragment() {
+        if (getTopFragment() instanceof MainActivityToolbarProvider) {
+            
toolbarCoordinator.setOverrideToolbar(((MainActivityToolbarProvider) 
getTopFragment()).getToolbar());
+        } else {
+            toolbarCoordinator.removeOverrideToolbar();
+        }
     }
 
     /**
@@ -770,11 +798,29 @@
         if (getTopFragment() instanceof BackPressedHandler
                 && ((BackPressedHandler) getTopFragment()).onBackPressed()) {
             return;
-        } else if (!(getTopFragment() instanceof PageFragment)) {
-            pushFragment(new PageFragment(), false);
+        }
+        if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
+            beforeFragmentChanged();
+            getSupportFragmentManager().popBackStackImmediate();
+            afterFragmentChanged();
             return;
         }
         finish();
+    }
+
+    @Override
+    public void onFeedSearchRequested() {
+        onSearchRequested();
+    }
+
+    @Override
+    public void onFeedSelectPage(PageTitle title) {
+        loadPage(title, new HistoryEntry(title, HistoryEntry.SOURCE_FEED));
+    }
+
+    @Override
+    public void onFeedAddPageToList(PageTitle title) {
+        showAddToListDialog(title, AddToReadingListDialog.InvokeSource.FEED);
     }
 
     private void loadMainPageIfNoTabs() {
@@ -1056,9 +1102,5 @@
                 new ComponentName(this, WidgetProviderFeaturedPage.class));
         widgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
         sendBroadcast(widgetIntent);
-    }
-
-    private void launchFeedActivity() {
-        startActivity(FeedActivity.newIntent(this));
     }
 }
\ No newline at end of file
diff --git 
a/app/src/main/java/org/wikipedia/MainActivityToolbarCoordinator.java 
b/app/src/main/java/org/wikipedia/MainActivityToolbarCoordinator.java
new file mode 100644
index 0000000..e549967
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/MainActivityToolbarCoordinator.java
@@ -0,0 +1,37 @@
+package org.wikipedia;
+
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.view.View;
+
+public class MainActivityToolbarCoordinator {
+    @NonNull private AppCompatActivity activity;
+    @NonNull private Toolbar defaultToolbar;
+    @Nullable private Toolbar overrideToolbar;
+
+    public MainActivityToolbarCoordinator(@NonNull AppCompatActivity activity, 
@NonNull Toolbar defaultToolbar) {
+        this.activity = activity;
+        this.defaultToolbar = defaultToolbar;
+        setActivityToolbar(defaultToolbar);
+    }
+
+    public void setOverrideToolbar(@NonNull Toolbar toolbar) {
+        overrideToolbar = toolbar;
+        defaultToolbar.setVisibility(View.GONE);
+        setActivityToolbar(overrideToolbar);
+    }
+
+    public void removeOverrideToolbar() {
+        overrideToolbar = null;
+        defaultToolbar.setVisibility(View.VISIBLE);
+        setActivityToolbar(defaultToolbar);
+    }
+
+    private void setActivityToolbar(Toolbar toolbar) {
+        activity.setSupportActionBar(toolbar);
+        activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+        
activity.getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
+    }
+}
diff --git a/app/src/main/java/org/wikipedia/MainActivityToolbarProvider.java 
b/app/src/main/java/org/wikipedia/MainActivityToolbarProvider.java
new file mode 100644
index 0000000..b7ca52a
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/MainActivityToolbarProvider.java
@@ -0,0 +1,7 @@
+package org.wikipedia;
+
+import android.support.v7.widget.Toolbar;
+
+public interface MainActivityToolbarProvider {
+    Toolbar getToolbar();
+}
diff --git a/app/src/main/java/org/wikipedia/feed/FeedActivity.java 
b/app/src/main/java/org/wikipedia/feed/FeedActivity.java
deleted file mode 100644
index d137b7d..0000000
--- a/app/src/main/java/org/wikipedia/feed/FeedActivity.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.wikipedia.feed;
-
-import android.content.Context;
-import android.content.Intent;
-import android.support.v7.widget.Toolbar;
-
-import org.wikipedia.activity.SingleFragmentActivity;
-
-public class FeedActivity extends SingleFragmentActivity<FeedFragment> 
implements FeedFragment.Callback {
-    public static Intent newIntent(Context context) {
-        return new Intent(context, FeedActivity.class);
-    }
-
-    @Override protected FeedFragment createFragment() {
-        return FeedFragment.newInstance();
-    }
-
-    @Override protected void setTheme() { }
-
-    @Override
-    public void onAddToolbar(Toolbar toolbar) {
-        setSupportActionBar(toolbar);
-        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
-    }
-
-    @Override
-    public void onRemoveToolbar(Toolbar toolbar) {
-        setSupportActionBar(null);
-    }
-}
\ No newline at end of file
diff --git a/app/src/main/java/org/wikipedia/feed/FeedFragment.java 
b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
index 00fe3c6..b610639 100644
--- a/app/src/main/java/org/wikipedia/feed/FeedFragment.java
+++ b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
@@ -1,6 +1,7 @@
 package org.wikipedia.feed;
 
 import android.os.Bundle;
+import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.design.widget.CollapsingToolbarLayout;
 import android.support.v4.app.Fragment;
@@ -12,6 +13,8 @@
 import android.view.View;
 import android.view.ViewGroup;
 
+import org.wikipedia.BackPressedHandler;
+import org.wikipedia.MainActivityToolbarProvider;
 import org.wikipedia.R;
 import org.wikipedia.WikipediaApp;
 import org.wikipedia.activity.CallbackFragment;
@@ -19,6 +22,7 @@
 import org.wikipedia.feed.model.Card;
 import org.wikipedia.feed.view.FeedView;
 import org.wikipedia.settings.Prefs;
+import org.wikipedia.page.PageTitle;
 
 import java.util.List;
 
@@ -26,17 +30,21 @@
 import butterknife.ButterKnife;
 import butterknife.Unbinder;
 
-public class FeedFragment extends Fragment implements 
CallbackFragment<CallbackFragment.Callback> {
+public class FeedFragment extends Fragment implements BackPressedHandler,
+        MainActivityToolbarProvider,
+        CallbackFragment<CallbackFragment.Callback> {
     @BindView(R.id.fragment_feed_feed) FeedView feedView;
     @BindView(R.id.feed_collapsing_toolbar_layout) CollapsingToolbarLayout 
collapsingToolbarLayout;
     @BindView(R.id.feed_toolbar) Toolbar toolbar;
     private Unbinder unbinder;
     private WikipediaApp app;
     private FeedCoordinator coordinator;
+    private FeedViewCallback feedCallback = new FeedCallback();
 
     public interface Callback extends CallbackFragment.Callback {
-        void onAddToolbar(Toolbar toolbar);
-        void onRemoveToolbar(Toolbar toolbar);
+        void onFeedSearchRequested();
+        void onFeedSelectPage(PageTitle title);
+        void onFeedAddPageToList(PageTitle title);
     }
 
     public static FeedFragment newInstance() {
@@ -58,11 +66,7 @@
         View view = inflater.inflate(R.layout.fragment_feed, container, false);
 
         unbinder = ButterKnife.bind(this, view);
-        feedView.set(coordinator.getCards());
-
-        if (getCallback() != null) {
-            getCallback().onAddToolbar(toolbar);
-        }
+        feedView.set(coordinator.getCards(), feedCallback);
 
         coordinator.setFeedUpdateListener(new 
FeedCoordinator.FeedUpdateListener() {
             @Override
@@ -84,16 +88,15 @@
         setHasOptionsMenu(true);
     }
 
-    @Override public void onDestroyView() {
-        if (getCallback() != null) {
-            getCallback().onRemoveToolbar(toolbar);
-        }
+    @Override
+    public void onDestroyView() {
         unbinder.unbind();
         super.onDestroyView();
     }
 
     @Override
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+        menu.clear();
         inflater.inflate(R.menu.menu_feed, menu);
     }
 
@@ -111,7 +114,33 @@
         }
     }
 
+    @Override
+    public boolean onBackPressed() {
+        return false;
+    }
+
+    @Override
+    public Toolbar getToolbar() {
+        return toolbar;
+    }
+
     @Override @Nullable public Callback getCallback() {
         return FragmentUtil.getCallback(this, Callback.class);
     }
+
+    private class FeedCallback implements FeedViewCallback {
+        @Override
+        public void onSelectPage(@NonNull PageTitle title) {
+            if (getCallback() != null) {
+                getCallback().onFeedSelectPage(title);
+            }
+        }
+
+        @Override
+        public void onAddPageToList(@NonNull PageTitle title) {
+            if (getCallback() != null) {
+                getCallback().onFeedAddPageToList(title);
+            }
+        }
+    }
 }
diff --git a/app/src/main/java/org/wikipedia/feed/FeedViewCallback.java 
b/app/src/main/java/org/wikipedia/feed/FeedViewCallback.java
new file mode 100644
index 0000000..7954be9
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/feed/FeedViewCallback.java
@@ -0,0 +1,10 @@
+package org.wikipedia.feed;
+
+import android.support.annotation.NonNull;
+
+import org.wikipedia.page.PageTitle;
+
+public interface FeedViewCallback {
+    void onSelectPage(@NonNull PageTitle title);
+    void onAddPageToList(@NonNull PageTitle title);
+}
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 145e529..c844c85 100644
--- 
a/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadCardView.java
+++ 
b/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadCardView.java
@@ -2,22 +2,31 @@
 
 import android.content.Context;
 import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 
+import org.wikipedia.feed.FeedViewCallback;
 import org.wikipedia.feed.view.CardLargeHeaderView;
-import org.wikipedia.feed.view.ListCardItemView;
-import org.wikipedia.feed.view.ListCardView;
+import org.wikipedia.feed.view.PageTitleListCardItemView;
+import org.wikipedia.feed.view.PageTitleListCardView;
 import org.wikipedia.views.DefaultViewHolder;
 
 import java.util.List;
 
-public class BecauseYouReadCardView extends ListCardView<BecauseYouReadCard> {
+public class BecauseYouReadCardView extends 
PageTitleListCardView<BecauseYouReadCard> {
+    @Nullable private FeedViewCallback callback;
+
     public BecauseYouReadCardView(Context context) {
         super(context);
     }
 
+    @NonNull public PageTitleListCardView setCallback(@Nullable 
FeedViewCallback callback) {
+        this.callback = callback;
+        return this;
+    }
+
     public void set(@NonNull final BecauseYouReadCard card) {
         header(card);
-        set(new RecyclerAdapter(card.items()));
+        set(new RecyclerAdapter(card.items(), callback));
     }
 
     private void header(@NonNull final BecauseYouReadCard card) {
@@ -29,16 +38,19 @@
         header(header);
     }
 
-    private static class RecyclerAdapter extends 
ListCardView.RecyclerAdapter<BecauseYouReadItemCard> {
-        RecyclerAdapter(@NonNull List<BecauseYouReadItemCard> items) {
+    private static class RecyclerAdapter extends 
PageTitleListCardView.RecyclerAdapter<BecauseYouReadItemCard> {
+        @Nullable private FeedViewCallback callback;
+
+        RecyclerAdapter(@NonNull List<BecauseYouReadItemCard> items, @Nullable 
FeedViewCallback callback) {
             super(items);
+            this.callback = callback;
         }
 
-        @Override public void 
onBindViewHolder(DefaultViewHolder<ListCardItemView> holder, int i) {
+        @Override
+        public void 
onBindViewHolder(DefaultViewHolder<PageTitleListCardItemView> holder, int i) {
             BecauseYouReadItemCard card = item(i);
-            holder.getView().setTitle(card.title());
-            holder.getView().setSubtitle(card.subtitle());
-            holder.getView().setImage(card.image());
+            holder.getView().setPageTitle(card.pageTitle());
+            holder.getView().setCallback(callback);
         }
     }
 }
\ No newline at end of file
diff --git 
a/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadClient.java 
b/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadClient.java
index fb811b7..cab772d 100644
--- 
a/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadClient.java
+++ 
b/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadClient.java
@@ -94,7 +94,7 @@
                     MwQueryResponse<Pages> pages = response.body();
                     if (pages.success() && pages.query() != null && 
pages.query().results(title.getSite()) != null) {
                         SearchResults results = 
SearchResults.filter(pages.query().results(title.getSite()), title.getText(), 
false);
-                        List<BecauseYouReadItemCard> itemCards = 
MwApiResultPage.searchResultsToCards(results);
+                        List<BecauseYouReadItemCard> itemCards = 
MwApiResultPage.searchResultsToCards(results, title.getSite());
 
                         cb.success(Collections.singletonList((Card) new 
BecauseYouReadCard(title, itemCards)));
                     } else {
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 0eb4218..dfe3580 100644
--- 
a/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadItemCard.java
+++ 
b/app/src/main/java/org/wikipedia/feed/becauseyouread/BecauseYouReadItemCard.java
@@ -3,33 +3,35 @@
 import android.net.Uri;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
+import android.text.TextUtils;
 
 import org.wikipedia.feed.model.Card;
+import org.wikipedia.page.PageTitle;
 
 public class BecauseYouReadItemCard extends Card {
-    @NonNull private final String title;
-    @Nullable private final String subtitle;
-    @Nullable private final Uri image;
+    @NonNull private final PageTitle title;
 
-    public BecauseYouReadItemCard(@NonNull String title, @Nullable String 
subtitle,
-                                  @Nullable String image) {
+    public BecauseYouReadItemCard(@NonNull PageTitle title) {
         this.title = title;
-        this.subtitle = subtitle;
-        this.image = image != null ? Uri.parse(image) : null;
+    }
+
+    @NonNull
+    public PageTitle pageTitle() {
+        return title;
     }
 
     @NonNull
     @Override public String title() {
-        return title;
+        return title.getDisplayText();
     }
 
     @Nullable
     @Override public String subtitle() {
-        return subtitle;
+        return title.getDescription();
     }
 
     @Nullable
     @Override public Uri image() {
-        return image;
+        return TextUtils.isEmpty(title.getThumbUrl()) ? null : 
Uri.parse(title.getThumbUrl());
     }
 }
diff --git a/app/src/main/java/org/wikipedia/feed/view/FeedRecyclerAdapter.java 
b/app/src/main/java/org/wikipedia/feed/view/FeedRecyclerAdapter.java
index 5e4962a..5faf189 100644
--- a/app/src/main/java/org/wikipedia/feed/view/FeedRecyclerAdapter.java
+++ b/app/src/main/java/org/wikipedia/feed/view/FeedRecyclerAdapter.java
@@ -2,9 +2,11 @@
 
 import android.content.Context;
 import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 import android.support.v7.widget.CardView;
 import android.view.ViewGroup;
 
+import org.wikipedia.feed.FeedViewCallback;
 import org.wikipedia.feed.becauseyouread.BecauseYouReadCard;
 import org.wikipedia.feed.becauseyouread.BecauseYouReadCardView;
 import org.wikipedia.feed.continuereading.ContinueReadingCard;
@@ -28,8 +30,11 @@
     private static final int VIEW_TYPE_MOST_READ = 3;
     private static final int VIEW_TYPE_INTEGER_LIST = 100;
 
-    public FeedRecyclerAdapter(@NonNull List<Card> items) {
+    @Nullable private FeedViewCallback callback;
+
+    public FeedRecyclerAdapter(@NonNull List<Card> items, @Nullable 
FeedViewCallback callback) {
         super(items);
+        this.callback = callback;
     }
 
     @Override public DefaultViewHolder<CardView> onCreateViewHolder(ViewGroup 
parent, int viewType) {
@@ -79,7 +84,7 @@
             case VIEW_TYPE_CONTINUE_READING:
                 return new ContinueReadingCardView(context);
             case VIEW_TYPE_BECAUSE_YOU_READ:
-                return new BecauseYouReadCardView(context);
+                return new 
BecauseYouReadCardView(context).setCallback(callback);
             case VIEW_TYPE_SEARCH_BAR:
                 return new SearchCardView(context);
             case VIEW_TYPE_MOST_READ:
diff --git a/app/src/main/java/org/wikipedia/feed/view/FeedView.java 
b/app/src/main/java/org/wikipedia/feed/view/FeedView.java
index d2ed57d..27b0af1 100644
--- a/app/src/main/java/org/wikipedia/feed/view/FeedView.java
+++ b/app/src/main/java/org/wikipedia/feed/view/FeedView.java
@@ -6,6 +6,7 @@
 import android.util.AttributeSet;
 
 import org.wikipedia.R;
+import org.wikipedia.feed.FeedViewCallback;
 import org.wikipedia.feed.model.Card;
 import org.wikipedia.views.AutoFitRecyclerView;
 import org.wikipedia.views.MarginItemDecoration;
@@ -32,10 +33,10 @@
         init();
     }
 
-    public void set(@NonNull List<Card> cards) {
+    public void set(@NonNull List<Card> cards, FeedViewCallback callback) {
         // TODO: should this class be responsible for showing a "no items in 
collection" view? It
         //       would be nice to show placeholder elements while it loads.
-        recyclerAdapter = new FeedRecyclerAdapter(cards);
+        recyclerAdapter = new FeedRecyclerAdapter(cards, callback);
         setAdapter(recyclerAdapter);
     }
 
@@ -53,7 +54,7 @@
                 R.dimen.view_list_card_margin_horizontal, 
R.dimen.view_list_card_margin_vertical,
                 R.dimen.view_list_card_margin_horizontal, 
R.dimen.view_list_card_margin_vertical));
         callback(new RecyclerViewColumnCallback());
-        set(Collections.<Card>emptyList());
+        set(Collections.<Card>emptyList(), null);
     }
 
     private class RecyclerViewColumnCallback implements 
AutoFitRecyclerView.Callback {
diff --git a/app/src/main/java/org/wikipedia/feed/view/ListCardItemView.java 
b/app/src/main/java/org/wikipedia/feed/view/ListCardItemView.java
index 1154b48..6fc7a59 100644
--- a/app/src/main/java/org/wikipedia/feed/view/ListCardItemView.java
+++ b/app/src/main/java/org/wikipedia/feed/view/ListCardItemView.java
@@ -23,6 +23,7 @@
         super(context);
 
         inflate(getContext(), R.layout.view_list_card_item, this);
+        setClickable(true);
         ButterKnife.bind(this);
     }
 
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 64d75f7..fa6cfd2 100644
--- a/app/src/main/java/org/wikipedia/feed/view/ListCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/view/ListCardView.java
@@ -14,7 +14,6 @@
 import org.wikipedia.views.DefaultRecyclerAdapter;
 import org.wikipedia.views.DefaultViewHolder;
 import org.wikipedia.views.DrawableItemDecoration;
-import org.wikipedia.views.MarginItemDecoration;
 import org.wikipedia.views.ViewUtil;
 
 import java.util.List;
@@ -58,8 +57,6 @@
 
     private void initRecycler() {
         recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
-        recyclerView.addItemDecoration(new MarginItemDecoration(getContext(),
-                R.dimen.view_list_card_item_margin));
         recyclerView.addItemDecoration(new DrawableItemDecoration(getContext(),
                 R.drawable.divider, true));
         recyclerView.setNestedScrollingEnabled(false);
diff --git 
a/app/src/main/java/org/wikipedia/feed/view/PageTitleListCardItemView.java 
b/app/src/main/java/org/wikipedia/feed/view/PageTitleListCardItemView.java
new file mode 100644
index 0000000..ff1e36f
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/feed/view/PageTitleListCardItemView.java
@@ -0,0 +1,41 @@
+package org.wikipedia.feed.view;
+
+import android.content.Context;
+import android.net.Uri;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.text.TextUtils;
+import android.view.View;
+
+import org.wikipedia.feed.FeedViewCallback;
+import org.wikipedia.page.PageTitle;
+
+public class PageTitleListCardItemView extends ListCardItemView {
+    @Nullable private FeedViewCallback callback;
+    @Nullable private PageTitle title;
+
+    public PageTitleListCardItemView(Context context) {
+        super(context);
+        setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                if (callback != null && title != null) {
+                    callback.onSelectPage(title);
+                }
+            }
+        });
+    }
+
+    @NonNull public PageTitleListCardItemView setCallback(@Nullable 
FeedViewCallback callback) {
+        this.callback = callback;
+        return this;
+    }
+
+    @NonNull public PageTitleListCardItemView setPageTitle(@NonNull PageTitle 
title) {
+        this.title = title;
+        titleView.setText(title.getDisplayText());
+        subtitleView.setText(title.getDescription());
+        imageView.setImageURI(TextUtils.isEmpty(title.getThumbUrl()) ? null : 
Uri.parse(title.getThumbUrl()));
+        return this;
+    }
+}
\ No newline at end of file
diff --git 
a/app/src/main/java/org/wikipedia/feed/view/PageTitleListCardView.java 
b/app/src/main/java/org/wikipedia/feed/view/PageTitleListCardView.java
new file mode 100644
index 0000000..c723afd
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/feed/view/PageTitleListCardView.java
@@ -0,0 +1,75 @@
+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 android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+import android.view.ViewGroup;
+
+import org.wikipedia.R;
+import org.wikipedia.feed.model.Card;
+import org.wikipedia.views.DefaultRecyclerAdapter;
+import org.wikipedia.views.DefaultViewHolder;
+import org.wikipedia.views.DrawableItemDecoration;
+import org.wikipedia.views.ViewUtil;
+
+import java.util.List;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+
+public abstract class PageTitleListCardView<T extends Card> extends CardView {
+    @BindView(R.id.view_list_card_header) View headerView;
+    @BindView(R.id.view_list_card_footer) View footerView;
+    @BindView(R.id.view_list_card_list) RecyclerView recyclerView;
+
+    public PageTitleListCardView(Context context) {
+        super(context);
+
+        inflate(getContext(), R.layout.view_list_card, this);
+        ButterKnife.bind(this);
+        initRecycler();
+    }
+
+    protected void set(@Nullable RecyclerAdapter<?> adapter) {
+        recyclerView.setAdapter(adapter);
+    }
+
+    protected void update() {
+        if (recyclerView.getAdapter() != null) {
+            recyclerView.getAdapter().notifyDataSetChanged();
+        }
+    }
+
+    protected void header(@NonNull View view) {
+        ViewUtil.replace(headerView, view);
+        headerView = view;
+    }
+
+    protected void footer(@NonNull View view) {
+        ViewUtil.replace(footerView, view);
+        footerView = view;
+    }
+
+    private void initRecycler() {
+        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
+        recyclerView.addItemDecoration(new DrawableItemDecoration(getContext(),
+                R.drawable.divider, true));
+        recyclerView.setNestedScrollingEnabled(false);
+    }
+
+    protected abstract static class RecyclerAdapter<T>
+            extends DefaultRecyclerAdapter<T, PageTitleListCardItemView> {
+        protected RecyclerAdapter(@NonNull List<T> items) {
+            super(items);
+        }
+
+        @Override public DefaultViewHolder<PageTitleListCardItemView> 
onCreateViewHolder(ViewGroup parent,
+                                                                               
 int viewType) {
+            return new DefaultViewHolder<>(new 
PageTitleListCardItemView(parent.getContext()));
+        }
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/wikipedia/history/HistoryEntry.java 
b/app/src/main/java/org/wikipedia/history/HistoryEntry.java
index 9ba7313..eb78b29 100644
--- a/app/src/main/java/org/wikipedia/history/HistoryEntry.java
+++ b/app/src/main/java/org/wikipedia/history/HistoryEntry.java
@@ -20,6 +20,7 @@
     public static final int SOURCE_NEARBY = 9;
     public static final int SOURCE_DISAMBIG = 10;
     public static final int SOURCE_READING_LIST = 11;
+    public static final int SOURCE_FEED = 12;
 
     private final PageTitle title;
     private final Date timestamp;
diff --git a/app/src/main/java/org/wikipedia/history/HistoryFragment.java 
b/app/src/main/java/org/wikipedia/history/HistoryFragment.java
index 13b2c9f..1213d08 100644
--- a/app/src/main/java/org/wikipedia/history/HistoryFragment.java
+++ b/app/src/main/java/org/wikipedia/history/HistoryFragment.java
@@ -168,6 +168,7 @@
         if (!isMenuToBeSetUp()) {
             return;
         }
+        menu.clear();
         inflater.inflate(R.menu.menu_history, menu);
     }
 
diff --git a/app/src/main/java/org/wikipedia/page/MwApiResultPage.java 
b/app/src/main/java/org/wikipedia/page/MwApiResultPage.java
index a16e557..6ff3f5e 100644
--- a/app/src/main/java/org/wikipedia/page/MwApiResultPage.java
+++ b/app/src/main/java/org/wikipedia/page/MwApiResultPage.java
@@ -7,7 +7,6 @@
 import org.wikipedia.feed.becauseyouread.BecauseYouReadItemCard;
 import org.wikipedia.search.SearchResult;
 import org.wikipedia.search.SearchResults;
-import org.wikipedia.util.StringUtil;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -46,19 +45,20 @@
         this.terms = new Terms(description);
     }
 
-    public static List<BecauseYouReadItemCard> 
searchResultsToCards(SearchResults results) {
+    public static List<BecauseYouReadItemCard> 
searchResultsToCards(SearchResults results, Site site) {
         List<BecauseYouReadItemCard> cards = new ArrayList<>();
         for (SearchResult result : results.getResults()) {
-            cards.add(result.toCard());
+            cards.add(result.toCard(site));
         }
         return cards;
     }
 
     @NonNull
-    public BecauseYouReadItemCard toCard() {
-        return new BecauseYouReadItemCard(StringUtil.removeUnderscores(title),
-                                          description(),
-                                          thumbUrl());
+    public BecauseYouReadItemCard toCard(Site site) {
+        PageTitle pageTitle = new PageTitle(title, site);
+        pageTitle.setThumbUrl(thumbUrl());
+        pageTitle.setDescription(description());
+        return new BecauseYouReadItemCard(pageTitle);
     }
 
     @NonNull
diff --git a/app/src/main/java/org/wikipedia/page/NavDrawerHelper.java 
b/app/src/main/java/org/wikipedia/page/NavDrawerHelper.java
index a493daa..cb7df94 100644
--- a/app/src/main/java/org/wikipedia/page/NavDrawerHelper.java
+++ b/app/src/main/java/org/wikipedia/page/NavDrawerHelper.java
@@ -19,7 +19,6 @@
 import org.wikipedia.MainActivity;
 import org.wikipedia.analytics.LoginFunnel;
 import org.wikipedia.analytics.NavMenuFunnel;
-import org.wikipedia.feed.FeedActivity;
 import org.wikipedia.feed.FeedFragment;
 import org.wikipedia.history.HistoryEntry;
 import org.wikipedia.history.HistoryFragment;
@@ -79,7 +78,7 @@
             public boolean onNavigationItemSelected(MenuItem menuItem) {
                 switch (menuItem.getItemId()) {
                     case R.id.nav_item_feed:
-                        launchFeedActivity();
+                        activity.showFeed();
                         // TODO: [Feed] add Feed logging.
                         break;
                     case R.id.nav_item_today:
@@ -247,11 +246,6 @@
         for (int i = 0; i < activity.getNavMenu().size(); i++) {
             activity.getNavMenu().getItem(i).setChecked(false);
         }
-    }
-
-    private void launchFeedActivity() {
-        activity.closeNavDrawer();
-        activity.startActivity(FeedActivity.newIntent(activity));
     }
 
     private void launchSettingsActivity() {
diff --git a/app/src/main/java/org/wikipedia/page/PageFragment.java 
b/app/src/main/java/org/wikipedia/page/PageFragment.java
index 31fbdfa..dba9f33 100755
--- a/app/src/main/java/org/wikipedia/page/PageFragment.java
+++ b/app/src/main/java/org/wikipedia/page/PageFragment.java
@@ -14,7 +14,6 @@
 import android.support.v4.view.animation.FastOutSlowInInterpolator;
 import android.support.v4.widget.SwipeRefreshLayout;
 import android.support.v7.app.AlertDialog;
-import android.support.v7.app.AppCompatActivity;
 import android.support.v7.view.ActionMode;
 import android.text.Html;
 import android.util.Log;
@@ -473,7 +472,6 @@
     @Override
     public void onResume() {
         super.onResume();
-        ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("");
         initPageScrollFunnel();
     }
 
@@ -628,6 +626,7 @@
         if (!isAdded() || getMainActivity().isSearching()) {
             return;
         }
+        menu.clear();
         inflater.inflate(R.menu.menu_page_actions, menu);
     }
 
diff --git 
a/app/src/main/java/org/wikipedia/readinglist/AddToReadingListDialog.java 
b/app/src/main/java/org/wikipedia/readinglist/AddToReadingListDialog.java
index 3836b6a..c2894e0 100644
--- a/app/src/main/java/org/wikipedia/readinglist/AddToReadingListDialog.java
+++ b/app/src/main/java/org/wikipedia/readinglist/AddToReadingListDialog.java
@@ -34,7 +34,8 @@
         BOOKMARK_BUTTON(0),
         CONTEXT_MENU(1),
         LINK_PREVIEW_MENU(2),
-        PAGE_OVERFLOW_MENU(3);
+        PAGE_OVERFLOW_MENU(3),
+        FEED(4);
 
         private static final EnumCodeMap<InvokeSource> MAP = new 
EnumCodeMap<>(InvokeSource.class);
 
diff --git 
a/app/src/main/java/org/wikipedia/readinglist/ReadingListsFragment.java 
b/app/src/main/java/org/wikipedia/readinglist/ReadingListsFragment.java
index 055a00a..87b3200 100644
--- a/app/src/main/java/org/wikipedia/readinglist/ReadingListsFragment.java
+++ b/app/src/main/java/org/wikipedia/readinglist/ReadingListsFragment.java
@@ -120,6 +120,7 @@
 
     @Override
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+        menu.clear();
         inflater.inflate(R.menu.menu_reading_lists, menu);
     }
 
diff --git a/app/src/main/res/drawable/ic_menu_white_24dp.xml 
b/app/src/main/res/drawable/ic_menu_white_24dp.xml
new file mode 100644
index 0000000..cf37e2a
--- /dev/null
+++ b/app/src/main/res/drawable/ic_menu_white_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android";
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FFFFFFFF"
+        
android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z"/>
+</vector>
diff --git a/app/src/main/res/layout/view_list_card_item.xml 
b/app/src/main/res/layout/view_list_card_item.xml
index 2fde418..6d80844 100644
--- a/app/src/main/res/layout/view_list_card_item.xml
+++ b/app/src/main/res/layout/view_list_card_item.xml
@@ -2,38 +2,46 @@
     xmlns:android="http://schemas.android.com/apk/res/android";
     xmlns:tools="http://schemas.android.com/tools";>
 
-    <com.facebook.drawee.view.SimpleDraweeView
-        style="@style/SimpleDraweeViewPlaceholder.Article"
-        android:id="@+id/view_list_card_item_image"
-        android:layout_width="@dimen/defaultListItemSize"
-        android:layout_height="@dimen/defaultListItemSize"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentStart="true" />
-
-    <TextView
-        android:id="@+id/view_list_card_item_title"
-        android:layout_width="wrap_content"
+    <RelativeLayout
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_toRightOf="@id/view_list_card_item_image"
-        android:layout_toEndOf="@id/view_list_card_item_image"
-        android:layout_marginLeft="16dp"
-        android:layout_marginRight="16dp"
-        android:textAppearance="@style/TextAppearance.AppCompat.Large"
-        android:textSize="16sp"
-        android:textStyle="bold"
-        tools:text="Lorem ipsum"/>
+        android:padding="@dimen/list_item_horizontal_padding"
+        android:background="?attr/selectableItemBackground">
 
-    <TextView
-        android:id="@+id/view_list_card_item_subtitle"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_toRightOf="@id/view_list_card_item_image"
-        android:layout_toEndOf="@id/view_list_card_item_image"
-        android:layout_below="@id/view_list_card_item_title"
-        android:layout_marginLeft="16dp"
-        android:layout_marginRight="16dp"
-        android:textAppearance="@style/TextAppearance.AppCompat.Medium"
-        android:textSize="14sp"
-        tools:text="Lorem ipsum"/>
+        <com.facebook.drawee.view.SimpleDraweeView
+            style="@style/SimpleDraweeViewPlaceholder.Article"
+            android:id="@+id/view_list_card_item_image"
+            android:layout_width="@dimen/defaultListItemSize"
+            android:layout_height="@dimen/defaultListItemSize"
+            android:layout_alignParentLeft="true"
+            android:layout_alignParentStart="true" />
+
+        <TextView
+            android:id="@+id/view_list_card_item_title"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_toRightOf="@id/view_list_card_item_image"
+            android:layout_toEndOf="@id/view_list_card_item_image"
+            android:layout_marginLeft="16dp"
+            android:layout_marginRight="16dp"
+            android:textAppearance="@style/TextAppearance.AppCompat.Large"
+            android:textSize="16sp"
+            android:textStyle="bold"
+            tools:text="Lorem ipsum"/>
+
+        <TextView
+            android:id="@+id/view_list_card_item_subtitle"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_toRightOf="@id/view_list_card_item_image"
+            android:layout_toEndOf="@id/view_list_card_item_image"
+            android:layout_below="@id/view_list_card_item_title"
+            android:layout_marginLeft="16dp"
+            android:layout_marginRight="16dp"
+            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
+            android:textSize="14sp"
+            tools:text="Lorem ipsum"/>
+
+    </RelativeLayout>
 
 </merge>
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0663b26dd247f65a28655213b73e08e07078426b
Gerrit-PatchSet: 6
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org>
Gerrit-Reviewer: Niedzielski <sniedziel...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to