Bug 1251362 - Part 4 - Update empty panel state when recent tabs count changes draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 15 May 2016 01:41:45 +0200
changeset 369298 84ad30c847c5e6098af088d6282922458b3d3b37
parent 369297 02cbce575e979677a7c4c920e9312c6f710c4d7c
child 369299 88414e47c29ca5e30ae5a526be6ddf1da6972845
push id18831
push usermozilla@buttercookie.de
push dateSat, 21 May 2016 18:52:21 +0000
bugs1251362
milestone49.0a1
Bug 1251362 - Part 4 - Update empty panel state when recent tabs count changes MozReview-Commit-ID: GLHM9LoWk2h
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
@@ -74,16 +74,18 @@ public class CombinedHistoryPanel extend
     private CombinedHistoryAdapter mHistoryAdapter;
     private ClientsAdapter mClientsAdapter;
     private RecentTabsAdapter mRecentTabsAdapter;
     private CursorLoaderCallbacks mCursorLoaderCallbacks;
 
     private OnPanelLevelChangeListener.PanelLevel mPanelLevel;
     private Button mPanelFooterButton;
 
+    private PanelStateUpdateHandler panelStateUpdateHandler;
+
     // Child refresh layout view.
     protected SwipeRefreshLayout mRefreshLayout;
 
     // Sync listener that stops refreshing when a sync is completed.
     protected RemoteTabsSyncListener mSyncStatusListener;
 
     // Reference to the View to display when there are no results.
     private View mHistoryEmptyView;
@@ -104,17 +106,17 @@ 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());
+        mRecentTabsAdapter = new RecentTabsAdapter(getContext(), 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);
@@ -306,16 +308,33 @@ public class CombinedHistoryPanel extend
 
         @Override
         public void onLoaderReset(Loader<Cursor> loader) {
             mClientsAdapter.setClients(Collections.<RemoteClient>emptyList());
             mHistoryAdapter.setHistory(null);
         }
     }
 
+    public interface PanelStateUpdateHandler {
+        void onPanelStateUpdated();
+    }
+
+    public PanelStateUpdateHandler getPanelStateUpdateHandler() {
+        if (panelStateUpdateHandler == null) {
+            panelStateUpdateHandler = new PanelStateUpdateHandler() {
+                @Override
+                public void onPanelStateUpdated() {
+                    updateEmptyView();
+                    updateButtonFromLevel();
+                }
+            };
+        }
+        return panelStateUpdateHandler;
+    }
+
     protected class OnLevelChangeListener implements OnPanelLevelChangeListener {
         @Override
         public boolean changeLevel(PanelLevel level) {
             if (level == mPanelLevel) {
                 return false;
             }
 
             mPanelLevel = level;
--- 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.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;
 
@@ -53,19 +54,22 @@ 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 PanelStateUpdateHandler panelStateUpdateHandler;
 
-    public RecentTabsAdapter(Context context) {
+    public RecentTabsAdapter(Context context,
+                             PanelStateUpdateHandler panelStateUpdateHandler) {
         this.context = context;
+        this.panelStateUpdateHandler = panelStateUpdateHandler;
         mRecentlyClosedTabs = new ClosedTab[0];
         mLastSessionTabs = new ClosedTab[0];
 
         readPreviousSessionData();
     }
 
     public void startListeningForClosedTabs() {
         EventDispatcher.getInstance().registerGeckoThreadListener(this, "ClosedTabs:Data");
@@ -88,16 +92,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;
+                panelStateUpdateHandler.onPanelStateUpdated();
                 notifyDataSetChanged();
             }
         });
     }
 
     private void readPreviousSessionData() {
         // TODO: When uithread-patch has landed, wait for the session file to be updated before proceeding.
 
@@ -128,16 +133,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;
+                        panelStateUpdateHandler.onPanelStateUpdated();
                         notifyDataSetChanged();
                     }
                 });
             }
         });
     }
 
     @Override