#2878: fix episode screen context menu is applied on wrong feed item during refresh
This commit is contained in:
parent
68b245701e
commit
1d87910cbe
|
@ -1,6 +1,7 @@
|
||||||
package de.danoeh.antennapod.adapter;
|
package de.danoeh.antennapod.adapter;
|
||||||
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||||
|
@ -51,7 +52,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
||||||
private final ActionButtonUtils actionButtonUtils;
|
private final ActionButtonUtils actionButtonUtils;
|
||||||
private final boolean showOnlyNewEpisodes;
|
private final boolean showOnlyNewEpisodes;
|
||||||
|
|
||||||
private int position = -1;
|
private FeedItem selectedItem;
|
||||||
|
|
||||||
private final int playingBackGroundColor;
|
private final int playingBackGroundColor;
|
||||||
private final int normalBackGroundColor;
|
private final int normalBackGroundColor;
|
||||||
|
@ -107,7 +108,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
||||||
final FeedItem item = itemAccess.getItem(position);
|
final FeedItem item = itemAccess.getItem(position);
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
holder.itemView.setOnLongClickListener(v -> {
|
holder.itemView.setOnLongClickListener(v -> {
|
||||||
this.position = holder.getAdapterPosition();
|
this.selectedItem = item;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
holder.item = item;
|
holder.item = item;
|
||||||
|
@ -200,6 +201,11 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
||||||
.into(new CoverTarget(item.getFeed().getImageLocation(), holder.placeholder, holder.cover, mainActivityRef.get()));
|
.into(new CoverTarget(item.getFeed().getImageLocation(), holder.placeholder, holder.cover, mainActivityRef.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public FeedItem getSelectedItem() {
|
||||||
|
return selectedItem;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(int position) {
|
public long getItemId(int position) {
|
||||||
FeedItem item = itemAccess.getItem(position);
|
FeedItem item = itemAccess.getItem(position);
|
||||||
|
@ -211,16 +217,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
||||||
return itemAccess.getCount();
|
return itemAccess.getCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FeedItem getItem(int position) {
|
|
||||||
return itemAccess.getItem(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPosition() {
|
|
||||||
int pos = position;
|
|
||||||
position = -1; // reset
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final View.OnClickListener secondaryActionListener = new View.OnClickListener() {
|
private final View.OnClickListener secondaryActionListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
|
@ -275,14 +275,10 @@ public class AllEpisodesFragment extends Fragment {
|
||||||
if(item.getItemId() == R.id.share_item) {
|
if(item.getItemId() == R.id.share_item) {
|
||||||
return true; // avoids that the position is reset when we need it in the submenu
|
return true; // avoids that the position is reset when we need it in the submenu
|
||||||
}
|
}
|
||||||
int pos = listAdapter.getPosition();
|
|
||||||
if(pos < 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
FeedItem selectedItem = itemAccess.getItem(pos);
|
|
||||||
|
|
||||||
|
FeedItem selectedItem = listAdapter.getSelectedItem();
|
||||||
if (selectedItem == null) {
|
if (selectedItem == null) {
|
||||||
Log.i(TAG, "Selected item at position " + pos + " was null, ignoring selection");
|
Log.i(TAG, "Selected item was null, ignoring selection");
|
||||||
return super.onContextItemSelected(item);
|
return super.onContextItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue