Bug 1288106 - More fixed height changes and tweaks r?ahunt
MozReview-Commit-ID: 1i62naZw4OS
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ActivityStream.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ActivityStream.java
@@ -62,15 +62,16 @@ public class ActivityStream extends Fram
@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);
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/HistoryRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/HistoryRecyclerAdapter.java
@@ -1,23 +1,30 @@
package org.mozilla.gecko.home.activitystream;
import android.content.Context;
+import android.support.v7.widget.CardView;
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.LinearLayout;
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"
};
HistoryRecyclerAdapter(Context context) {
this.context = context;
}
@Override
@@ -26,16 +33,20 @@ 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 {
deleted file mode 100644
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/Item.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.mozilla.gecko.home.activitystream;
-
-class Item {
- String label;
-
- Item(String label) {
- setLabel(label);
- }
-
- public void setLabel(String label) {
- this.label = label;
- }
-
- public String getLabel() {
- return label;
- }
-}
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/MainRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/MainRecyclerAdapter.java
@@ -9,86 +9,110 @@ 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.ArrayList;
+import java.util.Arrays;
import java.util.List;
class MainRecyclerAdapter extends RecyclerView.Adapter<MainRecyclerAdapter.ViewHolder> {
- private final List<Item> categories;
+ 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;
- categories = new ArrayList<>();
- categories.add(new Item("Top Sites"));
- categories.add(new Item("Highlights"));
- categories.add(new Item("History"));
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, parent.getResources().getDisplayMetrics());
- parent.setLayoutParams(new FrameLayout.LayoutParams(parent.getLayoutParams().width, (int) px));
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);
if (position == VIEW_TYPE_TOP_SITES) {
setCorrectedLayoutOrientation(layoutManager, LinearLayoutManager.HORIZONTAL);
- setCorrectedLayoutHeight(115, holder, context);
+ setCorrectedLayoutHeight(115, holder, layoutManager, context);
holder.vCategoryRv.setAdapter(new TopSitesRecyclerAdapter(context));
} else if (position == VIEW_TYPE_HIGHLIGHTS) {
setCorrectedLayoutOrientation(layoutManager, LinearLayoutManager.HORIZONTAL);
- setCorrectedLayoutHeight(220, holder, context);
+ setCorrectedLayoutHeight(220, holder, layoutManager, context);
holder.vCategoryRv.setAdapter(new HighlightRecyclerAdapter(context));
} else if (position == VIEW_TYPE_HISTORY) {
setCorrectedLayoutOrientation(layoutManager, LinearLayoutManager.VERTICAL);
- setCorrectedLayoutHeight(80, holder, context);
+ setCorrectedLayoutHeight(300, holder, layoutManager, context);
holder.vCategoryRv.setAdapter(new HistoryRecyclerAdapter(context));
}
holder.vTitle.setText(categories.get(position).getLabel());
holder.vCategoryRv.setLayoutManager(layoutManager);
}
@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());
+ }
+ holder.vCategoryRv.setLayoutParams(new LinearLayout.LayoutParams(
+ holder.vCategoryRv.getLayoutParams().width, (int) px));
+ }
+
+ private void setCorrectedLayoutOrientation(final LinearLayoutManager lm,
+ final int orientation) {
+ lm.setOrientation(orientation);
+ }
+
static class ViewHolder extends RecyclerView.ViewHolder {
TextView vTitle;
RecyclerView vCategoryRv;
ViewHolder(View itemView) {
super(itemView);
vTitle = (TextView) itemView.findViewById(R.id.category_title);
vCategoryRv = (RecyclerView) itemView.findViewById(R.id.recycler_category);
}
}
- private void setCorrectedLayoutHeight(int height, ViewHolder holder, Context context) {
- float px = TypedValue.applyDimension(
- TypedValue.COMPLEX_UNIT_DIP, height, context.getResources().getDisplayMetrics());
- holder.vCategoryRv.setLayoutParams(new LinearLayout.LayoutParams(
- holder.vCategoryRv.getLayoutParams().width, (int) px));
- }
+ static class Item {
+ String label;
+
+ Item(String label) {
+ setLabel(label);
+ }
- private void setCorrectedLayoutOrientation(LinearLayoutManager lm, int orientation) {
- lm.setOrientation(orientation);
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
}
}
\ No newline at end of file
--- a/mobile/android/base/resources/layout/activity_stream.xml
+++ b/mobile/android/base/resources/layout/activity_stream.xml
@@ -2,13 +2,15 @@
<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.support.v7.widget.RecyclerView
android:id="@+id/recycler_main"
- android:padding="12dp"
+ 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
@@ -2,17 +2,17 @@
<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_width="180dp"
- android:layout_height="200dp">
+ android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="vertical">
<FrameLayout
--- a/mobile/android/base/resources/layout/activity_stream_card_top_sites_item.xml
+++ b/mobile/android/base/resources/layout/activity_stream_card_top_sites_item.xml
@@ -2,27 +2,27 @@
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:orientation="vertical"
android:layout_width="90dp"
- android:layout_height="95dp">
+ android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<FrameLayout
android:layout_width="match_parent"
- android:background="@color/placeholder_grey"
+ android:background="@color/disabled_grey"
android:layout_height="70dp">
<ImageView
android:src="@drawable/favicon_globe"
android:scaleType="fitCenter"
android:layout_gravity="center"
android:layout_width="40dp"
android:layout_height="40dp"/>
--- a/mobile/android/base/resources/layout/activity_stream_category.xml
+++ b/mobile/android/base/resources/layout/activity_stream_category.xml
@@ -1,16 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
- android:layout_height="wrap_content">
+ android:layout_height="match_parent">
<RelativeLayout
android:orientation="horizontal"
+ android:layout_marginRight="12dp"
+ android:layout_marginEnd="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/category_title"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"