diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-09-16 07:48:52 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-09-16 07:48:52 -0700 |
commit | 7df08f3d1ac3d098260a99871b1b03b273111bc0 (patch) | |
tree | 2a47a0b2f981b619c3b9c1b39f8990e70f6fda58 /app/src/main/java | |
parent | 3386851d2a638892942a52ca8493458dfa683871 (diff) | |
download | dsub-7df08f3d1ac3d098260a99871b1b03b273111bc0.tar.gz dsub-7df08f3d1ac3d098260a99871b1b03b273111bc0.tar.bz2 dsub-7df08f3d1ac3d098260a99871b1b03b273111bc0.zip |
Fix for issues with drag/drop
Diffstat (limited to 'app/src/main/java')
5 files changed, 11 insertions, 72 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java index b4e4be93..edbeff43 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -42,6 +42,7 @@ import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.util.DownloadFileItemHelperCallback; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.Util; @@ -62,41 +63,7 @@ public class DownloadFragment extends SelectRecyclerFragment<DownloadFile> imple public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { super.onCreateView(inflater, container, bundle); - ItemTouchHelper touchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) { - @Override - public boolean onMove(RecyclerView recyclerView, final RecyclerView.ViewHolder fromHolder, final RecyclerView.ViewHolder toHolder) { - new SilentBackgroundTask<Void>(context) { - private int from; - private int to; - - @Override - protected Void doInBackground() throws Throwable { - from = fromHolder.getAdapterPosition(); - to = toHolder.getAdapterPosition(); - getDownloadService().swap(false, from, to); - return null; - } - - @Override - protected void done(Void result) { - adapter.notifyItemMoved(from, to); - } - }.execute(); - - return true; - } - - @Override - public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { - SongView songView = (SongView) ((UpdateView.UpdateViewHolder) viewHolder).getUpdateView(); - DownloadFile downloadFile = songView.getDownloadFile(); - - DownloadService downloadService = getDownloadService(); - downloadService.removeBackground(downloadFile); - adapter.removeItem(downloadFile); - currentRevision = downloadService.getDownloadListUpdateRevision(); - } - }); + ItemTouchHelper touchHelper = new ItemTouchHelper(new DownloadFileItemHelperCallback(this, false)); touchHelper.attachToRecyclerView(recyclerView); return rootView; diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java index 8af8a26b..68ade3cc 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -188,40 +188,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis FastScroller fastScroller = (FastScroller) rootView.findViewById(R.id.download_fast_scroller); fastScroller.attachRecyclerView(playlistView); setupLayoutManager(playlistView, false); - ItemTouchHelper touchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) { - @Override - public boolean onMove(RecyclerView recyclerView, final RecyclerView.ViewHolder fromHolder, final RecyclerView.ViewHolder toHolder) { - new SilentBackgroundTask<Void>(context) { - private int from; - private int to; - - @Override - protected Void doInBackground() throws Throwable { - from = fromHolder.getAdapterPosition(); - to = toHolder.getAdapterPosition(); - getDownloadService().swap(true, from, to); - return null; - } - - @Override - protected void done(Void result) { - songListAdapter.notifyItemMoved(from, to); - } - }.execute(); - - return true; - } - - @Override - public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { - SongView songView = (SongView) ((UpdateView.UpdateViewHolder) viewHolder).getUpdateView(); - DownloadFile downloadFile = songView.getDownloadFile(); - - DownloadService downloadService = getDownloadService(); - downloadService.remove(downloadFile); - songListAdapter.removeItem(downloadFile); - } - }); + ItemTouchHelper touchHelper = new ItemTouchHelper(new DownloadFileItemHelperCallback(this, true)); touchHelper.attachToRecyclerView(playlistView); starButton = (ImageButton)rootView.findViewById(R.id.download_star); @@ -860,6 +827,11 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis } } + @Override + public SectionAdapter getCurrentAdapter() { + return songListAdapter; + } + private void scheduleHideControls() { if (hideControlsFuture != null) { hideControlsFuture.cancel(false); diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 93188e2f..abd1c6aa 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -662,7 +662,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section } @Override - protected SectionAdapter<Entry> getCurrentAdapter() { + public SectionAdapter<Entry> getCurrentAdapter() { return entryGridAdapter; } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java index adf22484..787b96e0 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java @@ -142,7 +142,7 @@ public abstract class SelectRecyclerFragment<T> extends SubsonicFragment impleme } } - protected SectionAdapter getCurrentAdapter() { + public SectionAdapter getCurrentAdapter() { return adapter; } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java index c5a2b022..6c5b63d1 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -1779,7 +1779,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }.execute(); } - protected SectionAdapter getCurrentAdapter() { return null; } + public SectionAdapter getCurrentAdapter() { return null; } public void stopActionMode() { SectionAdapter adapter = getCurrentAdapter(); if(adapter != null) { |