diff --git a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java index 687d087681d2..ef5aa32e264a 100644 --- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java +++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java @@ -20,7 +20,8 @@ import java.util.List; public class CombinedHistoryAdapter extends RecyclerView.Adapter { private static final String LOGTAG = "GeckoCombinedHistAdapt"; - private enum ItemType { + + public enum ItemType { CLIENT, HISTORY; public static ItemType viewTypeToItemType(int viewType) { diff --git a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java index 13bf72b24c69..f4a98de9eb25 100644 --- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java +++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java @@ -47,6 +47,7 @@ public class CombinedHistoryPanel extends HomeFragment { 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. diff --git a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java index c22579995ee5..5635f5df9fc8 100644 --- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java +++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java @@ -10,11 +10,17 @@ 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); @@ -34,10 +40,33 @@ public class CombinedHistoryRecyclerView extends RecyclerView 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) {