Bug 1251362 - Part 8 - Directly notify the RecentTabsAdapter when clearing history, so the "tabs from last time" are removed immediately instead of having to wait for the next time the history panel is initialised. draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 14 May 2016 21:27:23 +0200
changeset 369302 256c58a53a11bc0a5a261dd90f72b96ac13c510e
parent 369301 50f88f712e303059b8229613e2d06401cc8067ff
child 369303 778cf9812bcc43468ddfaa4ef5abef081daf12bf
push id18831
push usermozilla@buttercookie.de
push dateSat, 21 May 2016 18:52:21 +0000
bugs1251362
milestone49.0a1
Bug 1251362 - Part 8 - Directly notify the RecentTabsAdapter when clearing history, so the "tabs from last time" are removed immediately instead of having to wait for the next time the history panel is initialised. MozReview-Commit-ID: 3EFY2WbWqzh
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -396,16 +396,17 @@ public class CombinedHistoryPanel extend
                     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());
+                    mRecentTabsAdapter.clearLastSessionData();
                     Telemetry.sendUIEvent(TelemetryContract.Event.SANITIZE, TelemetryContract.Method.BUTTON, "history");
                 }
             });
 
             dialogBuilder.show();
         }
     }
 
--- a/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
@@ -147,16 +147,31 @@ public class RecentTabsAdapter extends R
                         panelStateUpdateHandler.onPanelStateUpdated();
                         notifyDataSetChanged();
                     }
                 });
             }
         });
     }
 
+    public void clearLastSessionData() {
+        final ClosedTab[] lastSessionTabs = new ClosedTab[0];
+
+                // Only modify mLastSessionTabs on the UI thread.
+        ThreadUtils.postToUiThread(new Runnable() {
+            @Override
+            public void run() {
+                mLastSessionTabs = lastSessionTabs;
+                recentTabsUpdateHandler.onRecentTabsCountUpdated(mRecentlyClosedTabs.length + mLastSessionTabs.length);
+                panelStateUpdateHandler.onPanelStateUpdated();
+                notifyDataSetChanged();
+            }
+        });
+    }
+
     public void restoreTabFromPosition(int position) {
         final List<String> dataList = new ArrayList<>(1);
         dataList.add(getClosedTabForPosition(position).data);
         restoreSessionWithHistory(dataList);
     }
 
     public void restoreAllTabsFromPosition(int position) {
         final ClosedTab[] allClosedTabs;