Bug 1251362 - Part 5 - Update closed tabs count in overview draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 14 May 2016 20:35:07 +0200
changeset 369299 88414e47c29ca5e30ae5a526be6ddf1da6972845
parent 369298 84ad30c847c5e6098af088d6282922458b3d3b37
child 369300 a4e7e03d4d5d176ac3c9802a89bebd6ab562123c
push id18831
push usermozilla@buttercookie.de
push dateSat, 21 May 2016 18:52:21 +0000
bugs1251362
milestone49.0a1
Bug 1251362 - Part 5 - Update closed tabs count in overview MozReview-Commit-ID: BFwv5bY1DWk
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
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/CombinedHistoryAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
@@ -35,16 +35,17 @@ public class CombinedHistoryAdapter exte
         FOUR_MONTHS_AGO,
         FIVE_MONTHS_AGO,
         OLDER_THAN_SIX_MONTHS
     }
 
     private Cursor historyCursor;
     private DevicesUpdateHandler devicesUpdateHandler;
     private int deviceCount = 0;
+    private RecentTabsUpdateHandler recentTabsUpdateHandler;
     private int recentTabsCount = 0;
 
     // We use a sparse array to store each section header's position in the panel [more cheaply than a HashMap].
     private final SparseArray<SectionHeader> sectionHeaders;
 
     public CombinedHistoryAdapter(Resources resources) {
         super();
         sectionHeaders = new SparseArray<>();
@@ -69,16 +70,33 @@ public class CombinedHistoryAdapter exte
                     deviceCount = count;
                     notifyItemChanged(SYNCED_DEVICES_SMARTFOLDER_INDEX);
                 }
             };
         }
         return devicesUpdateHandler;
     }
 
+    public interface RecentTabsUpdateHandler {
+        void onRecentTabsCountUpdated(int count);
+    }
+
+    public RecentTabsUpdateHandler getRecentTabsUpdateHandler() {
+        if (recentTabsUpdateHandler == null) {
+            recentTabsUpdateHandler = new RecentTabsUpdateHandler() {
+                @Override
+                public void onRecentTabsCountUpdated(int count) {
+                    recentTabsCount = count;
+                    notifyItemChanged(RECENT_TABS_SMARTFOLDER_INDEX);
+                }
+            };
+        }
+        return recentTabsUpdateHandler;
+    }
+
     @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) {
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -106,17 +106,18 @@ public class CombinedHistoryPanel extend
     }
 
     @Override
     public void onCreate(Bundle savedInstance) {
         super.onCreate(savedInstance);
 
         mHistoryAdapter = new CombinedHistoryAdapter(getResources());
         mClientsAdapter = new ClientsAdapter(getContext());
-        mRecentTabsAdapter = new RecentTabsAdapter(getContext(), getPanelStateUpdateHandler());
+        mRecentTabsAdapter = new RecentTabsAdapter(getContext(),
+                mHistoryAdapter.getRecentTabsUpdateHandler(), getPanelStateUpdateHandler());
 
         mSyncStatusListener = new RemoteTabsSyncListener();
         FirefoxAccounts.addSyncStatusListener(mSyncStatusListener);
     }
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         return inflater.inflate(R.layout.home_combined_history_panel, container, false);
--- a/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
@@ -17,16 +17,17 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.AboutPages;
 import org.mozilla.gecko.EventDispatcher;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.SessionParser;
+import org.mozilla.gecko.home.CombinedHistoryAdapter.RecentTabsUpdateHandler;
 import org.mozilla.gecko.home.CombinedHistoryPanel.PanelStateUpdateHandler;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.NativeEventListener;
 import org.mozilla.gecko.util.NativeJSObject;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -54,21 +55,24 @@ public class RecentTabsAdapter extends R
         public ClosedTab(String url, String title, String data) {
             this.url = url;
             this.title = title;
             this.data = data;
         }
     }
 
     private final Context context;
+    private final RecentTabsUpdateHandler recentTabsUpdateHandler;
     private final PanelStateUpdateHandler panelStateUpdateHandler;
 
     public RecentTabsAdapter(Context context,
+                             RecentTabsUpdateHandler recentTabsUpdateHandler,
                              PanelStateUpdateHandler panelStateUpdateHandler) {
         this.context = context;
+        this.recentTabsUpdateHandler = recentTabsUpdateHandler;
         this.panelStateUpdateHandler = panelStateUpdateHandler;
         mRecentlyClosedTabs = new ClosedTab[0];
         mLastSessionTabs = new ClosedTab[0];
 
         readPreviousSessionData();
     }
 
     public void startListeningForClosedTabs() {
@@ -92,16 +96,17 @@ public class RecentTabsAdapter extends R
             closedTabs[i] = new ClosedTab(tab.getString("url"), tab.getString("title"), tab.getObject("data").toString());
         }
 
         // Only modify mRecentlyClosedTabs on the UI thread.
         ThreadUtils.postToUiThread(new Runnable() {
             @Override
             public void run() {
                 mRecentlyClosedTabs = closedTabs;
+                recentTabsUpdateHandler.onRecentTabsCountUpdated(mRecentlyClosedTabs.length + mLastSessionTabs.length);
                 panelStateUpdateHandler.onPanelStateUpdated();
                 notifyDataSetChanged();
             }
         });
     }
 
     private void readPreviousSessionData() {
         // TODO: When uithread-patch has landed, wait for the session file to be updated before proceeding.
@@ -133,16 +138,17 @@ public class RecentTabsAdapter extends R
 
                 final ClosedTab[] lastSessionTabs = parsedTabs.toArray(new ClosedTab[parsedTabs.size()]);
 
                 // 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();
                     }
                 });
             }
         });
     }