Bug 1288106 - History RecyclerView layout fixtures and cleanup r?ahunt
MozReview-Commit-ID: I1B1P3OwZET
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ActivityStream.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ActivityStream.java
@@ -59,17 +59,17 @@ public class ActivityStream extends Fram
public void setBanner(HomeBanner banner) {
// TODO: we should probably implement this to show snippets.
}
@Override
public void load(LoaderManager lm, FragmentManager fm, String panelId, Bundle restoreData,
PropertyAnimator animator) {
// Signal to load data from storage as needed, compare with HomePager
- RecyclerView rv = (RecyclerView) findViewById(R.id.recycler_main);
+ RecyclerView rv = (RecyclerView) findViewById(R.id.activity_stream_main_recyclerview);
rv.setAdapter(new MainRecyclerAdapter(getContext()));
rv.setLayoutManager(new LinearLayoutManager(getContext()));
rv.setHasFixedSize(true);
}
@Override
public void unload() {
// Signal to clear data that has been loaded, compare with HomePager
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/HighlightRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/HighlightRecyclerAdapter.java
@@ -12,18 +12,18 @@ import android.widget.TextView;
import org.mozilla.gecko.R;
class HighlightRecyclerAdapter extends RecyclerView.Adapter<HighlightRecyclerAdapter.ViewHolder> {
private final Context context;
private final String[] items = {
"What Do The Reviews Have To Say About the New Ghostbusters",
"The Dark Secrets Of This Now-Empty Island in Maine",
- "What Do The Reviews Have To Say About the New Ghostbusters",
- "The Dark Secrets Of This Now-Empty Island in Maine"
+ "How to Prototype a Game in Under 7 Days (2005)",
+ "Fuchsia, a new operating system"
};
private final String[] items_time = {
"3h",
"3h",
"3h",
"3h"
};
@@ -38,17 +38,18 @@ class HighlightRecyclerAdapter extends R
.inflate(R.layout.activity_stream_card_highlights_item, parent, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.vLabel.setText(items[position]);
holder.vTimeSince.setText(items_time[position]);
- int res = context.getResources().getIdentifier("thumb_" + (position+1), "drawable", context.getPackageName());
+ int res = context.getResources()
+ .getIdentifier("thumb_" + (position + 1), "drawable", context.getPackageName());
holder.vThumbnail.setImageResource(res);
}
@Override
public int getItemCount() {
return items.length;
}
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/HistoryRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/HistoryRecyclerAdapter.java
@@ -12,20 +12,20 @@ import android.widget.TextView;
import org.mozilla.gecko.R;
class HistoryRecyclerAdapter extends RecyclerView.Adapter<HistoryRecyclerAdapter.ViewHolder> {
private final Context context;
private final String[] items = {
"What Do The Reviews Have To Say About the New Ghostbusters",
- "What Do The Reviews Have To Say About the New Ghostbusters",
- "What Do The Reviews Have To Say About the New Ghostbusters",
- "What Do The Reviews Have To Say About the New Ghostbusters",
- "What Do The Reviews Have To Say About the New Ghostbusters"
+ "New “Leaf” Is More Efficient Than Natural Photosynthesis",
+ "Zero-cost futures in Rust",
+ "Indie Hackers: Learn how developers are making money",
+ "The fight to cheat death is heating up"
};
HistoryRecyclerAdapter(Context context) {
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
@@ -33,20 +33,16 @@ class HistoryRecyclerAdapter extends Rec
.from(context)
.inflate(R.layout.activity_stream_card_history_item, parent, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.vLabel.setText(items[position]);
-// float px = TypedValue.applyDimension(
-// TypedValue.COMPLEX_UNIT_DIP, 120, context.getResources().getDisplayMetrics());
-// holder.itemView.setLayoutParams(new CardView.LayoutParams(
-// holder.itemView.getWidth(), (int) px));
}
@Override
public int getItemCount() {
return items.length;
}
static class ViewHolder extends RecyclerView.ViewHolder {
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/MainRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/MainRecyclerAdapter.java
@@ -3,104 +3,126 @@ package org.mozilla.gecko.home.activitys
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.mozilla.gecko.R;
import java.util.Arrays;
import java.util.List;
class MainRecyclerAdapter extends RecyclerView.Adapter<MainRecyclerAdapter.ViewHolder> {
+ private final Context context;
+
+ private static final int VIEW_TYPE_TOP_SITES = 0;
+ private static final int VIEW_TYPE_HIGHLIGHTS = 1;
+ private static final int VIEW_TYPE_HISTORY = 2;
+
+ private static final int VIEW_SIZE_TOP_SITES = 115;
+ private static final int VIEW_SIZE_HIGHLIGHTS = 220;
+ private static final int VIEW_SIZE_HISTORY = 80;
+
private final List<Item> categories = Arrays.asList(
new Item("Top Sites"),
new Item("Highlights"),
new Item("History")
);
- private final Context context;
-
- private static final int VIEW_TYPE_TOP_SITES = 0;
- private static final int VIEW_TYPE_HIGHLIGHTS = 1;
- private static final int VIEW_TYPE_HISTORY = 2;
-
MainRecyclerAdapter(Context context) {
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater
.from(context)
.inflate(R.layout.activity_stream_category, parent, false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
- LinearLayoutManager layoutManager = new LinearLayoutManager(context);
+ LinearLayoutManager llm = new LinearLayoutManager(context);
if (position == VIEW_TYPE_TOP_SITES) {
- setCorrectedLayoutOrientation(layoutManager, LinearLayoutManager.HORIZONTAL);
- setCorrectedLayoutHeight(115, holder, layoutManager, context);
holder.vCategoryRv.setAdapter(new TopSitesRecyclerAdapter(context));
+ setCorrectedLayoutOrientation(llm, LinearLayoutManager.HORIZONTAL);
+ setCorrectedLayoutHeight(context, VIEW_SIZE_TOP_SITES, holder, llm);
} else if (position == VIEW_TYPE_HIGHLIGHTS) {
- setCorrectedLayoutOrientation(layoutManager, LinearLayoutManager.HORIZONTAL);
- setCorrectedLayoutHeight(220, holder, layoutManager, context);
holder.vCategoryRv.setAdapter(new HighlightRecyclerAdapter(context));
+ setCorrectedLayoutOrientation(llm, LinearLayoutManager.HORIZONTAL);
+ setCorrectedLayoutHeight(context, VIEW_SIZE_HIGHLIGHTS, holder, llm);
} else if (position == VIEW_TYPE_HISTORY) {
- setCorrectedLayoutOrientation(layoutManager, LinearLayoutManager.VERTICAL);
- setCorrectedLayoutHeight(300, holder, layoutManager, context);
holder.vCategoryRv.setAdapter(new HistoryRecyclerAdapter(context));
+ setCorrectedLayoutOrientation(llm, LinearLayoutManager.VERTICAL);
+ setCorrectedLayoutHeight(context, VIEW_SIZE_HISTORY, holder, llm);
}
- holder.vTitle.setText(categories.get(position).getLabel());
- holder.vCategoryRv.setLayoutManager(layoutManager);
+ holder.vCategoryRv.setLayoutManager(llm);
+
+ if (position != VIEW_TYPE_HISTORY) {
+ holder.vTitle.setText(categories.get(position).getLabel());
+ holder.vMore.setVisibility(View.VISIBLE);
+ }
}
@Override
public int getItemCount() {
return categories.size();
}
- private static void setCorrectedLayoutHeight(final int height,
- final ViewHolder holder,
- final LinearLayoutManager llm,
- final Context context) {
- float px;
- if (llm.getOrientation() == LinearLayoutManager.VERTICAL) {
- px = LinearLayout.LayoutParams.MATCH_PARENT;
- } else {
- px = TypedValue.applyDimension(
- TypedValue.COMPLEX_UNIT_DIP, height, context.getResources().getDisplayMetrics());
+ private void setCorrectedLayoutHeight(final Context context,
+ final int height,
+ final ViewHolder holder,
+ final LinearLayoutManager llm) {
+ int correctedHeight = height;
+ if (isHistoryView(llm)) {
+ int holderItemCount;
+ holderItemCount = holder.vCategoryRv.getAdapter().getItemCount();
+ correctedHeight = height * holderItemCount;
}
+ setHolderRecyclerViewHeight(holder,
+ getActualPixelValue(context, correctedHeight));
+ }
+
+ private static int getActualPixelValue(Context context, int height) {
+ return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, height,
+ context.getResources().getDisplayMetrics());
+ }
+
+ private static void setHolderRecyclerViewHeight(ViewHolder holder, int height) {
holder.vCategoryRv.setLayoutParams(new LinearLayout.LayoutParams(
- holder.vCategoryRv.getLayoutParams().width, (int) px));
+ holder.vCategoryRv.getLayoutParams().width, height));
+ }
+
+ private static boolean isHistoryView(LinearLayoutManager llm) {
+ return llm.getOrientation() == LinearLayoutManager.VERTICAL;
}
private void setCorrectedLayoutOrientation(final LinearLayoutManager lm,
final int orientation) {
lm.setOrientation(orientation);
}
static class ViewHolder extends RecyclerView.ViewHolder {
TextView vTitle;
+ TextView vMore;
RecyclerView vCategoryRv;
ViewHolder(View itemView) {
super(itemView);
vTitle = (TextView) itemView.findViewById(R.id.category_title);
+ vMore = (TextView) itemView.findViewById(R.id.category_more_link);
vCategoryRv = (RecyclerView) itemView.findViewById(R.id.recycler_category);
}
}
static class Item {
String label;
Item(String label) {
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/MainRecyclerLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/MainRecyclerLayout.java
@@ -7,17 +7,17 @@ import android.support.v7.widget.Recycle
import android.util.AttributeSet;
import android.widget.LinearLayout;
import org.mozilla.gecko.R;
public class MainRecyclerLayout extends LinearLayout {
public MainRecyclerLayout(Context context) {
super(context);
- RecyclerView rv = (RecyclerView) findViewById(R.id.recycler_main);
+ RecyclerView rv = (RecyclerView) findViewById(R.id.activity_stream_main_recyclerview);
rv.setAdapter(new MainRecyclerAdapter(context));
rv.setLayoutManager(new LinearLayoutManager(context));
}
public MainRecyclerLayout(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/TopSitesRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/TopSitesRecyclerAdapter.java
@@ -8,22 +8,23 @@ import android.view.ViewGroup;
import android.widget.TextView;
import org.mozilla.gecko.R;
class TopSitesRecyclerAdapter extends RecyclerView.Adapter<TopSitesRecyclerAdapter.ViewHolder> {
private final Context context;
private final String[] items = {
+ "FastMail",
"Firefox",
"Mozilla",
- "fx-team",
- "Firefox",
- "Mozilla",
- "fx-team"
+ "Hacker News",
+ "Github",
+ "YouTube",
+ "Google Maps"
};
TopSitesRecyclerAdapter(Context context) {
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -398,17 +398,16 @@ gbjar.sources += ['java/org/mozilla/geck
'GlobalHistory.java',
'GuestSession.java',
'health/HealthRecorder.java',
'health/SessionInformation.java',
'health/StubbedHealthRecorder.java',
'home/activitystream/ActivityStream.java',
'home/activitystream/HighlightRecyclerAdapter.java',
'home/activitystream/HistoryRecyclerAdapter.java',
- 'home/activitystream/Item.java',
'home/activitystream/MainRecyclerAdapter.java',
'home/activitystream/MainRecyclerLayout.java',
'home/activitystream/TopSitesRecyclerAdapter.java',
'home/BookmarkFolderView.java',
'home/BookmarkScreenshotRow.java',
'home/BookmarksListAdapter.java',
'home/BookmarksListView.java',
'home/BookmarksPanel.java',
--- a/mobile/android/base/resources/layout/activity_stream.xml
+++ b/mobile/android/base/resources/layout/activity_stream.xml
@@ -1,16 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<org.mozilla.gecko.home.activitystream.ActivityStream xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:background="@android:color/white">
-
+ android:background="#FAFAFA">
<android.support.v7.widget.RecyclerView
- android:id="@+id/recycler_main"
+ android:id="@+id/activity_stream_main_recyclerview"
android:layout_marginTop="12dp"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</org.mozilla.gecko.home.activitystream.ActivityStream>
--- a/mobile/android/base/resources/layout/activity_stream_card_highlights_item.xml
+++ b/mobile/android/base/resources/layout/activity_stream_card_highlights_item.xml
@@ -11,24 +11,24 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="vertical">
<FrameLayout
+ android:background="@color/disabled_grey"
android:layout_width="match_parent"
android:layout_height="140dp">
<ImageView
- android:visibility="gone"
+ android:visibility="visible"
android:id="@+id/card_highlights_thumbnail"
- android:src="@drawable/search_icon_active"
- android:scaleType="centerCrop"
+ android:src="@drawable/favicon_globe"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<RelativeLayout
android:padding="3dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
--- a/mobile/android/base/resources/layout/activity_stream_card_history_item.xml
+++ b/mobile/android/base/resources/layout/activity_stream_card_history_item.xml
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:layout_marginTop="10dp"
- android:layout_marginBottom="10dp"
+ android:layout_marginBottom="0dp"
android:layout_width="match_parent"
android:layout_height="60dp">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent">
--- a/mobile/android/base/resources/layout/activity_stream_category.xml
+++ b/mobile/android/base/resources/layout/activity_stream_category.xml
@@ -17,24 +17,26 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<TextView
android:id="@+id/category_more_link"
android:text="More"
+ android:visibility="invisible"
android:textAllCaps="true"
android:textSize="14sp"
android:textColor="@android:color/holo_orange_dark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_category"
+ android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>