Bump dependencies. Minor changes to download manager

This commit is contained in:
inorichi
2016-01-16 18:10:05 +01:00
parent 936d5e46eb
commit 67c9420606
5 changed files with 18 additions and 24 deletions

View File

@ -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<Download> downloadsQueueSubject;
private BehaviorSubject<Integer> threadsNumber;
private BehaviorSubject<Boolean> 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<String> 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);
}

View File

@ -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<Integer> portraitColumns() {
@ -156,8 +155,8 @@ public class PreferencesHelper {
prefs.edit().putString(getKey(R.string.pref_download_directory_key), path).apply();
}
public Preference<Integer> 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() {