Bug 1395792 - Hide Highlights empty state when Highlights are disabled. r=mcomella
authorChenxia Liu <liuche@mozilla.com>
Tue, 19 Sep 2017 17:49:41 -0700
changeset 431587 072a236f67fe85171955a001ef3ee12fb830365f
parent 431586 ed817e1a17ba8a2f66c955a6b5bf252d7e8e8985
child 431588 f39c3b2da2d12890a0c1d11b217a90f22fb1d9ce
push id7785
push userryanvm@gmail.com
push dateThu, 21 Sep 2017 13:39:55 +0000
treeherdermozilla-beta@06d4034a8a03 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1395792
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 1395792 - Hide Highlights empty state when Highlights are disabled. r=mcomella MozReview-Commit-ID: FMFTAFuWLqh
mobile/android/app/src/main/res/layout/activity_stream_highlights_empty_state.xml
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
--- a/mobile/android/app/src/main/res/layout/activity_stream_highlights_empty_state.xml
+++ b/mobile/android/app/src/main/res/layout/activity_stream_highlights_empty_state.xml
@@ -1,12 +1,18 @@
 <?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/. -->
+
+<!-- The width and height of this view are always overridden in onBindViewHolder because
+     this view is dynamically shown/hidden.
+
+     See StreamRecyclerAdapter.setViewVisible . -->
+
 <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/app/src/main/res/layout/activity_stream_main_highlightstitle.xml
+++ b/mobile/android/app/src/main/res/layout/activity_stream_main_highlightstitle.xml
@@ -1,20 +1,18 @@
 <?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/. -->
 
-<!-- The width and height of this view are always overridden in StreamTitleRow because
-     this view is dynamically shown/hidden in onBindViewHolder.
+<!-- The width and height of this view are always overridden in onBindViewHolder because
+     this view is dynamically shown/hidden.
 
-     NB: This is a hack because the title views for each section are always included
-     in the RecyclerView adapter.
-     A more correct implementation would dynamically add/remove these title views rather than
-     showing and hiding them. -->
+     See StreamRecyclerAdapter.setViewVisible . -->
+
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="0dp"
     android:layout_height="0dp"
     android:orientation="horizontal">
 
     <TextView
         android:id="@+id/title_highlights"
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
@@ -176,32 +176,62 @@ public class StreamRecyclerAdapter exten
         if (type == RowItemType.HIGHLIGHT_ITEM.getViewType()) {
             final Highlight highlight = (Highlight) recyclerViewModel.get(position);
             ((WebpageItemRow) holder).bind(highlight, position, tilesSize);
         } else if (type == RowItemType.TOP_PANEL.getViewType()) {
             ((TopPanelRow) holder).bind(topSitesCursor, tilesSize);
         } else if (type == RowItemType.TOP_STORIES_ITEM.getViewType()) {
             final TopStory story = (TopStory) recyclerViewModel.get(position);
             ((WebpageItemRow) holder).bind(story, position, tilesSize);
-        } else if (type == RowItemType.HIGHLIGHTS_TITLE.getViewType()) {
+        } else if (type == RowItemType.HIGHLIGHTS_TITLE.getViewType()
+                || type == RowItemType.HIGHLIGHTS_EMPTY_STATE.getViewType()) {
             final Context context = holder.itemView.getContext();
             final SharedPreferences sharedPreferences = GeckoSharedPrefs.forProfile(context);
             final boolean bookmarksEnabled = sharedPreferences.getBoolean(ActivityStreamPanel.PREF_BOOKMARKS_ENABLED,
                     context.getResources().getBoolean(R.bool.pref_activitystream_recentbookmarks_enabled_default));
             final boolean visitedEnabled = sharedPreferences.getBoolean(ActivityStreamPanel.PREF_VISITED_ENABLED,
                     context.getResources().getBoolean(R.bool.pref_activitystream_visited_enabled_default));
-            ((StreamTitleRow) holder).setVisible(bookmarksEnabled || visitedEnabled);
+            setViewVisible(bookmarksEnabled || visitedEnabled, holder.itemView);
         } else if (type == RowItemType.TOP_STORIES_TITLE.getViewType()) {
             final Context context = holder.itemView.getContext();
             final boolean pocketEnabled = GeckoSharedPrefs.forProfile(context).getBoolean(ActivityStreamPanel.PREF_POCKET_ENABLED,
                     context.getResources().getBoolean(R.bool.pref_activitystream_pocket_enabled_default));
-            ((StreamTitleRow) holder).setVisible(pocketEnabled);
+            setViewVisible(pocketEnabled, holder.itemView);
         }
     }
 
+    /**
+     * This sets a child view of the adapter visible or hidden.
+     *
+     * This only applies to children whose height and width are WRAP_CONTENT and MATCH_PARENT
+     * respectively.
+     *
+     * NB: This is a hack for the views that are included in the RecyclerView adapter even if
+     * they shouldn't be shown, such as the section title views or the empty view for highlights.
+     *
+     * A more correct implementation would dynamically add/remove these title views rather than
+     * showing and hiding them.
+     *
+     * @param toShow true if the view is to be shown, false to be hidden
+     * @param view child View whose visibility is to be changed
+     */
+    private static void setViewVisible(boolean toShow, final View view) {
+        view.setVisibility(toShow ? View.VISIBLE : View.GONE);
+        // We also need to set the layout height and width to 0 for the RecyclerView child.
+        final RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams();
+        if (toShow) {
+            layoutParams.height = RecyclerView.LayoutParams.WRAP_CONTENT;
+            layoutParams.width = RecyclerView.LayoutParams.MATCH_PARENT;
+        } else {
+            layoutParams.height = 0;
+            layoutParams.width = 0;
+        }
+        view.setLayoutParams(layoutParams);
+    }
+
     @Override
     public void onItemClicked(RecyclerView recyclerView, int position, View v) {
         if (!onItemClickIsValidRowItem(position)) {
             return;
         }
 
         final WebpageRowModel model = (WebpageRowModel) recyclerViewModel.get(position);
 
--- 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
@@ -2,17 +2,16 @@
  * 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.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;
 
@@ -44,24 +43,10 @@ public class StreamTitleRow extends Stre
             public void onClick(View view) {
                 onUrlOpenListener.onUrlOpen(url, EnumSet.of(HomePager.OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB));
             }
         };
 
         titleLink.setOnClickListener(clickListener);
         titleArrow.setOnClickListener(clickListener);
     }
-
-    public void setVisible(boolean toShow) {
-        itemView.setVisibility(toShow ? View.VISIBLE : View.GONE);
-        // We also need to set the layout height and width to 0 for the RecyclerView child.
-        final RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) itemView.getLayoutParams();
-        if (toShow) {
-            layoutParams.height = RecyclerView.LayoutParams.WRAP_CONTENT;
-            layoutParams.width = RecyclerView.LayoutParams.MATCH_PARENT;
-        } else {
-            layoutParams.height = 0;
-            layoutParams.width = 0;
-        }
-        itemView.setLayoutParams(layoutParams);
-    }
 }