headlines list: reimplement context menus

This commit is contained in:
Andrew Dolgov 2017-06-04 07:58:56 +03:00
parent 1102e522f1
commit 357b5c9a27
3 changed files with 61 additions and 8 deletions

View File

@ -243,7 +243,7 @@ public class HeadlinesFragment extends Fragment {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
Article article = getArticleAtPosition(info.position);
Article article = getArticleAtPosition(info.position - m_adapter.getHeaderCount());
if (!onArticleMenuItemSelected(item, article))
return super.onContextItemSelected(item);
@ -344,6 +344,7 @@ public class HeadlinesFragment extends Fragment {
});
m_list = (RecyclerView) view.findViewById(R.id.headlines_list);
registerForContextMenu(m_list);
m_layoutManager = new LinearLayoutManager(m_activity.getApplicationContext());
m_list.setLayoutManager(m_layoutManager);
@ -808,6 +809,7 @@ public class HeadlinesFragment extends Fragment {
public void clearAnimation() {
view.clearAnimation();
}
}
private class ArticleListAdapter extends RecyclerView.Adapter<ArticleViewHolder> {
@ -878,6 +880,8 @@ public class HeadlinesFragment extends Fragment {
View v = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
//registerForContextMenu(v);
return new ArticleViewHolder(v);
}
@ -890,6 +894,14 @@ public class HeadlinesFragment extends Fragment {
final Article article = holder.article;
holder.view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
m_list.showContextMenuForChild(v);
return true;
}
});
holder.view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -1080,14 +1092,14 @@ public class HeadlinesFragment extends Fragment {
}
});
/*holder.headlineHeader.setOnLongClickListener(new View.OnLongClickListener() {
holder.headlineHeader.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
m_activity.openContextMenu(v);
m_list.showContextMenuForChild(holder.view);
return true;
}
});*/
});
if (showFlavorImage && article.flavorImageUri != null && holder.flavorImageView != null) {
if (holder.flavorImageOverflow != null) {
@ -1130,9 +1142,7 @@ public class HeadlinesFragment extends Fragment {
holder.flavorImageView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
m_activity.openContextMenu(v);
m_list.showContextMenuForChild(holder.view);
return true;
}
});

View File

@ -0,0 +1,43 @@
package org.fox.ttrss.util;
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.ContextMenu;
import android.view.View;
import android.widget.AdapterView;
public class ContextMenuRecyclerView extends RecyclerView {
private AdapterView.AdapterContextMenuInfo mContextMenuInfo;
public ContextMenuRecyclerView(Context context) {
super(context);
}
public ContextMenuRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public ContextMenuRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected ContextMenu.ContextMenuInfo getContextMenuInfo() {
return mContextMenuInfo;
}
@Override
public boolean showContextMenuForChild(View originalView) {
final int longPressPosition = getChildPosition(originalView);
if (longPressPosition >= 0) {
final long longPressId = getAdapter().getItemId(longPressPosition);
mContextMenuInfo = new AdapterView.AdapterContextMenuInfo(originalView, longPressPosition, longPressId);
return super.showContextMenuForChild(originalView);
}
return false;
}
}

View File

@ -11,7 +11,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v7.widget.RecyclerView
<org.fox.ttrss.util.ContextMenuRecyclerView
android:id="@+id/headlines_list"
android:drawSelectorOnTop="true"
android:layout_width="match_parent"