#2878: fix episode screen context menu is applied on wrong feed item during refresh

This commit is contained in:
orionlee 2018-11-16 13:42:56 -08:00
parent 68b245701e
commit 1d87910cbe
2 changed files with 10 additions and 18 deletions

View File

@ -1,6 +1,7 @@
package de.danoeh.antennapod.adapter;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
@ -51,7 +52,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
private final ActionButtonUtils actionButtonUtils;
private final boolean showOnlyNewEpisodes;
private int position = -1;
private FeedItem selectedItem;
private final int playingBackGroundColor;
private final int normalBackGroundColor;
@ -107,7 +108,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
final FeedItem item = itemAccess.getItem(position);
if (item == null) return;
holder.itemView.setOnLongClickListener(v -> {
this.position = holder.getAdapterPosition();
this.selectedItem = item;
return false;
});
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()));
}
@Nullable
public FeedItem getSelectedItem() {
return selectedItem;
}
@Override
public long getItemId(int position) {
FeedItem item = itemAccess.getItem(position);
@ -211,16 +217,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
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() {
@Override
public void onClick(View v) {

View File

@ -275,14 +275,10 @@ public class AllEpisodesFragment extends Fragment {
if(item.getItemId() == R.id.share_item) {
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) {
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);
}