From 63d0161da554c70c8b46ae1de7583b94967859cf Mon Sep 17 00:00:00 2001 From: Kevin Richter Date: Tue, 9 Feb 2016 17:42:39 +0100 Subject: [PATCH] move clear queue to presenter --- .../tachiyomi/ui/download/DownloadFragment.java | 11 ++++++----- .../tachiyomi/ui/download/DownloadPresenter.java | 14 ++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java index e2dd46c68..68ac1d6ba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.java +++ b/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 { private MenuItem startButton; private MenuItem pauseButton; + private MenuItem clearButton; private Subscription queueStatusSubscription; private boolean isRunning; @@ -60,9 +60,10 @@ public class DownloadFragment extends BaseRxFragment { 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 { 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); diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.java index 36bb3d308..df10854a6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.java +++ b/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 { @Inject DownloadManager downloadManager; @@ -123,4 +121,8 @@ public class DownloadPresenter extends BasePresenter { remove(statusSubscription); } + public void clearQueue() { + downloadQueue.clear(); + start(GET_DOWNLOAD_QUEUE); + } }