Merge pull request #2600 from Gaffen/queuedragorder-dbsync

Only write queue order to database on drag release for podcast queue.
This commit is contained in:
Martin Fietz 2018-03-18 10:16:30 +01:00 committed by GitHub
commit e168614e0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 2 deletions

View File

@ -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);