Bug 850600 - Part 4: Add swipe to refresh to sync tab list. r=nalexander
☠☠ backed out by 62bedf537dfd ☠ ☠
authorJosh Dover <gerfuls@gmail.com>
Fri, 18 Apr 2014 14:04:00 -0700
changeset 198939 ce5ba3c8eb4745e540e71c6c707565f067e9ce65
parent 198938 3224b22c0f292d61020896475e140afaf8055128
child 198940 62bedf537dfd51b81f1c52cf2346201fb604a283
push id486
push userasasaki@mozilla.com
push dateMon, 14 Jul 2014 18:39:42 +0000
treeherdermozilla-release@d33428174ff1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs850600
milestone31.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 850600 - Part 4: Add swipe to refresh to sync tab list. r=nalexander
mobile/android/base/RemoteTabsContainer.java
mobile/android/base/resources/values/colors.xml
--- a/mobile/android/base/RemoteTabsContainer.java
+++ b/mobile/android/base/RemoteTabsContainer.java
@@ -1,59 +1,122 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
+import org.mozilla.gecko.fxa.FirefoxAccounts;
+import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
+import org.mozilla.gecko.util.ThreadUtils;
+import org.mozilla.gecko.widget.GeckoSwipeRefreshLayout;
+
+import android.accounts.Account;
 import android.content.Context;
 import android.util.AttributeSet;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.FrameLayout;
 
 /**
- * Serves as container to wrap the list of synced tabs and provide swipe-to-refresh support. The
+ * Provides a container to wrap the list of synced tabs and provide swipe-to-refresh support. The
  * only child view should be an instance of {@link RemoteTabsList}.
  */
-public class RemoteTabsContainer extends FrameLayout
+public class RemoteTabsContainer extends GeckoSwipeRefreshLayout
                                  implements TabsPanel.PanelView {
+    private static final String[] STAGES_TO_SYNC_ON_REFRESH = new String[] { "tabs" };
+
     private final Context context;
+    private final RemoteTabsSyncObserver syncListener;
     private RemoteTabsList list;
 
     public RemoteTabsContainer(Context context, AttributeSet attrs) {
         super(context, attrs);
         this.context = context;
+        this.syncListener = new RemoteTabsSyncObserver();
+
+        setOnRefreshListener(new RemoteTabsRefreshListener());
     }
 
     @Override
     public void addView(View child, int index, ViewGroup.LayoutParams params) {
         super.addView(child, index, params);
 
         list = (RemoteTabsList) child;
+
+        // Must be called after the child view has been added.
+        setColorScheme(R.color.swipe_refresh_orange_dark, R.color.background_tabs,
+                       R.color.swipe_refresh_orange_dark, R.color.background_tabs);
+    }
+
+
+    @Override
+    public boolean canChildScrollUp() {
+        // We are not supporting swipe-to-refresh for old sync. This disables the swipe gesture if
+        // no FxA are detected.
+        if (FirefoxAccounts.firefoxAccountsExist(getContext())) {
+            return super.canChildScrollUp();
+        } else {
+            return true;
+        }
     }
 
     @Override
     public ViewGroup getLayout() {
         return this;
     }
 
     @Override
     public void setTabsPanel(TabsPanel panel) {
         list.setTabsPanel(panel);
     }
 
     @Override
     public void show() {
         setVisibility(VISIBLE);
         TabsAccessor.getTabs(context, list);
+        FirefoxAccounts.addSyncStatusListener(syncListener);
     }
 
     @Override
     public void hide() {
         setVisibility(GONE);
+        FirefoxAccounts.removeSyncStatusListener(syncListener);
     }
 
     @Override
     public boolean shouldExpand() {
         return true;
     }
+
+    private class RemoteTabsRefreshListener implements OnRefreshListener {
+        @Override
+        public void onRefresh() {
+            if (FirefoxAccounts.firefoxAccountsExist(getContext())) {
+                final Account account = FirefoxAccounts.getFirefoxAccount(getContext());
+                FirefoxAccounts.requestSync(account, FirefoxAccounts.FORCE, STAGES_TO_SYNC_ON_REFRESH, null);
+            }
+        }
+    }
+
+    private class RemoteTabsSyncObserver implements FirefoxAccounts.SyncStatusListener {
+        @Override
+        public Context getContext() {
+            return RemoteTabsContainer.this.getContext();
+        }
+
+        @Override
+        public Account getAccount() {
+            return FirefoxAccounts.getFirefoxAccount(getContext());
+        }
+
+        public void onSyncFinished() {
+            ThreadUtils.postToUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    TabsAccessor.getTabs(context, list);
+                    setRefreshing(false);
+                }
+            });
+        }
+
+        public void onSyncStarted() {}
+    }
 }
--- a/mobile/android/base/resources/values/colors.xml
+++ b/mobile/android/base/resources/values/colors.xml
@@ -90,10 +90,10 @@
 
   <color name="home_last_tab_bar_bg">#FFF5F7F9</color>
 
   <color name="panel_image_item_background">#D1D9E1</color>
 
   <!-- Swipe to refresh colors -->
   <color name="swipe_refresh_orange">#FFFFC26C</color>
   <color name="swipe_refresh_white">#FFFFFFFF</color>
+  <color name="swipe_refresh_orange_dark">#FF9500</color>
 </resources>
-