From ab486862627f0dec14cda42d870860e9b8cd42d5 Mon Sep 17 00:00:00 2001 From: inorichi Date: Wed, 2 Dec 2015 11:53:32 +0100 Subject: [PATCH] Minor changes --- .../data/download/DownloadManager.java | 1 + .../data/download/model/Download.java | 1 - .../data/download/model/DownloadQueue.java | 13 ++++++++++++- .../ui/manga/chapter/ChaptersPresenter.java | 19 +++++-------------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/download/DownloadManager.java b/app/src/main/java/eu/kanade/mangafeed/data/download/DownloadManager.java index 3133fed7b..3b1d37f49 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/download/DownloadManager.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/download/DownloadManager.java @@ -340,6 +340,7 @@ public class DownloadManager { public void deleteChapter(Source source, Manga manga, Chapter chapter) { File path = getAbsoluteChapterDirectory(source, manga, chapter); DiskUtils.deleteFiles(path); + queue.remove(chapter); } public DownloadQueue getQueue() { diff --git a/app/src/main/java/eu/kanade/mangafeed/data/download/model/Download.java b/app/src/main/java/eu/kanade/mangafeed/data/download/model/Download.java index 7d8c02cf6..de66204ee 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/download/model/Download.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/download/model/Download.java @@ -35,7 +35,6 @@ public class Download { this.source = source; this.manga = manga; this.chapter = chapter; - this.status = QUEUE; } public int getStatus() { diff --git a/app/src/main/java/eu/kanade/mangafeed/data/download/model/DownloadQueue.java b/app/src/main/java/eu/kanade/mangafeed/data/download/model/DownloadQueue.java index 2581f9998..f4254093b 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/download/model/DownloadQueue.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/download/model/DownloadQueue.java @@ -3,7 +3,7 @@ package eu.kanade.mangafeed.data.download.model; import java.util.ArrayList; import java.util.List; -import eu.kanade.mangafeed.data.download.model.Download; +import eu.kanade.mangafeed.data.database.models.Chapter; import rx.Observable; import rx.subjects.PublishSubject; @@ -19,14 +19,25 @@ public class DownloadQueue { public void add(Download download) { download.setStatusSubject(statusSubject); + download.setStatus(Download.QUEUE); queue.add(download); } public void remove(Download download) { queue.remove(download); + download.setStatus(Download.NOT_DOWNLOADED); download.setStatusSubject(null); } + public void remove(Chapter chapter) { + for (Download download : queue) { + if (download.chapter.id == chapter.id) { + remove(download); + break; + } + } + } + public List get() { return queue; } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java index 5b64c2b50..cb079f134 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java @@ -22,7 +22,6 @@ import eu.kanade.mangafeed.ui.base.presenter.BasePresenter; import eu.kanade.mangafeed.util.EventBusHook; import eu.kanade.mangafeed.util.PostResult; import rx.Observable; -import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -42,10 +41,6 @@ public class ChaptersPresenter extends BasePresenter { private static final int DB_CHAPTERS = 1; private static final int FETCH_CHAPTERS = 2; - private Subscription markReadSubscription; - private Subscription downloadSubscription; - private Subscription deleteSubscription; - @Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); @@ -128,7 +123,7 @@ public class ChaptersPresenter extends BasePresenter { } public void markChaptersRead(Observable selectedChapters, boolean read) { - add(markReadSubscription = selectedChapters + add(selectedChapters .subscribeOn(Schedulers.io()) .map(chapter -> { chapter.read = read; @@ -138,27 +133,23 @@ public class ChaptersPresenter extends BasePresenter { .toList() .flatMap(chapters -> db.insertChapters(chapters).createObservable()) .observeOn(AndroidSchedulers.mainThread()) - .doOnCompleted(() -> remove(markReadSubscription)) - .subscribe(result -> { - })); + .subscribe()); } public void downloadChapters(Observable selectedChapters) { - add(downloadSubscription = selectedChapters + add(selectedChapters .toList() .subscribe(chapters -> { EventBus.getDefault().postSticky(new DownloadChaptersEvent(manga, chapters)); - remove(downloadSubscription); })); } public void deleteChapters(Observable selectedChapters) { - deleteSubscription = selectedChapters - .doOnCompleted(() -> remove(deleteSubscription)) + add(selectedChapters .subscribe(chapter -> { downloadManager.deleteChapter(source, manga, chapter); chapter.status = Download.NOT_DOWNLOADED; - }); + })); }