Category-specific auto download (#701)
* Category-specific auto download
This commit is contained in:
parent
3be9881997
commit
68c4116327
7 changed files with 62 additions and 7 deletions
|
@ -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()) {
|
||||
if (downloadNew) {
|
||||
if (categoriesToDownload.isEmpty() || manga.category in categoriesToDownload) {
|
||||
downloadChapters(manga, it.first)
|
||||
hasDownloads = true
|
||||
}
|
||||
}
|
||||
}
|
||||
// Convert to the manga that contains new chapters.
|
||||
|
@ -277,12 +291,14 @@ class LibraryUpdateService : Service() {
|
|||
cancelNotification()
|
||||
} else {
|
||||
showResultNotification(newUpdates, failedUpdates)
|
||||
if (preferences.downloadNew()) {
|
||||
if (downloadNew) {
|
||||
if (hasDownloads) {
|
||||
DownloadService.start(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun downloadChapters(manga: Manga, chapters: List<Chapter>) {
|
||||
// we need to get the chapters from the db so we have chapter ids
|
||||
|
|
|
@ -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, "")
|
||||
|
||||
|
|
|
@ -19,10 +19,12 @@ import com.nononsenseapps.filepicker.FilePickerActivity
|
|||
import com.nononsenseapps.filepicker.FilePickerFragment
|
||||
import com.nononsenseapps.filepicker.LogicHandler
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.util.inflate
|
||||
import eu.kanade.tachiyomi.util.plusAssign
|
||||
import net.xpece.android.support.preference.MultiSelectListPreference
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.io.File
|
||||
|
||||
|
@ -41,8 +43,12 @@ class SettingsDownloadsFragment : SettingsFragment() {
|
|||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
private val db: DatabaseHelper by injectLazy()
|
||||
|
||||
val downloadDirPref: Preference by bindPref(R.string.pref_download_directory_key)
|
||||
|
||||
val downloadCategory: MultiSelectListPreference by bindPref(R.string.pref_download_new_categories_key)
|
||||
|
||||
override fun onViewCreated(view: View, savedState: Bundle?) {
|
||||
super.onViewCreated(view, savedState)
|
||||
|
||||
|
@ -92,6 +98,29 @@ class SettingsDownloadsFragment : SettingsFragment() {
|
|||
dir.createFile(".nomedia")
|
||||
}
|
||||
}
|
||||
|
||||
subscriptions += preferences.downloadNew().asObservable()
|
||||
.subscribe { downloadCategory.isVisible = it }
|
||||
|
||||
val dbCategories = db.getCategories().executeAsBlocking()
|
||||
downloadCategory.apply {
|
||||
entries = dbCategories.map { it.name }.toTypedArray()
|
||||
entryValues = dbCategories.map { it.id.toString() }.toTypedArray()
|
||||
}
|
||||
|
||||
subscriptions += preferences.downloadNewCategories().asObservable()
|
||||
.subscribe {
|
||||
val selectedCategories = it
|
||||
.mapNotNull { id -> dbCategories.find { it.id == id.toInt() } }
|
||||
.sortedBy { it.order }
|
||||
|
||||
val summary = if (selectedCategories.isEmpty())
|
||||
getString(R.string.all)
|
||||
else
|
||||
selectedCategories.joinToString { it.name }
|
||||
|
||||
downloadCategory.summary = summary
|
||||
}
|
||||
}
|
||||
|
||||
fun getExternalFilesDirs(): List<File> {
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
<string name="pref_last_catalogue_source_key" translatable="false">last_catalogue_source</string>
|
||||
|
||||
<string name="pref_download_new_key" translatable="false">download_new</string>
|
||||
<string name="pref_download_new_categories_key" translatable="false">download_new_categories</string>
|
||||
|
||||
<!-- String Fonts -->
|
||||
<string name="font_roboto_medium" translatable="false">sans-serif</string>
|
||||
|
|
|
@ -176,6 +176,7 @@
|
|||
<string name="fourth_to_last">Fourth to last chapter</string>
|
||||
<string name="fifth_to_last">Fifth to last chapter</string>
|
||||
<string name="pref_download_new">Download new chapters</string>
|
||||
<string name="pref_download_new_categories">Categories to include in download</string>
|
||||
|
||||
<!-- Sync section -->
|
||||
<string name="services">Services</string>
|
||||
|
|
|
@ -53,6 +53,10 @@
|
|||
android:key="@string/pref_download_new_key"
|
||||
android:title="@string/pref_download_new"/>
|
||||
|
||||
<MultiSelectListPreference
|
||||
android:key="@string/pref_download_new_categories_key"
|
||||
android:title="@string/pref_download_new_categories" />
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
</PreferenceScreen>
|
Reference in a new issue