aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-06-25 17:46:04 -0700
committerScott Jackson <daneren2005@gmail.com>2015-06-25 17:46:04 -0700
commit03da89a7a0a3dd2c642bc8c5a7f12ed04d1ffc46 (patch)
tree51b24a9fa462ebd0de1232aeb0caf6ada859c32f /app
parent87d5c3552d89e245707fe59d95e5cc0b2431e61e (diff)
downloaddsub-03da89a7a0a3dd2c642bc8c5a7f12ed04d1ffc46.tar.gz
dsub-03da89a7a0a3dd2c642bc8c5a7f12ed04d1ffc46.tar.bz2
dsub-03da89a7a0a3dd2c642bc8c5a7f12ed04d1ffc46.zip
#525 Implement swipe remove on DownloadFragment
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java52
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java10
2 files changed, 62 insertions, 0 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 5a3d63ad..b89a25c5 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java
@@ -16,10 +16,17 @@
package github.daneren2005.dsub.fragments;
import android.content.DialogInterface;
+import android.os.Bundle;
import android.os.Handler;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.ContextMenu;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
@@ -39,6 +46,7 @@ import github.daneren2005.dsub.util.ProgressListener;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.adapter.DownloadFileAdapter;
+import github.daneren2005.dsub.view.SongView;
import github.daneren2005.dsub.view.UpdateView;
public class DownloadFragment extends SelectRecyclerFragment<DownloadFile> {
@@ -51,6 +59,50 @@ public class DownloadFragment extends SelectRecyclerFragment<DownloadFile> {
}
@Override
+ 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) {
+ @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();
+ }
+ });
+ touchHelper.attachToRecyclerView(recyclerView);
+
+ return rootView;
+ }
+
+ @Override
public void onResume() {
super.onResume();
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
index bf68c450..2e3217d2 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -739,6 +739,16 @@ public class DownloadService extends Service {
setNextPlaying();
}
}
+ public synchronized void removeBackground(DownloadFile downloadFile) {
+ if (downloadFile == currentDownloading && downloadFile != currentPlaying && downloadFile != nextPlaying) {
+ currentDownloading.cancelDownload();
+ currentDownloading = null;
+ }
+
+ backgroundDownloadList.remove(downloadFile);
+ revision++;
+ checkDownloads();
+ }
public synchronized void delete(List<MusicDirectory.Entry> songs) {
for (MusicDirectory.Entry song : songs) {