Bug 1388377: Add highlights empty state. r=liuche
☠☠ backed out by 3da77a7e896c ☠ ☠
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 31 Aug 2017 15:21:43 -0700
changeset 378344 512562477a1eaf83075a5a99825dea1ec702b1ad
parent 378343 c5b310c419c4d912df2fe967040f7cc435c5b0c3
child 378345 608f8c2125a79e2497b5ee5b04e4b2d4635d7317
push id32428
push userarchaeopteryx@coole-files.de
push dateSat, 02 Sep 2017 08:52:28 +0000
treeherdermozilla-central@b01a7e57425b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs1388377
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1388377: Add highlights empty state. r=liuche MozReview-Commit-ID: 1M1nqWSoER3
mobile/android/app/src/main/res/layout/activity_stream_highlights_empty_state.xml
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/HighlightsEmptyStateRow.java
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/strings.xml.in
new file mode 100644
--- /dev/null
+++ b/mobile/android/app/src/main/res/layout/activity_stream_highlights_empty_state.xml
@@ -0,0 +1,12 @@
+<?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:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_margin="@dimen/activity_stream_base_margin"
+        android:text="@string/activity_stream_highlights_empty"
+        android:textColor="@color/activity_stream_subtitle"
+        />
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
@@ -17,34 +17,33 @@ import android.view.ViewGroup;
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
 import org.mozilla.gecko.activitystream.homepanel.menu.ActivityStreamContextMenu;
 import org.mozilla.gecko.activitystream.homepanel.model.RowModel;
 import org.mozilla.gecko.activitystream.homepanel.model.WebpageRowModel;
+import org.mozilla.gecko.activitystream.homepanel.stream.HighlightsEmptyStateRow;
 import org.mozilla.gecko.activitystream.homepanel.stream.TopPanelRow;
 import org.mozilla.gecko.activitystream.homepanel.model.TopStory;
 import org.mozilla.gecko.activitystream.homepanel.topstories.PocketStoriesLoader;
 import org.mozilla.gecko.home.HomePager;
 import org.mozilla.gecko.activitystream.homepanel.model.Highlight;
 import org.mozilla.gecko.activitystream.homepanel.stream.WebpageItemRow;
 import org.mozilla.gecko.activitystream.homepanel.stream.StreamTitleRow;
 import org.mozilla.gecko.activitystream.homepanel.stream.StreamViewHolder;
 import org.mozilla.gecko.util.StringUtils;
 import org.mozilla.gecko.widget.RecyclerViewClickSupport;
 
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.LinkedList;
 import java.util.List;
 
-import static android.R.attr.type;
-
 /**
  * The adapter for the Activity Stream panel.
  *
  * Every item is in a single adapter: Top Sites, Welcome panel, Highlights.
  */
 public class StreamRecyclerAdapter extends RecyclerView.Adapter<StreamViewHolder> implements RecyclerViewClickSupport.OnItemClickListener,
         RecyclerViewClickSupport.OnItemLongClickListener, StreamHighlightItemRowContextMenuListener {
 
@@ -64,16 +63,17 @@ public class StreamRecyclerAdapter exten
     private int tiles;
     private int tilesSize;
 
     public enum RowItemType {
         TOP_PANEL (-2), // RecyclerView.NO_ID is -1, so start hard-coded stableIds at -2.
         TOP_STORIES_TITLE(-3),
         TOP_STORIES_ITEM(-1), // There can be multiple Top Stories items so caller should handle as a special case.
         HIGHLIGHTS_TITLE (-4),
+        HIGHLIGHTS_EMPTY_STATE(-5),
         HIGHLIGHT_ITEM (-1); // There can be multiple Highlight Items so caller should handle as a special case.
 
         public final int stableId;
 
         RowItemType(int stableId) {
             this.stableId = stableId;
         }
 
@@ -133,16 +133,18 @@ public class StreamRecyclerAdapter exten
             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);
             return new StreamTitleRow(inflater.inflate(StreamTitleRow.LAYOUT_ID, parent, false), R.string.activity_stream_highlights, bookmarksEnabled || visitedEnabled);
+        } else if (type == RowItemType.HIGHLIGHTS_EMPTY_STATE.getViewType()) {
+            return new HighlightsEmptyStateRow(inflater.inflate(HighlightsEmptyStateRow.LAYOUT_ID, parent, false));
         } else {
             throw new IllegalStateException("Missing inflation for ViewType " + type);
         }
     }
 
     /**
      * Returns the index of an item within highlights.
      * @param position position in adapter
@@ -305,17 +307,21 @@ public class StreamRecyclerAdapter exten
 
     @Override
     public int getItemCount() {
         return recyclerViewModel.size();
     }
 
     public void swapHighlights(List<Highlight> highlights) {
         recyclerViewModel = recyclerViewModel.subList(0, ACTIVITY_STREAM_SECTIONS.length + getNumOfTypeShown(RowItemType.TOP_STORIES_ITEM));
-        recyclerViewModel.addAll(highlights);
+        if (!highlights.isEmpty()) {
+            recyclerViewModel.addAll(highlights);
+        } else {
+            recyclerViewModel.add(makeRowModelFromType(RowItemType.HIGHLIGHTS_EMPTY_STATE));
+        }
         notifyDataSetChanged();
     }
 
     public void swapTopStories(List<TopStory> newStories) {
         final int insertionIndex = indexOfType(RowItemType.TOP_STORIES_TITLE, recyclerViewModel) + 1;
         int numOldStories = getNumOfTypeShown(RowItemType.TOP_STORIES_ITEM);
         while (numOldStories > 0) {
             recyclerViewModel.remove(insertionIndex);
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/HighlightsEmptyStateRow.java
@@ -0,0 +1,20 @@
+/* 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/. */
+
+package org.mozilla.gecko.activitystream.homepanel.stream;
+
+import android.support.annotation.LayoutRes;
+import android.view.View;
+import org.mozilla.gecko.R;
+
+/** A row to be displayed when there are no highlights. */
+public class HighlightsEmptyStateRow extends StreamViewHolder {
+
+    @LayoutRes
+    public static final int LAYOUT_ID = R.layout.activity_stream_highlights_empty_state;
+
+    public HighlightsEmptyStateRow(final View itemView) {
+        super(itemView);
+    }
+}
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -844,16 +844,18 @@ just addresses the organization to follo
 <!-- 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">
+<!-- LOCALIZATION NOTE (activity_stream_highlights_empty): This text is shown when we could not find highlights for this user. This is also shown on first run. -->
+<!ENTITY activity_stream_highlights_empty "Start browsing, and we\'ll show some of the great articles, videos, and other pages you\'ve recently visited or bookmarked here.">
 
 <!-- LOCALIZATION NOTE (activity_stream_remove): This label is shown in the Activity Stream context menu,
 and allows hiding a URL/page from highlights or topsites. The page remains in history/bookmarks, but
 is simply hidden from the Activity Stream panel. -->
 <!ENTITY activity_stream_remove "Remove">
 <!ENTITY activity_stream_delete_history "Delete from History">
 
 <!ENTITY private_tab_panel_title "Private Browsing + Tracking Protection">
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -629,15 +629,17 @@
   <string name="activity_stream_topstories">&activity_stream_topstories;</string>
   <string name="activity_stream_highlights">&activity_stream_highlights;</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>
+
   <string name="private_tab_panel_title">&private_tab_panel_title;</string>
   <string name="private_tab_panel_description">&private_tab_panel_description;</string>
   <string name="private_tab_panel_description2">&private_tab_panel_description2;</string>
   <string name="private_tab_learn_more">&private_tab_learn_more;</string>
 
   <string name="fullscreen_warning">&fullscreen_warning;</string>
 </resources>