diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-11-17 17:22:56 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-11-17 17:22:56 -0800 |
commit | 128f979438b3d2151123392ddc0e524d34feaf1f (patch) | |
tree | 30df64cf5254bcbbb351e86c94a3129fb43262b6 /app/src/main/java | |
parent | 25a67f1f8d186fabd339c711ceef6ad8a0c3d5d5 (diff) | |
download | dsub-128f979438b3d2151123392ddc0e524d34feaf1f.tar.gz dsub-128f979438b3d2151123392ddc0e524d34feaf1f.tar.bz2 dsub-128f979438b3d2151123392ddc0e524d34feaf1f.zip |
Fix swapping position of download files not sticking until refresh due to not moving in local list immediately
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java | 14 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/util/DownloadFileItemHelperCallback.java | 5 |
2 files changed, 18 insertions, 1 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java index 95bef065..d5f9a6ea 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java @@ -363,6 +363,20 @@ public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewH } } + 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) { diff --git a/app/src/main/java/github/daneren2005/dsub/util/DownloadFileItemHelperCallback.java b/app/src/main/java/github/daneren2005/dsub/util/DownloadFileItemHelperCallback.java index 4074fece..e1e2dc63 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/DownloadFileItemHelperCallback.java +++ b/app/src/main/java/github/daneren2005/dsub/util/DownloadFileItemHelperCallback.java @@ -2,6 +2,7 @@ package github.daneren2005.dsub.util; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; +import android.util.Log; import org.eclipse.jetty.util.ArrayQueue; @@ -15,6 +16,8 @@ import github.daneren2005.dsub.view.SongView; 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; @@ -31,7 +34,7 @@ public class DownloadFileItemHelperCallback extends ItemTouchHelper.SimpleCallba 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)); |