Bug 1386735 - Support disabling titles in StreamRecyclerView. r?mcomella
MozReview-Commit-ID: 15h7Lp497JN
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamPanel.java
@@ -87,17 +87,19 @@ public class ActivityStreamPanel extends
void setOnUrlOpenListeners(HomePager.OnUrlOpenListener onUrlOpenListener, HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
adapter.setOnUrlOpenListeners(onUrlOpenListener, onUrlOpenInBackgroundListener);
}
public void load(LoaderManager lm) {
lm.initLoader(LOADER_ID_TOPSITES, null, new TopSitesCallback());
lm.initLoader(LOADER_ID_HIGHLIGHTS, null, new HighlightsCallbacks());
- lm.initLoader(LOADER_ID_POCKET, null, new PocketStoriesCallbacks());
+ if (StreamRecyclerAdapter.POCKET_ENABLED) {
+ lm.initLoader(LOADER_ID_POCKET, null, new PocketStoriesCallbacks());
+ }
}
public void unload() {
adapter.swapHighlights(Collections.<Highlight>emptyList());
adapter.swapTopSitesCursor(null);
}
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/HighlightsDividerItemDecoration.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/HighlightsDividerItemDecoration.java
@@ -34,16 +34,19 @@ import android.view.View;
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
final int childCount = parent.getChildCount();
for (int i = START_DRAWING_AT_POSITION; i < childCount; i++) {
final View child = parent.getChildAt(i);
+ if (child.getVisibility() == View.GONE) {
+ continue;
+ }
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getBottom() + params.bottomMargin;
final int bottom = top + divider.getIntrinsicHeight();
divider.setBounds(left, top, right, bottom);
divider.draw(c);
}
}
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
@@ -46,16 +46,19 @@ public class StreamRecyclerAdapter exten
RecyclerViewClickSupport.OnItemLongClickListener, StreamHighlightItemRowContextMenuListener {
private static final String LOGTAG = StringUtils.safeSubstring("Gecko" + StreamRecyclerAdapter.class.getSimpleName(), 0, 23);
private Cursor topSitesCursor;
private List<RowModel> recyclerViewModel; // List of item types backing this RecyclerView.
private List<TopStory> topStoriesQueue;
+ // TODO: Replace temporary pref placeholder with pref
+ public static final boolean POCKET_ENABLED = false;
+
private final RowItemType[] FIXED_ROWS = {RowItemType.TOP_PANEL, RowItemType.WELCOME, RowItemType.TOP_STORIES_TITLE, RowItemType.HIGHLIGHTS_TITLE};
private final int MAX_TOP_STORIES = 3;
private HomePager.OnUrlOpenListener onUrlOpenListener;
private HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener;
private int tiles;
private int tilesSize;
@@ -119,25 +122,25 @@ 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()) {
- return new StreamTitleRow(inflater.inflate(StreamTitleRow.LAYOUT_ID, parent, false), R.string.activity_stream_topstories);
+ return new StreamTitleRow(inflater.inflate(StreamTitleRow.LAYOUT_ID, parent, false), R.string.activity_stream_topstories, POCKET_ENABLED);
} else if (type == RowItemType.TOP_STORIES_ITEM.getViewType()) {
return new WebpageItemRow(inflater.inflate(WebpageItemRow.LAYOUT_ID, parent, false), this);
} else if (type == RowItemType.WELCOME.getViewType()) {
return new WelcomePanelRow(inflater.inflate(WelcomePanelRow.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()) {
- return new StreamTitleRow(inflater.inflate(StreamTitleRow.LAYOUT_ID, parent, false), R.string.activity_stream_highlights);
+ return new StreamTitleRow(inflater.inflate(StreamTitleRow.LAYOUT_ID, parent, false), R.string.activity_stream_highlights, true);
} else {
throw new IllegalStateException("Missing inflation for ViewType " + type);
}
}
/**
* Returns the index of an item within highlights.
* @param position position in adapter
--- 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,23 +2,37 @@
* 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.TextView;
import org.mozilla.gecko.R;
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) {
+ 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);
+ }
+ }
+
+ 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);
}
}