aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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) {