Positions change: remember item

This commit is contained in:
Martin Fietz 2015-11-12 13:21:45 +01:00
parent 63020ec4ce
commit 166c067194
2 changed files with 10 additions and 10 deletions

View File

@ -2,6 +2,7 @@ package de.danoeh.antennapod.adapter;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.Nullable;
import android.support.v4.view.MotionEventCompat; import android.support.v4.view.MotionEventCompat;
import android.support.v7.widget.PopupMenu; import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@ -59,7 +60,7 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
private boolean locked; private boolean locked;
private int position = -1; private FeedItem selectedItem;
public QueueRecyclerAdapter(MainActivity mainActivity, public QueueRecyclerAdapter(MainActivity mainActivity,
ItemAccess itemAccess, ItemAccess itemAccess,
@ -88,17 +89,18 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
FeedItem item = itemAccess.getItem(pos); FeedItem item = itemAccess.getItem(pos);
holder.bind(item); holder.bind(item);
holder.itemView.setOnLongClickListener(v -> { holder.itemView.setOnLongClickListener(v -> {
position = pos; selectedItem = item;
return false; return false;
}); });
} }
public int getItemCount() { @Nullable
return itemAccess.getCount(); public FeedItem getSelectedItem() {
return selectedItem;
} }
public int getPosition() { public int getItemCount() {
return position; return itemAccess.getCount();
} }
public class ViewHolder extends RecyclerView.ViewHolder public class ViewHolder extends RecyclerView.ViewHolder

View File

@ -327,11 +327,9 @@ public class QueueFragment extends Fragment {
if(!isVisible()) { if(!isVisible()) {
return false; return false;
} }
int pos = recyclerAdapter.getPosition(); FeedItem selectedItem = recyclerAdapter.getSelectedItem();
FeedItem selectedItem = itemAccess.getItem(pos);
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);
} }