Bug 1261527 - Add clear history button. r=sebastian, a=lizzard
authorChenxia Liu <liuche@mozilla.com>
Fri, 22 Apr 2016 18:00:03 -0700
changeset 332731 edc81c1262fa88d549ddf4b79223831a5c107ea6
parent 332730 fea137d66b0957d426b8f12d6cb5fd2b6075e311
child 332732 69886489143eaac2e9e9a5503b5f31fd313f761a
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, lizzard
bugs1261527
milestone48.0a2
Bug 1261527 - Add clear history button. r=sebastian, a=lizzard MozReview-Commit-ID: DnRZYtIjqbE
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
mobile/android/base/resources/layout/home_combined_history_panel.xml
mobile/android/base/resources/layout/home_history_clear_button.xml
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -187,36 +187,33 @@ public class CombinedHistoryPanel extend
                     Log.e(LOGTAG, "Unknown loader id!");
                     return null;
             }
         }
 
         @Override
         public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
             final int loaderId = loader.getId();
+            boolean showEmptyView = false;
             switch (loaderId) {
                 case LOADER_ID_HISTORY:
                     mHistoryAdapter.setHistory(c);
-                    if (mPanelLevel == OnPanelLevelChangeListener.PanelLevel.PARENT) {
-                        updateEmptyView(mHistoryAdapter.getItemCount() <= NUM_SMART_FOLDERS, OnPanelLevelChangeListener.PanelLevel.PARENT);
-                    }
+                    showEmptyView = mHistoryAdapter.getItemCount() == NUM_SMART_FOLDERS;
                     break;
 
                 case LOADER_ID_REMOTE:
                     final List<RemoteClient> clients = mDB.getTabsAccessor().getClientsFromCursor(c);
                     mHistoryAdapter.getDeviceUpdateHandler().onDeviceCountUpdated(clients.size());
                     mClientsAdapter.setClients(clients);
-                    if (mPanelLevel == OnPanelLevelChangeListener.PanelLevel.CHILD) {
-                        updateEmptyView(mClientsAdapter.getItemCount() <= 2, OnPanelLevelChangeListener.PanelLevel.CHILD);
-                    }
+                    showEmptyView = mClientsAdapter.getItemCount() == 1;
                     break;
             }
 
-            // TODO: Add "Clear all history" button.
-//            updateButtonFromLevel(mPanelLevel);
+            updateEmptyView(showEmptyView, mPanelLevel);
+            updateButtonFromLevel();
         }
 
         @Override
         public void onLoaderReset(Loader<Cursor> loader) {
             mClientsAdapter.setClients(Collections.<RemoteClient>emptyList());
             mHistoryAdapter.setHistory(null);
         }
     }
@@ -232,38 +229,34 @@ public class CombinedHistoryPanel extend
             switch (level) {
                 case PARENT:
                     mRecyclerView.swapAdapter(mHistoryAdapter, false);
                     break;
                 case CHILD:
                     mRecyclerView.swapAdapter(mClientsAdapter, false);
                     break;
             }
-            load();
+            updateButtonFromLevel();
             return true;
-           // updateButtonFromLevel(level);
         }
     }
 
-    private void updateButtonFromLevel(OnPanelLevelChangeListener.PanelLevel level) {
-        mPanelLevel = level;
-        switch (level) {
-            case CHILD:
-                mPanelFooterButton.setVisibility(View.VISIBLE);
-                mPanelFooterButton.setText(R.string.home_open_all);
-                break;
+    private void updateButtonFromLevel() {
+        switch (mPanelLevel) {
             case PARENT:
                 final boolean historyRestricted = !Restrictions.isAllowed(getActivity(), Restrictable.CLEAR_HISTORY);
                 if (historyRestricted || mHistoryAdapter.getItemCount() <= NUM_SMART_FOLDERS) {
                     mPanelFooterButton.setVisibility(View.GONE);
                 } else {
                     mPanelFooterButton.setVisibility(View.VISIBLE);
-                    mPanelFooterButton.setText(R.string.home_clear_history_button);
                 }
                 break;
+            case CHILD:
+                mPanelFooterButton.setVisibility(View.GONE);
+                break;
         }
     }
 
     private class OnFooterButtonClickListener implements View.OnClickListener {
         @Override
         public void onClick(View view) {
 
             final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
--- a/mobile/android/base/resources/layout/home_combined_history_panel.xml
+++ b/mobile/android/base/resources/layout/home_combined_history_panel.xml
@@ -19,11 +19,16 @@
               android:layout_height="match_parent"/>
 
     <org.mozilla.gecko.home.CombinedHistoryRecyclerView
             android:id="@+id/combined_recycler_view"
             android:layout_width="match_parent"
             android:layout_height="0dp"
             android:layout_weight="1"/>
 
-    <include layout="@layout/home_history_clear_button"/>
+    <Button android:id="@+id/clear_history_button"
+            style="@style/Widget.Home.ActionButton"
+            android:text="@string/home_clear_history_button"
+            android:layout_width="match_parent"
+            android:layout_height="48dp"
+            android:visibility="gone" />
 
 </LinearLayout>
deleted file mode 100644
--- a/mobile/android/base/resources/layout/home_history_clear_button.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<?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/. -->
-
-<Button xmlns:android="http://schemas.android.com/apk/res/android"
-        android:id="@+id/clear_history_button"
-        style="@style/Widget.Home.ActionButton"
-        android:text="@string/home_clear_history_button"
-        android:visibility="gone" />