Bug 850600: Part 2: Split RemoteTabs into container and list. r=margaret
☠☠ backed out by 62bedf537dfd ☠ ☠
authorJosh Dover <gerfuls@gmail.com>
Mon, 14 Apr 2014 14:55:00 -0700
changeset 197872 3224b22c0f292d61020896475e140afaf8055128
parent 197871 1e27e759fa2c34128a1fc75e1d2f3d4e3bcd215b
child 197873 ce5ba3c8eb4745e540e71c6c707565f067e9ce65
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
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 2: Split RemoteTabs into container and list. r=margaret
mobile/android/base/RemoteTabs.java
mobile/android/base/RemoteTabsContainer.java
mobile/android/base/RemoteTabsList.java
mobile/android/base/TabsPanel.java
mobile/android/base/moz.build
mobile/android/base/resources/layout/tabs_panel.xml
deleted file mode 100644
--- a/mobile/android/base/RemoteTabs.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/* 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 android.content.Context;
-import android.text.TextUtils;
-import android.util.AttributeSet;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ExpandableListView;
-import android.widget.SimpleExpandableListAdapter;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-public class RemoteTabs extends ExpandableListView
-                        implements TabsPanel.PanelView,
-                                   ExpandableListView.OnGroupClickListener,
-                                   ExpandableListView.OnChildClickListener, 
-                                   TabsAccessor.OnQueryTabsCompleteListener {
-    private static final String LOGTAG = "GeckoRemoteTabs";
-
-    private Context mContext;
-    private TabsPanel mTabsPanel;
-
-    private static ArrayList <ArrayList <HashMap <String, String>>> mTabsList;
-
-    private static final String[] CLIENT_KEY = new String[] { "name" };
-    private static final String[] TAB_KEY = new String[] { "title", "url" };
-    private static final int[] CLIENT_RESOURCE = new int[] { R.id.client };
-    private static final int[] TAB_RESOURCE = new int[] { R.id.tab, R.id.url };
-
-    public RemoteTabs(Context context, AttributeSet attrs) {
-        super(context, attrs);
-        mContext = context;
-
-        setOnGroupClickListener(this);
-        setOnChildClickListener(this);
-    }
-
-    @Override
-    public ViewGroup getLayout() {
-        return this;
-    }
-
-    @Override
-    public void setTabsPanel(TabsPanel panel) {
-        mTabsPanel = panel;
-    }
-
-    @Override
-    public void show() {
-        setVisibility(View.VISIBLE);
-        TabsAccessor.getTabs(mContext, this);
-    }
-
-    @Override
-    public void hide() {
-        setVisibility(View.GONE);
-    }
-
-    private void autoHidePanel() {
-        mTabsPanel.autoHidePanel();
-    }
-
-    @Override
-    public boolean shouldExpand() {
-        return true;
-    }
-
-    @Override
-    public boolean onGroupClick(ExpandableListView parent, View view, int position, long id) {
-        // By default, the group collapses/expands. Consume the event.
-        return true;
-    }
-
-    @Override
-    public boolean onChildClick(ExpandableListView parent, View view, int groupPosition, int childPosition, long id) {
-        HashMap <String, String> tab = mTabsList.get(groupPosition).get(childPosition);
-        if (tab == null) {
-            autoHidePanel();
-            return true;
-        }
-
-        Tabs.getInstance().loadUrl(tab.get("url"), Tabs.LOADURL_NEW_TAB);
-        autoHidePanel();
-        return true;
-    }
-
-    @Override
-    public void onQueryTabsComplete(List<TabsAccessor.RemoteTab> remoteTabsList) {
-        ArrayList<TabsAccessor.RemoteTab> remoteTabs = new ArrayList<TabsAccessor.RemoteTab> (remoteTabsList);
-        if (remoteTabs == null || remoteTabs.size() == 0)
-            return;
-        
-        ArrayList <HashMap <String, String>> clients = new ArrayList <HashMap <String, String>>();
-
-        mTabsList = new ArrayList <ArrayList <HashMap <String, String>>>();
-
-        String oldGuid = null;
-        ArrayList <HashMap <String, String>> tabsForClient = null;
-        HashMap <String, String> client;
-        HashMap <String, String> tab;
-        
-        for (TabsAccessor.RemoteTab remoteTab : remoteTabs) {
-            if (oldGuid == null || !TextUtils.equals(oldGuid, remoteTab.guid)) {
-                client = new HashMap <String, String>();
-                client.put("name", remoteTab.name);
-                clients.add(client);
-        
-                tabsForClient = new ArrayList <HashMap <String, String>>();
-                mTabsList.add(tabsForClient);
-        
-                oldGuid = new String(remoteTab.guid);
-            }
-        
-            tab = new HashMap<String, String>();
-            tab.put("title", TextUtils.isEmpty(remoteTab.title) ? remoteTab.url : remoteTab.title);
-            tab.put("url", remoteTab.url);
-            tabsForClient.add(tab);
-        }
-        
-        setAdapter(new SimpleExpandableListAdapter(mContext,
-                                                   clients,
-                                                   R.layout.remote_tabs_group,
-                                                   CLIENT_KEY,
-                                                   CLIENT_RESOURCE,
-                                                   mTabsList,
-                                                   R.layout.remote_tabs_child,
-                                                   TAB_KEY,
-                                                   TAB_RESOURCE));
-        
-        for (int i = 0; i < clients.size(); i++) {
-            expandGroup(i);
-        }
-    }
-}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/RemoteTabsContainer.java
@@ -0,0 +1,59 @@
+/* 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 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
+ * only child view should be an instance of {@link RemoteTabsList}.
+ */
+public class RemoteTabsContainer extends FrameLayout
+                                 implements TabsPanel.PanelView {
+    private final Context context;
+    private RemoteTabsList list;
+
+    public RemoteTabsContainer(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        this.context = context;
+    }
+
+    @Override
+    public void addView(View child, int index, ViewGroup.LayoutParams params) {
+        super.addView(child, index, params);
+
+        list = (RemoteTabsList) child;
+    }
+
+    @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);
+    }
+
+    @Override
+    public void hide() {
+        setVisibility(GONE);
+    }
+
+    @Override
+    public boolean shouldExpand() {
+        return true;
+    }
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/RemoteTabsList.java
@@ -0,0 +1,119 @@
+/* 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 android.content.Context;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ExpandableListView;
+import android.widget.SimpleExpandableListAdapter;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * The actual list of synced tabs. This serves as the only child view of {@link RemoteTabsContainer}
+ * so it can be refreshed using a swipe-to-refresh gesture.
+ */
+class RemoteTabsList extends ExpandableListView
+                            implements ExpandableListView.OnGroupClickListener,
+                                       ExpandableListView.OnChildClickListener,
+                                       TabsAccessor.OnQueryTabsCompleteListener {
+    private static final String[] CLIENT_KEY = new String[] { "name" };
+    private static final String[] TAB_KEY = new String[] { "title", "url" };
+    private static final int[] CLIENT_RESOURCE = new int[] { R.id.client };
+    private static final int[] TAB_RESOURCE = new int[] { R.id.tab, R.id.url };
+
+    private final Context context;
+    private TabsPanel tabsPanel;
+
+    private ArrayList <ArrayList <HashMap <String, String>>> tabsList;
+
+    public RemoteTabsList(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        this.context = context;
+
+        setOnGroupClickListener(this);
+        setOnChildClickListener(this);
+    }
+
+    public void setTabsPanel(TabsPanel panel) {
+        tabsPanel = panel;
+    }
+
+    private void autoHidePanel() {
+        tabsPanel.autoHidePanel();
+    }
+
+    @Override
+    public boolean onGroupClick(ExpandableListView parent, View view, int position, long id) {
+        // By default, the group collapses/expands. Consume the event.
+        return true;
+    }
+
+    @Override
+    public boolean onChildClick(ExpandableListView parent, View view, int groupPosition, int childPosition, long id) {
+        HashMap <String, String> tab = tabsList.get(groupPosition).get(childPosition);
+        if (tab == null) {
+            autoHidePanel();
+            return true;
+        }
+
+        Tabs.getInstance().loadUrl(tab.get("url"), Tabs.LOADURL_NEW_TAB);
+        autoHidePanel();
+        return true;
+    }
+
+    @Override
+    public void onQueryTabsComplete(List<TabsAccessor.RemoteTab> remoteTabsList) {
+        ArrayList<TabsAccessor.RemoteTab> remoteTabs = new ArrayList<TabsAccessor.RemoteTab> (remoteTabsList);
+        if (remoteTabs == null || remoteTabs.size() == 0)
+            return;
+
+        ArrayList <HashMap <String, String>> clients = new ArrayList <HashMap <String, String>>();
+
+        tabsList = new ArrayList <ArrayList <HashMap <String, String>>>();
+
+        String oldGuid = null;
+        ArrayList <HashMap <String, String>> tabsForClient = null;
+        HashMap <String, String> client;
+        HashMap <String, String> tab;
+
+        for (TabsAccessor.RemoteTab remoteTab : remoteTabs) {
+            if (oldGuid == null || !TextUtils.equals(oldGuid, remoteTab.guid)) {
+                client = new HashMap <String, String>();
+                client.put("name", remoteTab.name);
+                clients.add(client);
+
+                tabsForClient = new ArrayList <HashMap <String, String>>();
+                tabsList.add(tabsForClient);
+
+                oldGuid = new String(remoteTab.guid);
+            }
+
+            tab = new HashMap<String, String>();
+            tab.put("title", TextUtils.isEmpty(remoteTab.title) ? remoteTab.url : remoteTab.title);
+            tab.put("url", remoteTab.url);
+            tabsForClient.add(tab);
+        }
+
+        setAdapter(new SimpleExpandableListAdapter(context,
+                                                   clients,
+                                                   R.layout.remote_tabs_group,
+                                                   CLIENT_KEY,
+                                                   CLIENT_RESOURCE,
+                                                   tabsList,
+                                                   R.layout.remote_tabs_child,
+                                                   TAB_KEY,
+                                                   TAB_RESOURCE));
+
+        for (int i = 0; i < clients.size(); i++) {
+            expandGroup(i);
+        }
+    }
+}
--- a/mobile/android/base/TabsPanel.java
+++ b/mobile/android/base/TabsPanel.java
@@ -83,23 +83,23 @@ public class TabsPanel extends LinearLay
         LayoutInflater.from(context).inflate(R.layout.tabs_panel, this);
         initialize();
     }
 
     private void initialize() {
         mHeader = (RelativeLayout) findViewById(R.id.tabs_panel_header);
         mTabsContainer = (TabsListContainer) findViewById(R.id.tabs_container);
 
-        mPanelNormal = (TabsTray) findViewById(R.id.normal_tabs);
+        mPanelNormal = (PanelView) findViewById(R.id.normal_tabs);
         mPanelNormal.setTabsPanel(this);
 
-        mPanelPrivate = (TabsTray) findViewById(R.id.private_tabs);
+        mPanelPrivate = (PanelView) findViewById(R.id.private_tabs);
         mPanelPrivate.setTabsPanel(this);
 
-        mPanelRemote = (RemoteTabs) findViewById(R.id.synced_tabs);
+        mPanelRemote = (PanelView) findViewById(R.id.synced_tabs);
         mPanelRemote.setTabsPanel(this);
 
         mFooter = (RelativeLayout) findViewById(R.id.tabs_panel_footer);
 
         mAddTab = (ImageButton) findViewById(R.id.add_tab);
         mAddTab.setOnClickListener(new Button.OnClickListener() {
             @Override
             public void onClick(View v) {
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -333,17 +333,18 @@ gbjar.sources += [
     'prompts/Prompt.java',
     'prompts/PromptInput.java',
     'prompts/PromptListAdapter.java',
     'prompts/PromptListItem.java',
     'prompts/PromptService.java',
     'prompts/TabInput.java',
     'ReaderModeUtils.java',
     'ReferrerReceiver.java',
-    'RemoteTabs.java',
+    'RemoteTabsContainer.java',
+    'RemoteTabsList.java',
     'Restarter.java',
     'ScrollAnimator.java',
     'ServiceNotificationClient.java',
     'SessionParser.java',
     'SharedPreferencesHelper.java',
     'SiteIdentity.java',
     'SmsManager.java',
     'sqlite/ByteBufferInputStream.java',
--- a/mobile/android/base/resources/layout/tabs_panel.xml
+++ b/mobile/android/base/resources/layout/tabs_panel.xml
@@ -42,20 +42,26 @@
         <org.mozilla.gecko.TabsTray android:id="@+id/private_tabs"
                                     style="@style/TabsList"
                                     android:layout_width="fill_parent"
                                     android:layout_height="fill_parent"
                                     android:choiceMode="singleChoice"
                                     android:visibility="gone"
                                     gecko:tabs="tabs_private"/>
 
-        <org.mozilla.gecko.RemoteTabs android:id="@+id/synced_tabs"
-                                      style="@style/RemoteTabsList"
-                                      android:layout_width="fill_parent"
-                                      android:layout_height="fill_parent"
-                                      android:visibility="gone"
-                                      android:paddingLeft="@dimen/tabs_panel_list_padding"
-                                      android:paddingRight="@dimen/tabs_panel_list_padding"
-                                      android:scrollbarStyle="outsideOverlay"/>
+        <org.mozilla.gecko.RemoteTabsContainer android:id="@+id/synced_tabs"
+                                               android:layout_width="fill_parent"
+                                               android:layout_height="fill_parent"
+                                               android:visibility="gone">
+
+            <org.mozilla.gecko.RemoteTabsList android:id="@+id/synced_tabs_list"
+                                          style="@style/RemoteTabsList"
+                                          android:layout_width="fill_parent"
+                                          android:layout_height="fill_parent"
+                                          android:paddingLeft="@dimen/tabs_panel_list_padding"
+                                          android:paddingRight="@dimen/tabs_panel_list_padding"
+                                          android:scrollbarStyle="outsideOverlay"/>
+
+        </org.mozilla.gecko.RemoteTabsContainer>
 
     </view>
 
 </merge>