Browse Source

move clear queue to presenter

Kevin Richter 9 years ago
parent
commit
63d0161da5

+ 6 - 5
app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java

@@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment;
 import nucleus.factory.RequiresPresenter;
 import rx.Subscription;
 
-import java.util.ArrayList;
 import java.util.List;
 
 @RequiresPresenter(DownloadPresenter.class)
@@ -25,6 +24,7 @@ public class DownloadFragment extends BaseRxFragment<DownloadPresenter> {
 
     private MenuItem startButton;
     private MenuItem pauseButton;
+    private MenuItem clearButton;
 
     private Subscription queueStatusSubscription;
     private boolean isRunning;
@@ -60,9 +60,10 @@ public class DownloadFragment extends BaseRxFragment<DownloadPresenter> {
         inflater.inflate(R.menu.download_queue, menu);
         startButton = menu.findItem(R.id.start_queue);
         pauseButton = menu.findItem(R.id.pause_queue);
+        clearButton = menu.findItem(R.id.clear_queue);
 
         if(adapter.getItemCount() > 0) {
-            menu.findItem(R.id.clear_queue).setVisible(true);
+            clearButton.setVisible(true);
         }
 
         // Menu seems to be inflated after onResume in fragments, so we initialize them here
@@ -79,10 +80,10 @@ public class DownloadFragment extends BaseRxFragment<DownloadPresenter> {
             case R.id.pause_queue:
                 DownloadService.stop(getActivity());
                 break;
-            case R.id.clear_queue: // Not sure if this is correct
+            case R.id.clear_queue:
                 DownloadService.stop(getActivity());
-                getPresenter().downloadManager.getQueue().clear();
-                onNextDownloads(new ArrayList<>());
+                getPresenter().clearQueue();
+                clearButton.setVisible(false);
                 break;
         }
         return super.onOptionsItemSelected(item);

+ 8 - 6
app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.java

@@ -1,12 +1,6 @@
 package eu.kanade.tachiyomi.ui.download;
 
 import android.os.Bundle;
-
-import java.util.HashMap;
-import java.util.concurrent.TimeUnit;
-
-import javax.inject.Inject;
-
 import eu.kanade.tachiyomi.data.download.DownloadManager;
 import eu.kanade.tachiyomi.data.download.model.Download;
 import eu.kanade.tachiyomi.data.download.model.DownloadQueue;
@@ -18,6 +12,10 @@ import rx.android.schedulers.AndroidSchedulers;
 import rx.schedulers.Schedulers;
 import timber.log.Timber;
 
+import javax.inject.Inject;
+import java.util.HashMap;
+import java.util.concurrent.TimeUnit;
+
 public class DownloadPresenter extends BasePresenter<DownloadFragment> {
 
     @Inject DownloadManager downloadManager;
@@ -123,4 +121,8 @@ public class DownloadPresenter extends BasePresenter<DownloadFragment> {
         remove(statusSubscription);
     }
 
+    public void clearQueue() {
+        downloadQueue.clear();
+        start(GET_DOWNLOAD_QUEUE);
+    }
 }