Bug 1393174 - Add "More" link to Pocket AS title. r?mcomella draft
authorChenxia Liu <liuche@mozilla.com>
Thu, 14 Sep 2017 17:54:50 -0700
changeset 665752 aecf85eed6e65d810dde4b7afdaa54b3ad4b6075
parent 664985 593158cd491002031b4527a95d9bfac79c0cdcef
child 665753 37399dd3877440c09e8f5bdbc1bb4658b48271d4
push id80157
push usercliu@mozilla.com
push dateFri, 15 Sep 2017 21:51:19 +0000
reviewersmcomella
bugs1393174
milestone57.0a1
Bug 1393174 - Add "More" link to Pocket AS title. r?mcomella MozReview-Commit-ID: kromR87f43
mobile/android/app/src/main/res/layout/activity_stream_main_highlightstitle.xml
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/StreamTitleRow.java
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/strings.xml.in
--- a/mobile/android/app/src/main/res/layout/activity_stream_main_highlightstitle.xml
+++ b/mobile/android/app/src/main/res/layout/activity_stream_main_highlightstitle.xml
@@ -1,17 +1,44 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/title_highlights"
-    android:layout_marginLeft="@dimen/activity_stream_base_margin"
-    android:layout_marginStart="@dimen/activity_stream_base_margin"
-    android:layout_marginTop="@dimen/activity_stream_base_margin"
-    android:layout_marginBottom="@dimen/activity_stream_base_margin"
-    android:layout_marginRight="@dimen/activity_stream_base_margin"
-    android:layout_marginEnd="@dimen/activity_stream_base_margin"
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:textStyle="bold"
-    android:textSize="16sp"
-    android:textColor="#FF858585" />
+    android:orientation="horizontal">
+
+    <TextView
+        android:id="@+id/title_highlights"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        android:layout_margin="@dimen/activity_stream_base_margin"
+        android:textColor="#FF858585"
+        android:textSize="16sp"
+        android:textStyle="bold" />
+
+    <!-- These *_link items are shown if the constructor includes a link to be shown
+    on the right side of the stream title -->
+    <TextView
+        android:id="@+id/title_link"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:gravity="center_vertical"
+        android:paddingStart="0dp"
+        android:paddingLeft="0dp"
+        android:paddingEnd="@dimen/activity_stream_base_margin"
+        android:paddingRight="@dimen/activity_stream_base_margin"
+        android:textAppearance="@style/TextAppearance.FirstrunRegular.Link"
+        android:textAllCaps="true"
+        android:visibility="gone"/>
+
+    <ImageView
+        android:id="@+id/arrow_link"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:layout_marginEnd="@dimen/activity_stream_base_margin"
+        android:layout_marginRight="@dimen/activity_stream_base_margin"
+        android:visibility="gone"/>
+
+</LinearLayout>
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
@@ -51,16 +51,17 @@ public class StreamRecyclerAdapter exten
 
     private Cursor topSitesCursor;
     private List<RowModel> recyclerViewModel; // List of item types backing this RecyclerView.
     private List<TopStory> topStoriesQueue;
 
     // Content sections available on the Activity Stream page. These may be hidden if the sections are disabled.
     private final RowItemType[] ACTIVITY_STREAM_SECTIONS = { RowItemType.TOP_PANEL, RowItemType.TOP_STORIES_TITLE, RowItemType.HIGHLIGHTS_TITLE };
     public static final int MAX_TOP_STORIES = 3;
+    private static final String LINK_MORE_POCKET = "https://getpocket.cdn.mozilla.net/explore/trending?src=ff_android";
 
     private HomePager.OnUrlOpenListener onUrlOpenListener;
     private HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener;
 
     private int tiles;
     private int tilesSize;
 
     public enum RowItemType {
@@ -123,17 +124,17 @@ public class StreamRecyclerAdapter exten
     @Override
     public StreamViewHolder onCreateViewHolder(ViewGroup parent, final int type) {
         final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
 
         if (type == RowItemType.TOP_PANEL.getViewType()) {
             return new TopPanelRow(inflater.inflate(TopPanelRow.LAYOUT_ID, parent, false), onUrlOpenListener, onUrlOpenInBackgroundListener);
         } else if (type == RowItemType.TOP_STORIES_TITLE.getViewType()) {
             final boolean pocketEnabled = GeckoSharedPrefs.forProfile(parent.getContext()).getBoolean(ActivityStreamPanel.PREF_POCKET_ENABLED, true);
-            return new StreamTitleRow(inflater.inflate(StreamTitleRow.LAYOUT_ID, parent, false), R.string.activity_stream_topstories, pocketEnabled);
+            return new StreamTitleRow(inflater.inflate(StreamTitleRow.LAYOUT_ID, parent, false), R.string.activity_stream_topstories, pocketEnabled, R.string.activity_stream_link_more, LINK_MORE_POCKET, onUrlOpenListener);
         } else if (type == RowItemType.TOP_STORIES_ITEM.getViewType()) {
             return new WebpageItemRow(inflater.inflate(WebpageItemRow.LAYOUT_ID, parent, false), this);
         } else if (type == RowItemType.HIGHLIGHT_ITEM.getViewType()) {
             return new WebpageItemRow(inflater.inflate(WebpageItemRow.LAYOUT_ID, parent, false), this);
         } else if (type == RowItemType.HIGHLIGHTS_TITLE.getViewType()) {
             final SharedPreferences sharedPreferences = GeckoSharedPrefs.forProfile(parent.getContext());
             final boolean bookmarksEnabled = sharedPreferences.getBoolean(ActivityStreamPanel.PREF_BOOKMARKS_ENABLED, true);
             final boolean visitedEnabled = sharedPreferences.getBoolean(ActivityStreamPanel.PREF_VISITED_ENABLED, true);
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/StreamTitleRow.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/StreamTitleRow.java
@@ -4,32 +4,60 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.activitystream.homepanel.stream;
 
 import android.support.annotation.NonNull;
 import android.support.annotation.StringRes;
 import android.support.v7.widget.RecyclerView;
 import android.view.View;
+import android.widget.ImageView;
 import android.widget.TextView;
 
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.home.HomePager;
+import org.mozilla.gecko.util.DrawableUtil;
+
+import java.util.EnumSet;
 
 public class StreamTitleRow extends StreamViewHolder {
     public static final int LAYOUT_ID = R.layout.activity_stream_main_highlightstitle;
 
     public StreamTitleRow(final View itemView, final @StringRes @NonNull int titleResId, boolean isEnabled) {
         super(itemView);
         final TextView titleView = (TextView) itemView.findViewById(R.id.title_highlights);
         titleView.setText(titleResId);
         if (!isEnabled) {
             hideView(itemView);
         }
     }
 
+    public StreamTitleRow(final View itemView, final @StringRes @NonNull int titleResId, boolean isEnabled,
+                          final @StringRes int linkTitleResId, final String url, final HomePager.OnUrlOpenListener onUrlOpenListener) {
+        this(itemView, titleResId, isEnabled);
+        // Android 21+ is needed to set RTL-aware compound drawables, so we use a tinted ImageView here.
+        final TextView titleLink = (TextView) itemView.findViewById(R.id.title_link);
+        titleLink.setVisibility(View.VISIBLE);
+        titleLink.setText(linkTitleResId);
+
+        final ImageView titleArrow = (ImageView) itemView.findViewById(R.id.arrow_link);
+        titleArrow.setImageDrawable(DrawableUtil.tintDrawableWithColorRes(itemView.getContext(), R.drawable.menu_item_more, R.color.ob_click));
+        titleArrow.setVisibility(View.VISIBLE);
+
+        final View.OnClickListener clickListener = new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                onUrlOpenListener.onUrlOpen(url, EnumSet.of(HomePager.OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB));
+            }
+        };
+
+        titleLink.setOnClickListener(clickListener);
+        titleArrow.setOnClickListener(clickListener);
+    }
+
     private static void hideView(final View itemView) {
         itemView.setVisibility(View.GONE);
         // We also need to set the layout height, width, and margins to 0 for the RecyclerView child.
         final RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) itemView.getLayoutParams();
         layoutParams.setMargins(0, 0, 0, 0);
         layoutParams.height = 0;
         layoutParams.width = 0;
         itemView.setLayoutParams(layoutParams);
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -827,16 +827,19 @@ just addresses the organization to follo
 <!ENTITY helper_triple_readerview_open_message "Bookmark Reader View items to read them offline.">
 <!ENTITY helper_triple_readerview_open_button "Add to Bookmarks">
 
 <!ENTITY activity_stream_topsites "Top Sites">
 <!-- LOCALIZATION NOTE (activity_stream_topstories): &brandPocket is the brand of the company, Pocket, that is being used to provide suggestions for articles. -->
 <!ENTITY activity_stream_topstories "Recommended by &brandPocket;">
 <!ENTITY activity_stream_highlights "Highlights">
 
+<!-- LOCALIZATION NOET (activity_stream_link_more): Link-like text displayed to take user to a website with more content from Pocket. This string will be displayed in all uppercase. -->
+<!ENTITY activity_stream_link_more "more">
+
 <!-- LOCALIZATION NOTE (activity_stream_highlight_label_bookmarked): This label is shown in the Activity
 Stream list for highlights sourced from th user's bookmarks. -->
 <!ENTITY activity_stream_highlight_label_bookmarked "Bookmarked">
 <!-- LOCALIZATION NOTE (activity_stream_highlight_label_visited): This label is shown in the Activity
 Stream list for highlights sourced from th user's bookmarks. -->
 <!ENTITY activity_stream_highlight_label_visited "Visited">
 <!-- LOCALIZATION NOTE (activity_stream_highlight_label_trending): This label is shown in the Activity Stream list for highlights sourced from a recommendations engine. -->
 <!ENTITY activity_stream_highlight_label_trending "Trending">
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -620,16 +620,18 @@
 
   <string name="helper_triple_readerview_open_title">&helper_triple_readerview_open_title;</string>
   <string name="helper_triple_readerview_open_message">&helper_triple_readerview_open_message;</string>
   <string name="helper_triple_readerview_open_button">&helper_triple_readerview_open_button;</string>
 
   <string name="activity_stream_topsites">&activity_stream_topsites;</string>
   <string name="activity_stream_topstories">&activity_stream_topstories;</string>
   <string name="activity_stream_highlights">&activity_stream_highlights;</string>
+  <string name="activity_stream_link_more">&activity_stream_link_more;</string>
+
   <string name="activity_stream_highlight_label_bookmarked">&activity_stream_highlight_label_bookmarked;</string>
   <string name="activity_stream_highlight_label_visited">&activity_stream_highlight_label_visited;</string>
   <string name="activity_stream_highlight_label_trending">&activity_stream_highlight_label_trending;</string>
   <string name="activity_stream_remove">&activity_stream_remove;</string>
   <string name="activity_stream_delete_history">&activity_stream_delete_history;</string>
 
   <string name="activity_stream_highlights_empty">&activity_stream_highlights_empty;</string>