Category-specific auto download (#701)
* Category-specific auto download
This commit is contained in:
committed by
GitHub
parent
3be9881997
commit
68c4116327
@@ -57,6 +57,9 @@ class LibraryUpdateService : Service() {
|
||||
*/
|
||||
val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
/**
|
||||
* Download Manager
|
||||
*/
|
||||
val downloadManager: DownloadManager by injectLazy()
|
||||
|
||||
/**
|
||||
@@ -216,7 +219,7 @@ class LibraryUpdateService : Service() {
|
||||
.filter { it.category in categoriesToUpdate }
|
||||
.distinctBy { it.id }
|
||||
else
|
||||
db.getFavoriteMangas().executeAsBlocking().distinctBy { it.id }
|
||||
db.getLibraryMangas().executeAsBlocking().distinctBy { it.id }
|
||||
}
|
||||
|
||||
if (!intent.getBooleanExtra(UPDATE_DETAILS, false) && preferences.updateOnlyNonCompleted()) {
|
||||
@@ -238,8 +241,16 @@ class LibraryUpdateService : Service() {
|
||||
fun updateChapterList(mangaToUpdate: List<Manga>): Observable<Manga> {
|
||||
// Initialize the variables holding the progress of the updates.
|
||||
val count = AtomicInteger(0)
|
||||
// List containing new updates
|
||||
val newUpdates = ArrayList<Manga>()
|
||||
// list containing failed updates
|
||||
val failedUpdates = ArrayList<Manga>()
|
||||
// List containing categories that get included in downloads.
|
||||
val categoriesToDownload = preferences.downloadNewCategories().getOrDefault().map(String::toInt)
|
||||
// Boolean to determine if user wants to automatically download new chapters.
|
||||
val downloadNew = preferences.downloadNew().getOrDefault()
|
||||
// Boolean to determine if DownloadManager has downloads
|
||||
var hasDownloads = false
|
||||
|
||||
// Emit each manga and update it sequentially.
|
||||
return Observable.from(mangaToUpdate)
|
||||
@@ -254,10 +265,13 @@ class LibraryUpdateService : Service() {
|
||||
Pair(emptyList<Chapter>(), emptyList<Chapter>())
|
||||
}
|
||||
// Filter out mangas without new chapters (or failed).
|
||||
.filter { pair -> pair.first.size > 0 }
|
||||
.filter { pair -> pair.first.isNotEmpty() }
|
||||
.doOnNext {
|
||||
if (preferences.downloadNew()) {
|
||||
downloadChapters(manga, it.first)
|
||||
if (downloadNew) {
|
||||
if (categoriesToDownload.isEmpty() || manga.category in categoriesToDownload) {
|
||||
downloadChapters(manga, it.first)
|
||||
hasDownloads = true
|
||||
}
|
||||
}
|
||||
}
|
||||
// Convert to the manga that contains new chapters.
|
||||
@@ -277,8 +291,10 @@ class LibraryUpdateService : Service() {
|
||||
cancelNotification()
|
||||
} else {
|
||||
showResultNotification(newUpdates, failedUpdates)
|
||||
if (preferences.downloadNew()) {
|
||||
DownloadService.start(this)
|
||||
if (downloadNew) {
|
||||
if (hasDownloads) {
|
||||
DownloadService.start(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,8 @@ class PreferenceKeys(context: Context) {
|
||||
|
||||
val downloadNew = context.getString(R.string.pref_download_new_key)
|
||||
|
||||
val downloadNewCategories = context.getString(R.string.pref_download_new_categories_key)
|
||||
|
||||
fun sourceUsername(sourceId: Long) = "pref_source_username_$sourceId"
|
||||
|
||||
fun sourcePassword(sourceId: Long) = "pref_source_password_$sourceId"
|
||||
|
||||
@@ -142,7 +142,9 @@ class PreferencesHelper(val context: Context) {
|
||||
|
||||
fun hiddenCatalogues() = rxPrefs.getStringSet("hidden_catalogues", emptySet())
|
||||
|
||||
fun downloadNew() = prefs.getBoolean(keys.downloadNew, false)
|
||||
fun downloadNew() = rxPrefs.getBoolean(keys.downloadNew, false)
|
||||
|
||||
fun downloadNewCategories() = rxPrefs.getStringSet(keys.downloadNewCategories, emptySet())
|
||||
|
||||
fun lang() = prefs.getString(keys.lang, "")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user