Bug 1289242 - Override CombinedHistoryPanel styling for use in AS r?sebastian draft
authorAndrzej Hunt <ahunt@mozilla.com>
Mon, 01 Aug 2016 08:49:48 -0700
changeset 399220 003f241995dacb66aa20de8ac1c996da224702d5
parent 399219 08937b69d747b7da0592ec7115f5bfc3667dd577
child 399221 154b12b90e68d57a1b70edc570ea62a378bb9ffb
push id25764
push userahunt@mozilla.com
push dateWed, 10 Aug 2016 17:18:33 +0000
reviewerssebastian
bugs1289242
milestone51.0a1
Bug 1289242 - Override CombinedHistoryPanel styling for use in AS r?sebastian MozReview-Commit-ID: 52406VMEa1T
mobile/android/base/java/org/mozilla/gecko/home/activitystream/ASCombinedHistoryAdapter.java
mobile/android/base/java/org/mozilla/gecko/home/activitystream/ASCombinedHistoryPanel.java
mobile/android/base/moz.build
mobile/android/base/resources/layout/as_home_header_row.xml
mobile/android/base/resources/layout/as_home_item_row.xml
mobile/android/base/resources/layout/as_home_smartfolder.xml
mobile/android/base/resources/values/styles.xml
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ASCombinedHistoryAdapter.java
@@ -0,0 +1,54 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * 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.home.activitystream;
+
+import android.content.res.Resources;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import org.mozilla.gecko.R;
+import org.mozilla.gecko.home.CombinedHistoryAdapter;
+import org.mozilla.gecko.home.CombinedHistoryItem;
+
+/**
+ * AS version of the CombinedHistoryAdapter, which uses different styling for the history/bookmarks
+ * panels.
+ *
+ * The simplest way to get differents styling seems to be by inflating separate layouts with different
+ * styles, so we only need to override the inflation methods.
+ */
+public class ASCombinedHistoryAdapter extends CombinedHistoryAdapter {
+    public ASCombinedHistoryAdapter(Resources resources,
+                                    boolean disableSmartfolders) {
+        super(resources, disableSmartfolders);
+    }
+
+    @Override
+    public CombinedHistoryItem onCreateViewHolder(ViewGroup viewGroup, int viewType) {
+        final LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
+        final View view;
+
+        final CombinedHistoryItem.ItemType itemType = CombinedHistoryItem.ItemType.viewTypeToItemType(viewType);
+
+        switch (itemType) {
+            case RECENT_TABS:
+            case SYNCED_DEVICES:
+                view = inflater.inflate(R.layout.as_home_smartfolder, viewGroup, false);
+                return new CombinedHistoryItem.SmartFolder(view);
+
+            case SECTION_HEADER:
+                view = inflater.inflate(R.layout.as_home_header_row, viewGroup, false);
+                return new CombinedHistoryItem.BasicItem(view);
+
+            case HISTORY:
+                view = inflater.inflate(R.layout.as_home_item_row, viewGroup, false);
+                return new CombinedHistoryItem.BookmarkHistoryItem(view);
+
+            default:
+                throw new IllegalArgumentException("Unexpected Home Panel item type");
+        }
+    }
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ASCombinedHistoryPanel.java
@@ -0,0 +1,18 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * 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.home.activitystream;
+
+import android.content.res.Resources;
+
+import org.mozilla.gecko.home.CombinedHistoryAdapter;
+import org.mozilla.gecko.home.CombinedHistoryPanel;
+
+public class ASCombinedHistoryPanel extends CombinedHistoryPanel {
+
+    @Override
+    protected CombinedHistoryAdapter createAdapter(Resources resources, boolean bookmarksMode) {
+        return new ASCombinedHistoryAdapter(resources, bookmarksMode);
+    }
+}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -434,16 +434,18 @@ gbjar.sources += ['java/org/mozilla/geck
     'GeckoProfilesProvider.java',
     'GeckoUpdateReceiver.java',
     'GlobalHistory.java',
     'GuestSession.java',
     'health/HealthRecorder.java',
     'health/SessionInformation.java',
     'health/StubbedHealthRecorder.java',
     'home/activitystream/ActivityStream.java',
+    'home/activitystream/ASCombinedHistoryAdapter.java',
+    'home/activitystream/ASCombinedHistoryPanel.java',
     'home/activitystream/ASDetailActivity.java',
     'home/activitystream/ASOpenURLDelegate.java',
     'home/BookmarkFolderView.java',
     'home/BookmarkScreenshotRow.java',
     'home/BookmarksListAdapter.java',
     'home/BookmarksListView.java',
     'home/BookmarksPanel.java',
     'home/BrowserSearch.java',
copy from mobile/android/base/resources/layout/home_header_row.xml
copy to mobile/android/base/resources/layout/as_home_header_row.xml
--- a/mobile/android/base/resources/layout/home_header_row.xml
+++ b/mobile/android/base/resources/layout/as_home_header_row.xml
@@ -1,7 +1,8 @@
 <?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"
-          style="@style/Widget.Home.HeaderItem"/>
+          style="@style/Widget.Home.HeaderItem.AS"/>
+
copy from mobile/android/base/resources/layout/home_item_row.xml
copy to mobile/android/base/resources/layout/as_home_item_row.xml
--- a/mobile/android/base/resources/layout/home_item_row.xml
+++ b/mobile/android/base/resources/layout/as_home_item_row.xml
@@ -1,10 +1,10 @@
 <?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/. -->
 
 <org.mozilla.gecko.home.TwoLinePageRow xmlns:android="http://schemas.android.com/apk/res/android"
-                                       style="@style/Widget.TwoLinePageRow"
                                        android:layout_width="match_parent"
                                        android:layout_height="@dimen/page_row_height"
+                                       style="@style/Widget.TwoLinePageRow.AS"
                                        android:minHeight="@dimen/page_row_height"/>
copy from mobile/android/base/resources/layout/home_smartfolder.xml
copy to mobile/android/base/resources/layout/as_home_smartfolder.xml
--- a/mobile/android/base/resources/layout/home_smartfolder.xml
+++ b/mobile/android/base/resources/layout/as_home_smartfolder.xml
@@ -3,17 +3,17 @@
    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/.
 -->
 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     xmlns:gecko="http://schemas.android.com/apk/res-auto"
-    style="@style/Widget.RemoteTabsClientView"
+    style="@style/Widget.RemoteTabsClientView.AS"
     android:gravity="center_vertical"
     android:layout_width="match_parent"
     android:layout_height="@dimen/home_header_item_height"
     android:minHeight="@dimen/home_header_item_height">
 
     <ImageView
         android:id="@+id/device_type"
         android:layout_width="26dp"
--- a/mobile/android/base/resources/values/styles.xml
+++ b/mobile/android/base/resources/values/styles.xml
@@ -126,16 +126,20 @@
     <style name="Widget.FolderTitle.TwoLine">
         <item name="android:textSize">@dimen/home_folder_title_twoline_textsize</item>
     </style>
 
     <style name="Widget.TwoLinePageRow" >
         <item name="android:background">@color/pressed_about_page_header_grey</item>
     </style>
 
+    <style name="Widget.TwoLinePageRow.AS" >
+        <item name="android:background">#FFFFFF</item>
+    </style>
+
     <style name="Widget.TwoLinePageRow.Title">
         <item name="android:textAppearance">@style/TextAppearance.Widget.Home.ItemTitle</item>
         <item name="android:textSize">@dimen/home_twolinepagerow_title_textsize</item>
     </style>
 
     <style name="Widget.TwoLinePageRow.Url">
         <item name="android:textAppearance">@style/TextAppearance.Widget.Home.ItemDescription</item>
         <item name="android:includeFontPadding">false</item>
@@ -236,16 +240,21 @@
         <item name="android:gravity">center|left</item>
         <item name="android:paddingLeft">16dp</item>
         <item name="android:paddingRight">16dp</item>
         <item name="android:paddingTop">11dp</item>
         <item name="android:paddingBottom">11dp</item>
         <item name="android:includeFontPadding">false</item>
     </style>
 
+    <style name="Widget.Home.HeaderItem.AS">
+        <item name="android:background">#ECECEC</item>
+        <item name="android:textAppearance">@style/TextAppearance.Widget.Home.Header.AS</item>
+    </style>
+
     <style name="Widget.Home.ActionButton">
         <item name="android:layout_width">match_parent</item>
         <item name="android:layout_height">48dp</item>
         <item name="android:textColor">@color/text_and_tabs_tray_grey</item>
         <item name="android:textSize">14sp</item>
         <item name="android:background">@drawable/home_history_clear_button_bg</item>
         <item name="android:focusable">true</item>
         <item name="android:gravity">center</item>
@@ -386,16 +395,20 @@
 
     <style name="TextAppearance.Widget.Home" />
 
     <style name="TextAppearance.Widget.Home.Header" parent="TextAppearance.Small">
         <item name="android:textColor">@color/disabled_grey</item>
         <item name="android:textSize">12sp</item>
     </style>
 
+    <style name="TextAppearance.Widget.Home.Header.AS" parent="TextAppearance.Small">
+        <item name="android:textColor">@android:color/black</item>
+    </style>
+
     <style name="TextAppearance.Widget.Home.ItemTitle" parent="TextAppearance">
         <item name="android:textSize">16dp</item>
     </style>
 
     <style name="TextAppearance.Widget.Home.ItemDescription" parent="TextAppearance.Micro">
         <item name="android:textColor">@color/tabs_tray_icon_grey</item>
     </style>
 
@@ -532,16 +545,18 @@
     </style>
 
     <style name="Widget.RemoteTabsItemView" parent="Widget.TwoLinePageRow"/>
 
     <style name="Widget.RemoteTabsClientView" parent="Widget.TwoLinePageRow">
         <item name="android:background">@color/about_page_header_grey</item>
     </style>
 
+    <style name="Widget.RemoteTabsClientView.AS" parent="Widget.TwoLinePageRow.AS"/>
+
     <style name="Widget.RemoteTabsListView" parent="Widget.HomeListView">
         <item name="android:childDivider">@color/toolbar_divider_grey</item>
     </style>
 
     <style name="Widget.HistoryListView" parent="Widget.HomeListView">
         <item name="android:childDivider">@color/toolbar_divider_grey</item>
         <item name="android:drawSelectorOnTop">true</item>
     </style>