headlines list: reimplement context menus
This commit is contained in:
parent
1102e522f1
commit
357b5c9a27
@ -243,7 +243,7 @@ public class HeadlinesFragment extends Fragment {
|
|||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
|
||||||
.getMenuInfo();
|
.getMenuInfo();
|
||||||
|
|
||||||
Article article = getArticleAtPosition(info.position);
|
Article article = getArticleAtPosition(info.position - m_adapter.getHeaderCount());
|
||||||
|
|
||||||
if (!onArticleMenuItemSelected(item, article))
|
if (!onArticleMenuItemSelected(item, article))
|
||||||
return super.onContextItemSelected(item);
|
return super.onContextItemSelected(item);
|
||||||
@ -344,6 +344,7 @@ public class HeadlinesFragment extends Fragment {
|
|||||||
});
|
});
|
||||||
|
|
||||||
m_list = (RecyclerView) view.findViewById(R.id.headlines_list);
|
m_list = (RecyclerView) view.findViewById(R.id.headlines_list);
|
||||||
|
registerForContextMenu(m_list);
|
||||||
|
|
||||||
m_layoutManager = new LinearLayoutManager(m_activity.getApplicationContext());
|
m_layoutManager = new LinearLayoutManager(m_activity.getApplicationContext());
|
||||||
m_list.setLayoutManager(m_layoutManager);
|
m_list.setLayoutManager(m_layoutManager);
|
||||||
@ -808,6 +809,7 @@ public class HeadlinesFragment extends Fragment {
|
|||||||
public void clearAnimation() {
|
public void clearAnimation() {
|
||||||
view.clearAnimation();
|
view.clearAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ArticleListAdapter extends RecyclerView.Adapter<ArticleViewHolder> {
|
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);
|
View v = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
|
||||||
|
|
||||||
|
//registerForContextMenu(v);
|
||||||
|
|
||||||
return new ArticleViewHolder(v);
|
return new ArticleViewHolder(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -890,6 +894,14 @@ public class HeadlinesFragment extends Fragment {
|
|||||||
|
|
||||||
final Article article = holder.article;
|
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() {
|
holder.view.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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
|
@Override
|
||||||
public boolean onLongClick(View v) {
|
public boolean onLongClick(View v) {
|
||||||
m_activity.openContextMenu(v);
|
m_list.showContextMenuForChild(holder.view);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});*/
|
});
|
||||||
|
|
||||||
if (showFlavorImage && article.flavorImageUri != null && holder.flavorImageView != null) {
|
if (showFlavorImage && article.flavorImageUri != null && holder.flavorImageView != null) {
|
||||||
if (holder.flavorImageOverflow != null) {
|
if (holder.flavorImageOverflow != null) {
|
||||||
@ -1130,9 +1142,7 @@ public class HeadlinesFragment extends Fragment {
|
|||||||
holder.flavorImageView.setOnLongClickListener(new View.OnLongClickListener() {
|
holder.flavorImageView.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View v) {
|
public boolean onLongClick(View v) {
|
||||||
|
m_list.showContextMenuForChild(holder.view);
|
||||||
m_activity.openContextMenu(v);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -11,7 +11,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" >
|
android:layout_height="match_parent" >
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<org.fox.ttrss.util.ContextMenuRecyclerView
|
||||||
android:id="@+id/headlines_list"
|
android:id="@+id/headlines_list"
|
||||||
android:drawSelectorOnTop="true"
|
android:drawSelectorOnTop="true"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
Loading…
Reference in New Issue
Block a user