Bug 1220928 - Open links for history. r=sebastian

MozReview-Commit-ID: KCXDHb3UEy9

--HG--
extra : rebase_source : b0b7bf667b79af12dfc04634d1881416d1f32726
extra : source : 6220841fe652e4711e0a31b4bd0f5f7a358b7a6b
This commit is contained in:
Chenxia Liu 2016-03-29 17:17:08 -07:00
Родитель a72bac67ca
Коммит df5f443116
3 изменённых файлов: 33 добавлений и 2 удалений

Просмотреть файл

@ -20,7 +20,8 @@ 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) {

Просмотреть файл

@ -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.

Просмотреть файл

@ -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) {