From 67c9420606865baa9c0956209491be4b7a9e53f9 Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 16 Jan 2016 18:10:05 +0100 Subject: [PATCH] Bump dependencies. Minor changes to download manager --- app/build.gradle | 4 +-- .../data/download/DownloadManager.java | 26 +++++++------------ .../data/preference/PreferencesHelper.java | 7 +++-- app/src/main/res/xml/pref_reader.xml | 3 ++- build.gradle | 2 +- 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6d3a924c5..453550794 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -112,7 +112,7 @@ dependencies { provided "frankiesardo:icepick-processor:$ICEPICK_VERSION" compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4' compile 'eu.davidea:flexible-adapter:4.2.0@aar' - compile 'com.nononsenseapps:filepicker:2.5.0' + compile 'com.nononsenseapps:filepicker:2.5.1' compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' compile 'com.github.pwittchen:reactivenetwork:0.1.5' @@ -121,7 +121,7 @@ dependencies { apt "com.pushtorefresh.storio:sqlite-annotations-processor:$STORIO_VERSION" provided 'org.glassfish:javax.annotation:10.0-b28' - compile('com.mikepenz:materialdrawer:4.6.1@aar') { + compile('com.mikepenz:materialdrawer:4.6.4@aar') { transitive = true } compile('com.github.afollestad.material-dialogs:core:0.8.5.3@aar') { 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 aafe36d66..ab553a071 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 @@ -13,6 +13,7 @@ import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.List; import eu.kanade.tachiyomi.data.database.models.Chapter; @@ -42,10 +43,8 @@ public class DownloadManager { private Gson gson; private PublishSubject downloadsQueueSubject; - private BehaviorSubject threadsNumber; private BehaviorSubject runningSubject; private Subscription downloadsSubscription; - private Subscription threadsNumberSubscription; private DownloadQueue queue; private volatile boolean isRunning; @@ -61,7 +60,6 @@ public class DownloadManager { queue = new DownloadQueue(); downloadsQueueSubject = PublishSubject.create(); - threadsNumber = BehaviorSubject.create(); runningSubject = BehaviorSubject.create(); } @@ -69,14 +67,8 @@ public class DownloadManager { if (downloadsSubscription != null && !downloadsSubscription.isUnsubscribed()) downloadsSubscription.unsubscribe(); - if (threadsNumberSubscription != null && !threadsNumberSubscription.isUnsubscribed()) - threadsNumberSubscription.unsubscribe(); - - threadsNumberSubscription = preferences.downloadThreads().asObservable() - .subscribe(threadsNumber::onNext); - downloadsSubscription = downloadsQueueSubject - .lift(new DynamicConcurrentMergeOperator<>(this::downloadChapter, threadsNumber)) + .flatMap(this::downloadChapter, preferences.downloadThreads()) .onBackpressureBuffer() .observeOn(AndroidSchedulers.mainThread()) .map(download -> areAllDownloadsFinished()) @@ -102,11 +94,6 @@ public class DownloadManager { downloadsSubscription.unsubscribe(); downloadsSubscription = null; } - - if (threadsNumberSubscription != null && !threadsNumberSubscription.isUnsubscribed()) { - threadsNumberSubscription.unsubscribe(); - threadsNumberSubscription = null; - } } // Create a download object for every chapter in the event and add them to the downloads queue @@ -114,7 +101,14 @@ public class DownloadManager { final Manga manga = event.getManga(); final Source source = sourceManager.get(manga.source); + // Used to avoid downloading chapters with the same name + final List addedChapters = new ArrayList<>(); + for (Chapter chapter : event.getChapters()) { + if (addedChapters.contains(chapter.name)) + continue; + + addedChapters.add(chapter.name); Download download = new Download(source, manga, chapter); if (!prepareDownload(download)) { @@ -362,7 +356,7 @@ public class DownloadManager { File.separator + manga.title.replaceAll("[^\\sa-zA-Z0-9.-]", "_") + File.separator + - chapter.name.replaceAll("[^\\sa-zA-Z0-9.-]", "_") + " (" + chapter.id + ")"; + chapter.name.replaceAll("[^\\sa-zA-Z0-9.-]", "_"); return new File(preferences.getDownloadsDirectory(), chapterRelativePath); } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.java b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.java index d79b1c7f3..896883c4d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.java @@ -85,8 +85,7 @@ public class PreferencesHelper { } public int getDefaultViewer() { - // TODO use IntListPreference - return Integer.parseInt(prefs.getString(getKey(R.string.pref_default_viewer_key), "1")); + return prefs.getInt(getKey(R.string.pref_default_viewer_key), 1); } public Preference portraitColumns() { @@ -156,8 +155,8 @@ public class PreferencesHelper { prefs.edit().putString(getKey(R.string.pref_download_directory_key), path).apply(); } - public Preference downloadThreads() { - return rxPrefs.getInteger(getKey(R.string.pref_download_slots_key), 1); + public int downloadThreads() { + return prefs.getInt(getKey(R.string.pref_download_slots_key), 1); } public boolean downloadOnlyOverWifi() { diff --git a/app/src/main/res/xml/pref_reader.xml b/app/src/main/res/xml/pref_reader.xml index 23fa857d0..ac2c27945 100644 --- a/app/src/main/res/xml/pref_reader.xml +++ b/app/src/main/res/xml/pref_reader.xml @@ -21,7 +21,8 @@ android:key="@string/pref_custom_brightness_key" android:defaultValue="false" /> -