Skip to content

Commit

Permalink
Fix swapping position of download files not sticking until refresh du…
Browse files Browse the repository at this point in the history
…e to not moving in local list immediately
  • Loading branch information
daneren2005 committed Nov 18, 2015
1 parent 25a67f1 commit 128f979
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,20 @@ public void clearSelected() {
}
}

public void moveItem(int from, int to) {
List<T> section = sections.get(0);
int max = section.size();
if(to >= max) {
to = max - 1;
} else if(to < 0) {
to = 0;
}

T moved = section.remove(from);
section.add(to, moved);

notifyItemMoved(from, to);
}
public void removeItem(T item) {
int subPosition = 0;
for(List<T> section: sections) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.Log;

import org.eclipse.jetty.util.ArrayQueue;

Expand All @@ -15,6 +16,8 @@
import github.daneren2005.dsub.view.UpdateView;

public class DownloadFileItemHelperCallback extends ItemTouchHelper.SimpleCallback {
private static final String TAG = DownloadFileItemHelperCallback.class.getSimpleName();

private SubsonicFragment fragment;
private boolean mainList;

Expand All @@ -31,7 +34,7 @@ public DownloadFileItemHelperCallback(SubsonicFragment fragment, boolean mainLis
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder fromHolder, RecyclerView.ViewHolder toHolder) {
int from = fromHolder.getAdapterPosition();
int to = toHolder.getAdapterPosition();
getSectionAdapter().notifyItemMoved(from, to);
getSectionAdapter().moveItem(from, to);

synchronized (pendingOperations) {
pendingOperations.add(new Pair<>(from, to));
Expand Down

0 comments on commit 128f979

Please sign in to comment.