From 0210fd882886af9f059dd6d406905c195d53dcdf Mon Sep 17 00:00:00 2001 From: inorichi Date: Wed, 20 Jan 2016 14:38:45 +0100 Subject: [PATCH] Fix a big issue with the download threads. Release 0.1.1 --- app/build.gradle | 4 ++-- .../data/download/DownloadManager.java | 18 +++++++++++------- .../kanade/tachiyomi/ui/main/MainActivity.java | 6 +++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7d263c6c83..931d28b1f3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,8 +39,8 @@ android { minSdkVersion 16 targetSdkVersion 23 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - versionCode 1 - versionName "0.1.0" + versionCode 2 + versionName "0.1.1" buildConfigField "String", "COMMIT_COUNT", "\"${getCommitCount()}\"" buildConfigField "String", "COMMIT_SHA", "\"${getGitSha()}\"" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.java b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.java index c1c3411a55..16fe3f9638 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.java @@ -41,7 +41,7 @@ public class DownloadManager { private PreferencesHelper preferences; private Gson gson; - private PublishSubject downloadsQueueSubject; + private PublishSubject> downloadsQueueSubject; private BehaviorSubject runningSubject; private Subscription downloadsSubscription; @@ -67,7 +67,8 @@ public class DownloadManager { downloadsSubscription.unsubscribe(); downloadsSubscription = downloadsQueueSubject - .flatMap(this::downloadChapter, preferences.downloadThreads()) + .concatMap(downloads -> Observable.from(downloads) + .flatMap(this::downloadChapter, preferences.downloadThreads())) .onBackpressureBuffer() .observeOn(AndroidSchedulers.mainThread()) .map(download -> areAllDownloadsFinished()) @@ -102,6 +103,7 @@ public class DownloadManager { // Used to avoid downloading chapters with the same name final List addedChapters = new ArrayList<>(); + final List pending = new ArrayList<>(); for (Chapter chapter : event.getChapters()) { if (addedChapters.contains(chapter.name)) @@ -112,9 +114,10 @@ public class DownloadManager { if (!prepareDownload(download)) { queue.add(download); - if (isRunning) downloadsQueueSubject.onNext(download); + pending.add(download); } } + if (isRunning) downloadsQueueSubject.onNext(pending); } // Public method to check if a chapter is downloaded @@ -386,18 +389,19 @@ public class DownloadManager { if (queue.isEmpty()) return false; - boolean hasPendingDownloads = false; if (downloadsSubscription == null) initializeSubscriptions(); + final List pending = new ArrayList<>(); for (Download download : queue) { if (download.getStatus() != Download.DOWNLOADED) { if (download.getStatus() != Download.QUEUE) download.setStatus(Download.QUEUE); - if (!hasPendingDownloads) hasPendingDownloads = true; - downloadsQueueSubject.onNext(download); + pending.add(download); } } - return hasPendingDownloads; + downloadsQueueSubject.onNext(pending); + + return !pending.isEmpty(); } public void stopDownloads() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.java b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.java index cda74f7deb..2eb86920b6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.java @@ -72,9 +72,9 @@ public class MainActivity extends BaseActivity { new PrimaryDrawerItem() .withName(R.string.label_library) .withIdentifier(R.id.nav_drawer_library), - new PrimaryDrawerItem() - .withName(R.string.label_recent_updates) - .withIdentifier(R.id.nav_drawer_recent_updates), +// new PrimaryDrawerItem() +// .withName(R.string.label_recent_updates) +// .withIdentifier(R.id.nav_drawer_recent_updates), new PrimaryDrawerItem() .withName(R.string.label_catalogues) .withIdentifier(R.id.nav_drawer_catalogues),