Bug 1220928 - Add RecyclerView boilerplate. r=sebastian
☠☠ backed out by 435d12d164aa ☠ ☠
authorChenxia Liu <liuche@mozilla.com>
Tue, 23 Feb 2016 11:00:42 -0800
changeset 290823 d64938914b3ed77c22ba4559b01d92907056b438
parent 290822 494289c72ba3997183e7b5beaca3e0447ecaf96d
child 290824 ceb669fb17f23763eb4f9cfc53ad74d011e842a5
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1220928
milestone48.0a1
Bug 1220928 - Add RecyclerView boilerplate. r=sebastian MozReview-Commit-ID: xaRLs8JxMs
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryItem.java
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java
mobile/android/base/moz.build
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
@@ -0,0 +1,56 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * 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.home;
+
+import android.database.Cursor;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import org.mozilla.gecko.R;
+import org.mozilla.gecko.db.RemoteClient;
+
+import java.util.Collections;
+import java.util.List;
+
+public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistoryItem> {
+    // These ordinal positions are used in CombinedHistoryAdapter as viewType.
+    private enum ItemType {
+        CLIENT, HISTORY
+    }
+
+    private List<RemoteClient> remoteClients = Collections.emptyList();
+    private Cursor historyCursor;
+
+    @Override
+    public CombinedHistoryItem onCreateViewHolder(ViewGroup viewGroup, int viewType) {
+        final LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
+        final View view;
+        if (viewType == ItemType.CLIENT.ordinal()) {
+            view = inflater.inflate(R.layout.home_remote_tabs_group, viewGroup, false);
+            return new CombinedHistoryItem.ClientItem(view);
+        } else {
+            view = inflater.inflate(R.layout.home_item_row, viewGroup, false);
+            return new CombinedHistoryItem.HistoryItem(view);
+        }
+    }
+
+    @Override
+    public int getItemViewType(int position) {
+        final int numClients = remoteClients.size();
+        return (position < numClients) ? ItemType.CLIENT.ordinal() : ItemType.HISTORY.ordinal();
+    }
+
+    @Override
+    public int getItemCount() {
+        final int remoteSize = remoteClients.size();
+        final int historySize = historyCursor == null ? 0 : historyCursor.getCount();
+        return remoteSize + historySize;
+    }
+
+    @Override
+    public void onBindViewHolder(CombinedHistoryItem viewHolder, int position) {}
+
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryItem.java
@@ -0,0 +1,27 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * 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.home;
+
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+
+public abstract class CombinedHistoryItem extends RecyclerView.ViewHolder {
+    public CombinedHistoryItem(View view) {
+        super(view);
+    }
+
+    public static class HistoryItem extends CombinedHistoryItem {
+        public HistoryItem(View view) {
+            super(view);
+        }
+    }
+
+    public static class ClientItem extends CombinedHistoryItem {
+        public ClientItem(View view) {
+            super(view);
+        }
+
+    }
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -0,0 +1,12 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * 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.home;
+
+public class CombinedHistoryPanel extends HomeFragment {
+
+    @Override
+    protected void load() {}
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java
@@ -0,0 +1,46 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * 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.home;
+
+import android.content.Context;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.util.AttributeSet;
+import android.view.View;
+import org.mozilla.gecko.widget.RecyclerViewClickSupport;
+
+public class CombinedHistoryRecyclerView extends RecyclerView
+        implements RecyclerViewClickSupport.OnItemClickListener, RecyclerViewClickSupport.OnItemLongClickListener {
+
+    public CombinedHistoryRecyclerView(Context context) {
+        super(context);
+        init(context);
+    }
+
+    public CombinedHistoryRecyclerView(Context context, AttributeSet attributeSet) {
+        super(context, attributeSet);
+        init(context);
+    }
+
+    public CombinedHistoryRecyclerView(Context context, AttributeSet attributeSet, int defStyle) {
+        super(context, attributeSet, defStyle);
+        init(context);
+    }
+
+    private void init(Context context) {
+        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
+        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
+        setLayoutManager(layoutManager);
+    }
+
+    @Override
+    public void onItemClicked(RecyclerView recyclerView, int position, View v) {}
+
+    @Override
+    public boolean onItemLongClicked(RecyclerView recyclerView, int position, View v) {
+        return showContextMenuForChild(this);
+    }
+}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -374,16 +374,20 @@ gbjar.sources += ['java/org/mozilla/geck
     'health/SessionInformation.java',
     'health/StubbedHealthRecorder.java',
     'home/BookmarkFolderView.java',
     'home/BookmarkScreenshotRow.java',
     'home/BookmarksListAdapter.java',
     'home/BookmarksListView.java',
     'home/BookmarksPanel.java',
     'home/BrowserSearch.java',
+    'home/CombinedHistoryAdapter.java',
+    'home/CombinedHistoryItem.java',
+    'home/CombinedHistoryPanel.java',
+    'home/CombinedHistoryRecyclerView.java',
     'home/DynamicPanel.java',
     'home/FramePanelLayout.java',
     'home/HistoryHeaderListCursorAdapter.java',
     'home/HistoryItemAdapter.java',
     'home/HistoryPanel.java',
     'home/HomeAdapter.java',
     'home/HomeBanner.java',
     'home/HomeConfig.java',