зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1220928 - Add context menu. r=sebastian
MozReview-Commit-ID: CQ01edJs3vP --HG-- extra : rebase_source : dcd7b5ed6f48b422cf106f64b6ce9c827c387eca extra : source : b2828872f3e78911798083fde9b196e7206aaf19
This commit is contained in:
Родитель
145a10dc43
Коммит
959ca283cb
|
@ -111,6 +111,21 @@ public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistory
|
|||
}
|
||||
}
|
||||
|
||||
public HomeContextMenuInfo makeContextMenuInfoFromPosition(View view, int position) {
|
||||
final ItemType itemType = ItemType.viewTypeToItemType(getItemViewType(position));
|
||||
HomeContextMenuInfo info;
|
||||
switch (itemType) {
|
||||
case CHILD:
|
||||
info = new HomeContextMenuInfo(view, position, -1);
|
||||
return CombinedHistoryPanel.populateChildInfoFromTab(info, clientChildren.get(position));
|
||||
case HISTORY:
|
||||
info = new HomeContextMenuInfo(view, position, -1);
|
||||
historyCursor.moveToPosition(transformPosition(ItemType.HISTORY, position));
|
||||
return CombinedHistoryPanel.populateHistoryInfoFromCursor(info, historyCursor);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CombinedHistoryItem onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||
final LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
|
||||
|
|
|
@ -37,8 +37,10 @@ import org.mozilla.gecko.R;
|
|||
import org.mozilla.gecko.Restrictions;
|
||||
import org.mozilla.gecko.Telemetry;
|
||||
import org.mozilla.gecko.TelemetryContract;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.db.BrowserDB;
|
||||
import org.mozilla.gecko.db.RemoteClient;
|
||||
import org.mozilla.gecko.db.RemoteTab;
|
||||
import org.mozilla.gecko.home.HistorySectionsHelper.SectionDateRange;
|
||||
import org.mozilla.gecko.restrictions.Restrictable;
|
||||
import org.mozilla.gecko.widget.DividerItemDecoration;
|
||||
|
@ -105,6 +107,8 @@ public class CombinedHistoryPanel extends HomeFragment {
|
|||
mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext()));
|
||||
mRecyclerView.setOnHistoryClickedListener(mUrlOpenListener);
|
||||
mRecyclerView.setOnPanelLevelChangeListener(new OnLevelChangeListener());
|
||||
registerForContextMenu(mRecyclerView);
|
||||
|
||||
mPanelFooterButton = (Button) view.findViewById(R.id.clear_history_button);
|
||||
mPanelFooterButton.setOnClickListener(new OnFooterButtonClickListener());
|
||||
}
|
||||
|
@ -381,4 +385,26 @@ public class CombinedHistoryPanel extends HomeFragment {
|
|||
|
||||
return ssb;
|
||||
}
|
||||
|
||||
protected static HomeContextMenuInfo populateHistoryInfoFromCursor(HomeContextMenuInfo info, Cursor cursor) {
|
||||
info.url = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.URL));
|
||||
info.title = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.TITLE));
|
||||
info.historyId = cursor.getInt(cursor.getColumnIndexOrThrow(BrowserContract.Combined.HISTORY_ID));
|
||||
info.itemType = HomeContextMenuInfo.RemoveItemType.HISTORY;
|
||||
final int bookmarkIdCol = cursor.getColumnIndexOrThrow(BrowserContract.Combined.BOOKMARK_ID);
|
||||
if (cursor.isNull(bookmarkIdCol)) {
|
||||
// If this is a combined cursor, we may get a history item without a
|
||||
// bookmark, in which case the bookmarks ID column value will be null.
|
||||
info.bookmarkId = -1;
|
||||
} else {
|
||||
info.bookmarkId = cursor.getInt(bookmarkIdCol);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
protected static HomeContextMenuInfo populateChildInfoFromTab(HomeContextMenuInfo info, RemoteTab tab) {
|
||||
info.url = tab.url;
|
||||
info.title = tab.title;
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ public class CombinedHistoryRecyclerView extends RecyclerView
|
|||
|
||||
protected HomePager.OnUrlOpenListener mOnUrlOpenListener;
|
||||
protected OnPanelLevelChangeListener mOnPanelLevelChangeListener;
|
||||
protected HomeContextMenuInfo mContextMenuInfo;
|
||||
|
||||
public CombinedHistoryRecyclerView(Context context) {
|
||||
super(context);
|
||||
|
@ -84,7 +85,13 @@ public class CombinedHistoryRecyclerView extends RecyclerView
|
|||
|
||||
@Override
|
||||
public boolean onItemLongClicked(RecyclerView recyclerView, int position, View v) {
|
||||
// TODO: open context menu if not a date title
|
||||
mContextMenuInfo = ((CombinedHistoryAdapter) getAdapter()).makeContextMenuInfoFromPosition(v, position);
|
||||
return showContextMenuForChild(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HomeContextMenuInfo getContextMenuInfo() {
|
||||
return mContextMenuInfo;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче