Bug 1251362 - Part 9 - Display a button to open all recently closed tabs. r=liuche
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 26 May 2016 16:36:25 +0200
changeset 301162 8c7176aa08d7e4baa4f7848a2e0731d893f8d66c
parent 301161 1e50a28316e7321897b9c4545049eba887192592
child 301163 ab0c1b005ffe6f628e1d4170e19ff02fa255ba1a
push id78241
push userkwierso@gmail.com
push dateThu, 09 Jun 2016 00:09:10 +0000
treeherdermozilla-inbound@2c66b75bbb7f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs1251362
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1251362 - Part 9 - Display a button to open all recently closed tabs. r=liuche Depending on the History panel's PanelLevel state, we now dynamically set the panel footer button's text and determine its onClick behaviour. MozReview-Commit-ID: EjesnHsntyC
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/resources/layout/home_combined_history_panel.xml
mobile/android/base/strings.xml.in
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -137,17 +137,18 @@ public class CombinedHistoryPanel extend
         mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
         setUpRefreshLayout();
 
         mClientsEmptyView = view.findViewById(R.id.home_clients_empty_view);
         mHistoryEmptyView = view.findViewById(R.id.home_history_empty_view);
         mRecentTabsEmptyView = view.findViewById(R.id.home_recent_tabs_empty_view);
         setUpEmptyViews();
 
-        mPanelFooterButton = (Button) view.findViewById(R.id.clear_history_button);
+        mPanelFooterButton = (Button) view.findViewById(R.id.history_panel_footer_button);
+        mPanelFooterButton.setText(R.string.home_clear_history_button);
         mPanelFooterButton.setOnClickListener(new OnFooterButtonClickListener());
 
         mRecentTabsAdapter.startListeningForClosedTabs();
     }
 
     private void setUpRecyclerView() {
         if (mPanelLevel == null) {
             mPanelLevel = PanelLevel.PARENT;
@@ -363,58 +364,72 @@ public class CombinedHistoryPanel extend
 
     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.setText(R.string.home_clear_history_button);
                     mPanelFooterButton.setVisibility(View.VISIBLE);
                 }
                 break;
+            case CHILD_RECENT_TABS:
+                if (mRecentTabsAdapter.getClosedTabsCount() > 1) {
+                    mPanelFooterButton.setText(R.string.home_restore_all);
+                    mPanelFooterButton.setVisibility(View.VISIBLE);
+                } else {
+                    mPanelFooterButton.setVisibility(View.GONE);
+                }
+                break;
             case CHILD_SYNC:
-            case CHILD_RECENT_TABS:
                 mPanelFooterButton.setVisibility(View.GONE);
                 break;
         }
     }
 
     private class OnFooterButtonClickListener implements View.OnClickListener {
         @Override
         public void onClick(View view) {
+            switch (mPanelLevel) {
+                case PARENT:
+                    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
+                    dialogBuilder.setMessage(R.string.home_clear_history_confirm);
+                    dialogBuilder.setNegativeButton(R.string.button_cancel, new AlertDialog.OnClickListener() {
+                        @Override
+                        public void onClick(final DialogInterface dialog, final int which) {
+                            dialog.dismiss();
+                        }
+                    });
 
-            final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
-            dialogBuilder.setMessage(R.string.home_clear_history_confirm);
-            dialogBuilder.setNegativeButton(R.string.button_cancel, new AlertDialog.OnClickListener() {
-                @Override
-                public void onClick(final DialogInterface dialog, final int which) {
-                    dialog.dismiss();
-                }
-            });
-
-            dialogBuilder.setPositiveButton(R.string.button_ok, new AlertDialog.OnClickListener() {
-                @Override
-                public void onClick(final DialogInterface dialog, final int which) {
-                    dialog.dismiss();
+                    dialogBuilder.setPositiveButton(R.string.button_ok, new AlertDialog.OnClickListener() {
+                        @Override
+                        public void onClick(final DialogInterface dialog, final int which) {
+                            dialog.dismiss();
 
-                    // Send message to Java to clear history.
-                    final JSONObject json = new JSONObject();
-                    try {
-                        json.put("history", true);
-                    } catch (JSONException e) {
-                        Log.e(LOGTAG, "JSON error", e);
-                    }
+                            // Send message to Java to clear history.
+                            final JSONObject json = new JSONObject();
+                            try {
+                                json.put("history", true);
+                            } catch (JSONException e) {
+                                Log.e(LOGTAG, "JSON error", e);
+                            }
 
-                    GeckoAppShell.notifyObservers("Sanitize:ClearData", json.toString());
-                    Telemetry.sendUIEvent(TelemetryContract.Event.SANITIZE, TelemetryContract.Method.BUTTON, "history");
-                }
-            });
+                            GeckoAppShell.notifyObservers("Sanitize:ClearData", json.toString());
+                            Telemetry.sendUIEvent(TelemetryContract.Event.SANITIZE, TelemetryContract.Method.BUTTON, "history");
+                        }
+                    });
 
-            dialogBuilder.show();
+                    dialogBuilder.show();
+                    break;
+                case CHILD_RECENT_TABS:
+                    mRecentTabsAdapter.restoreAllTabs();
+                    break;
+            }
         }
     }
 
     private void updateEmptyView() {
         boolean showEmptyHistoryView = false;
         boolean showEmptyClientsView = false;
         boolean showEmptyRecentTabsView = false;
         switch (mPanelLevel) {
--- a/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
@@ -206,16 +206,34 @@ public class RecentTabsAdapter extends R
     }
 
     public void restoreTabFromPosition(int position) {
         final List<String> dataList = new ArrayList<>(1);
         dataList.add(getClosedTabForPosition(position).data);
         restoreSessionWithHistory(dataList);
     }
 
+    public void restoreAllTabs() {
+        if (recentlyClosedTabs.length == 0 && lastSessionTabs.length == 0) {
+            return;
+        }
+
+        final List<String> dataList = new ArrayList<>(getClosedTabsCount());
+        addTabDataToList(dataList, recentlyClosedTabs);
+        addTabDataToList(dataList, lastSessionTabs);
+
+        restoreSessionWithHistory(dataList);
+    }
+
+    private void addTabDataToList(List<String> dataList, ClosedTab[] closedTabs) {
+        for (ClosedTab closedTab : closedTabs) {
+            dataList.add(closedTab.data);
+        }
+    }
+
     private static void restoreSessionWithHistory(List<String> dataList) {
         final JSONObject json = new JSONObject();
         try {
             json.put("tabs", new JSONArray(dataList));
         } catch (JSONException e) {
             Log.e(LOGTAG, "JSON error", e);
         }
 
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -570,16 +570,17 @@ size. -->
 <!ENTITY home_clear_history_button "Clear browsing history">
 <!ENTITY home_clear_history_confirm "Are you sure you want to clear your history?">
 <!ENTITY home_bookmarks_empty "Bookmarks you save show up here.">
 <!ENTITY home_closed_tabs_title "Recently closed tabs">
 <!ENTITY home_closed_tabs_title2 "Recently closed">
 <!ENTITY home_last_tabs_title "Tabs from last time">
 <!ENTITY home_last_tabs_empty "Your recent tabs show up here.">
 <!ENTITY home_open_all "Open all">
+<!ENTITY home_restore_all "Restore all">
 <!ENTITY home_closed_tabs_number "&formatD; tabs">
 <!-- Localization note (home_closed_tabs_one): This is the singular version of home_closed_tabs_number, referring to the number of recently closed tabs available. -->
 <!ENTITY home_closed_tabs_one "1 tab">
 <!ENTITY home_most_recent_empty "Websites you visited most recently show up here.">
 <!-- Localization note (home_most_recent_emptyhint2): "Psst" is a sound that might be used to attract someone's attention unobtrusively, and intended to hint at Private Browsing to the user.
      The placeholders &formatS1; and &formatS2; are used to mark the location of text underlining. -->
 <!ENTITY home_most_recent_emptyhint2 "Psst: using a &formatS1;New Private Tab&formatS2; won\'t save your history.">
 
--- a/mobile/android/base/resources/layout/home_combined_history_panel.xml
+++ b/mobile/android/base/resources/layout/home_combined_history_panel.xml
@@ -38,16 +38,15 @@
 
     <include android:id="@+id/home_recent_tabs_empty_view"
               layout="@layout/home_empty_panel"
               android:layout_width="match_parent"
               android:layout_height="0dp"
               android:layout_weight="3"
               android:visibility="gone"/>
 
-    <Button android:id="@+id/clear_history_button"
+    <Button android:id="@+id/history_panel_footer_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>
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -452,16 +452,17 @@
   <string name="home_clear_history_button">&home_clear_history_button;</string>
   <string name="home_clear_history_confirm">&home_clear_history_confirm;</string>
   <string name="home_bookmarks_empty">&home_bookmarks_empty;</string>
   <string name="home_closed_tabs_title">&home_closed_tabs_title;</string>
   <string name="home_closed_tabs_title2">&home_closed_tabs_title2;</string>
   <string name="home_last_tabs_title">&home_last_tabs_title;</string>
   <string name="home_last_tabs_empty">&home_last_tabs_empty;</string>
   <string name="home_open_all">&home_open_all;</string>
+  <string name="home_restore_all">&home_restore_all;</string>
   <string name="home_closed_tabs_number">&home_closed_tabs_number;</string>
   <string name="home_closed_tabs_one">&home_closed_tabs_one;</string>
   <string name="home_most_recent_empty">&home_most_recent_empty;</string>
   <string name="home_most_recent_emptyhint">&home_most_recent_emptyhint2;</string>
   <string name="home_default_empty">&home_default_empty;</string>
   <string name="home_move_back_to_filter">&home_move_back_to_filter;</string>
   <string name="home_remote_tabs_many_hidden_devices">&home_remote_tabs_many_hidden_devices;</string>
   <string name="home_remote_tabs_hidden_devices_title">&home_remote_tabs_hidden_devices_title;</string>