Bug 1220928 - Open links for history. r=sebastian
authorChenxia Liu <liuche@mozilla.com>
Tue, 29 Mar 2016 17:17:08 -0700
changeset 291320 df8b8021d41939f362f013a70239d827d505dffd
parent 291319 82af1bb19859da55d3ea73012d02a70d5b428c80
child 291321 1139e8f7b278942800183d18d10ba17b937b6642
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 - Open links for history. r=sebastian MozReview-Commit-ID: KCXDHb3UEy9
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/CombinedHistoryRecyclerView.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
@@ -15,17 +15,18 @@ 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> {
     private static final String LOGTAG = "GeckoCombinedHistAdapt";
-    private enum ItemType {
+
+    public enum ItemType {
         CLIENT, HISTORY;
 
         public static ItemType viewTypeToItemType(int viewType) {
             if (viewType >= ItemType.values().length) {
                 Log.e(LOGTAG, "No corresponding ItemType!");
             }
             return ItemType.values()[viewType];
         }
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -42,16 +42,17 @@ public class CombinedHistoryPanel extend
 
     @Override
     public void onViewCreated(View view, Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
 
         mRecyclerView = (CombinedHistoryRecyclerView) view.findViewById(R.id.combined_recycler_view);
         mAdapter = new CombinedHistoryAdapter(getContext());
         mRecyclerView.setAdapter(mAdapter);
+        mRecyclerView.setOnHistoryClickedListener(mUrlOpenListener);
         mClearHistoryButton = view.findViewById(R.id.clear_history_button);
         // TODO: link up click handler for clear history button
         // TODO: Handle date headers.
     }
 
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java
@@ -5,21 +5,27 @@
 
 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.Telemetry;
+import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.widget.RecyclerViewClickSupport;
 
+import java.util.EnumSet;
+
 public class CombinedHistoryRecyclerView extends RecyclerView
         implements RecyclerViewClickSupport.OnItemClickListener, RecyclerViewClickSupport.OnItemLongClickListener {
 
+    protected HomePager.OnUrlOpenListener mOnUrlOpenListener;
+
     public CombinedHistoryRecyclerView(Context context) {
         super(context);
         init(context);
     }
 
     public CombinedHistoryRecyclerView(Context context, AttributeSet attributeSet) {
         super(context, attributeSet);
         init(context);
@@ -29,19 +35,42 @@ public class CombinedHistoryRecyclerView
         super(context, attributeSet, defStyle);
         init(context);
     }
 
     private void init(Context context) {
         LinearLayoutManager layoutManager = new LinearLayoutManager(context);
         layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
         setLayoutManager(layoutManager);
+
+        RecyclerViewClickSupport.addTo(this)
+            .setOnItemClickListener(this)
+            .setOnItemLongClickListener(this);
+    }
+
+    public void setOnHistoryClickedListener(HomePager.OnUrlOpenListener listener) {
+        this.mOnUrlOpenListener = listener;
     }
 
     @Override
-    public void onItemClicked(RecyclerView recyclerView, int position, View v) {}
+    public void onItemClicked(RecyclerView recyclerView, int position, View v) {
+        final int viewType = getAdapter().getItemViewType(position);
+        final CombinedHistoryAdapter.ItemType itemType = CombinedHistoryAdapter.ItemType.viewTypeToItemType(viewType);
+
+        switch(itemType) {
+            case CLIENT:
+                // TODO: open new panel with all the remote children, and hide all the other items
+                return;
+            case HISTORY:
+                if (mOnUrlOpenListener != null) {
+                    final TwoLinePageRow historyItem = (TwoLinePageRow) v;
+                    Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.LIST_ITEM, "history");
+                    mOnUrlOpenListener.onUrlOpen(historyItem.getUrl(), EnumSet.of(HomePager.OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB));
+                }
+        }
+    }
 
     @Override
     public boolean onItemLongClicked(RecyclerView recyclerView, int position, View v) {
         // TODO: open context menu if not a date title
         return showContextMenuForChild(this);
     }
 }