diff options
author | Matthew Gaffen <matt@gaffen.co.uk> | 2018-03-16 11:01:23 +0000 |
---|---|---|
committer | Matthew Gaffen <matt@gaffen.co.uk> | 2018-03-16 11:01:23 +0000 |
commit | a9f566f3f104e37eb160a0dcb9dcb11f8879e110 (patch) | |
tree | fb8cb754ebde05a13faae0ceb24b1f83992550ee /app/src | |
parent | f3299e7de2b9b7733f0ed572e20dc39679971b5a (diff) | |
download | AntennaPod-a9f566f3f104e37eb160a0dcb9dcb11f8879e110.zip |
Only write queue order to database on drag release for the podcast queue.
This prevents large numbers of db writes in quick succession. This is a particular problem for large queue lengths. Fixes #2562 and potentially fixed #2573
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index bf22e71f5..7ec96dbbe 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -389,17 +389,29 @@ public class QueueFragment extends Fragment { itemTouchHelper = new ItemTouchHelper( new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.RIGHT) { + // Position tracking whilst dragging + int dragFrom = -1; + int dragTo = -1; + @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { + int fromPosition = viewHolder.getAdapterPosition(); + int toPosition = target.getAdapterPosition(); + + // Update tracked position + if(dragFrom == -1) { + dragFrom = fromPosition; + } + dragTo = toPosition; + int from = viewHolder.getAdapterPosition(); int to = target.getAdapterPosition(); - Log.d(TAG, "move(" + from + ", " + to + ")"); + Log.d(TAG, "move(" + from + ", " + to + ") in memory"); if(from >= queue.size() || to >= queue.size()) { return false; } queue.add(to, queue.remove(from)); recyclerAdapter.notifyItemMoved(from, to); - DBWriter.moveQueueItem(from, to, true); return true; } @@ -453,12 +465,25 @@ public class QueueFragment extends Fragment { RecyclerView.ViewHolder viewHolder) { super.clearView(recyclerView, viewHolder); + // Check if drag finished + if(dragFrom != -1 && dragTo != -1 && dragFrom != dragTo) { + reallyMoved(dragFrom, dragTo); + } + + dragFrom = dragTo = -1; + if (viewHolder instanceof QueueRecyclerAdapter.ItemTouchHelperViewHolder) { QueueRecyclerAdapter.ItemTouchHelperViewHolder itemViewHolder = (QueueRecyclerAdapter.ItemTouchHelperViewHolder) viewHolder; itemViewHolder.onItemClear(); } } + + private void reallyMoved(int from, int to) { + // Write drag operation to database + Log.d(TAG, "Write to database move(" + dragFrom + ", " + dragTo + ")"); + DBWriter.moveQueueItem(dragFrom, dragTo, true); + } } ); itemTouchHelper.attachToRecyclerView(recyclerView); |