Merge pull request #1377 from mfietz/issue/1375-queue-duplicates

Fix queue ordering/duplicate issues
This commit is contained in:
Tom Hennen 2015-11-12 17:45:24 -05:00
commit fc1ac0c175
2 changed files with 12 additions and 12 deletions

View File

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

View File

@ -165,7 +165,7 @@ public class QueueFragment extends Fragment {
case MOVED:
int from = FeedItemUtil.indexOfItemWithId(queue, event.item.getId());
int to = event.position;
Collections.swap(queue, from, to);
queue.add(to, queue.remove(from));
recyclerAdapter.notifyItemMoved(from, to);
break;
}
@ -327,11 +327,9 @@ public class QueueFragment extends Fragment {
if(!isVisible()) {
return false;
}
int pos = recyclerAdapter.getPosition();
FeedItem selectedItem = itemAccess.getItem(pos);
FeedItem selectedItem = recyclerAdapter.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);
}
@ -367,7 +365,7 @@ public class QueueFragment extends Fragment {
int from = viewHolder.getAdapterPosition();
int to = target.getAdapterPosition();
Log.d(TAG, "move(" + from + ", " + to + ")");
Collections.swap(queue, from, to);
queue.add(to, queue.remove(from));
recyclerAdapter.notifyItemMoved(from, to);
DBWriter.moveQueueItem(from, to, false);
return true;