Bug 1251362 - Part 11 - Directly notify the RecentTabsAdapter when clearing history. r=liuche draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 14 May 2016 21:27:23 +0200
changeset 376079 c13f797a595a81465ef998fedcb03f0dd3187b74
parent 376078 4e8c2219cd7f9ecce454be55014429485aa60ad5
child 376080 1e2005f8d6b8774e333c0e0ce21e2a838f61f410
push id20500
push usermozilla@buttercookie.de
push dateTue, 07 Jun 2016 11:41:20 +0000
reviewersliuche
bugs1251362
milestone50.0a1
Bug 1251362 - Part 11 - Directly notify the RecentTabsAdapter when clearing history. r=liuche Sessionstore.bak is only read when we are initialising the home panels, so after clearing all history from the button in the Combined History panel, the "Tabs from last time" section would still linger around until the home panels have been closed and reopened. To prevent this, we now directly notify the RecentTabsAdapter when all history has been deleted, so it can immediately clear its own copy of the last session's tabs. 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
@@ -410,16 +410,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();
                     break;
                 case CHILD_RECENT_TABS:
                     mRecentTabsAdapter.restoreAllTabs();
--- a/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
@@ -169,16 +169,44 @@ public class RecentTabsAdapter extends R
                         // Update the "Tabs from last time" part of the tab list.
                         updateTabsList(prevClosedTabsCount, lastSessionTabs.length, getFirstLastSessionTabIndex(), getLastLastSessionTabIndex());
                     }
                 });
             }
         });
     }
 
+    public void clearLastSessionData() {
+        final ClosedTab[] emptyLastSessionTabs = new ClosedTab[0];
+
+        // Only modify mLastSessionTabs on the UI thread.
+        ThreadUtils.postToUiThread(new Runnable() {
+            @Override
+            public void run() {
+                // Save some data about the old panel state, so we can be
+                // smarter about notifying the recycler view which bits changed.
+                int prevClosedTabsCount = lastSessionTabs.length;
+                boolean prevSectionHeaderVisibility = isSectionHeaderVisible();
+                int prevSectionHeaderIndex = getSectionHeaderIndex();
+
+                lastSessionTabs = emptyLastSessionTabs;
+                recentTabsUpdateHandler.onRecentTabsCountUpdated(getClosedTabsCount());
+                panelStateUpdateHandler.onPanelStateUpdated();
+
+                // Handle the section header hiding.
+                updateHeaderVisibility(prevSectionHeaderVisibility, prevSectionHeaderIndex);
+
+                // Handle the "tabs from last time" being cleared.
+                if (prevClosedTabsCount > 0) {
+                    notifyItemRangeRemoved(getFirstLastSessionTabIndex(), prevClosedTabsCount);
+                }
+            }
+        });
+    }
+
     private void updateHeaderVisibility(boolean prevSectionHeaderVisibility, int prevSectionHeaderIndex) {
         if (prevSectionHeaderVisibility && !isSectionHeaderVisible()) {
             notifyItemRemoved(prevSectionHeaderIndex);
         } else if (!prevSectionHeaderVisibility && isSectionHeaderVisible()) {
             notifyItemInserted(getSectionHeaderIndex());
         }
     }