mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 06:31:47 +01:00
Option to include default category in downloading new chapters
This commit is contained in:
parent
63e6fb715d
commit
5c6a91b0d3
@ -28,14 +28,13 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.toMangaInfo
|
||||
import eu.kanade.tachiyomi.source.model.toSChapter
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
||||
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
||||
import eu.kanade.tachiyomi.util.manga.MangaShortcutManager
|
||||
import eu.kanade.tachiyomi.util.system.executeOnIO
|
||||
import eu.kanade.tachiyomi.util.shouldDownloadNewChapters
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -97,10 +96,6 @@ class LibraryUpdateService(
|
||||
val count = AtomicInteger(0)
|
||||
val jobCount = AtomicInteger(0)
|
||||
|
||||
// List containing categories that get included in downloads.
|
||||
private val categoriesToDownload =
|
||||
preferences.downloadNewCategories().get().map(String::toInt)
|
||||
|
||||
// Boolean to determine if user wants to automatically download new chapters.
|
||||
private val downloadNew: Boolean = preferences.downloadNew().get()
|
||||
|
||||
@ -258,13 +253,7 @@ class LibraryUpdateService(
|
||||
}
|
||||
GlobalScope.launch(handler) {
|
||||
val hasDLs = try {
|
||||
requestSemaphore.withPermit {
|
||||
updateMangaInSource(
|
||||
it.key,
|
||||
downloadNew,
|
||||
categoriesToDownload
|
||||
)
|
||||
}
|
||||
requestSemaphore.withPermit { updateMangaInSource(it.key) }
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
@ -314,7 +303,7 @@ class LibraryUpdateService(
|
||||
async {
|
||||
try {
|
||||
requestSemaphore.withPermit {
|
||||
updateMangaInSource(source, downloadNew, categoriesToDownload)
|
||||
updateMangaInSource(source)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
@ -341,7 +330,7 @@ class LibraryUpdateService(
|
||||
DownloadService.start(this)
|
||||
}
|
||||
} else if (downloadNew && hasDownloads) {
|
||||
DownloadService.start(this)
|
||||
DownloadService.start(this.applicationContext)
|
||||
}
|
||||
newUpdates.clear()
|
||||
}
|
||||
@ -357,25 +346,14 @@ class LibraryUpdateService(
|
||||
notifier.cancelProgressNotification()
|
||||
}
|
||||
|
||||
private suspend fun updateMangaInSource(
|
||||
source: Long,
|
||||
downloadNew: Boolean,
|
||||
categoriesToDownload: List<Int>
|
||||
): Boolean {
|
||||
private suspend fun updateMangaInSource(source: Long): Boolean {
|
||||
if (mangaToUpdateMap[source] == null) return false
|
||||
var count = 0
|
||||
var hasDownloads = false
|
||||
while (count < mangaToUpdateMap[source]!!.size) {
|
||||
val shouldDownload =
|
||||
(
|
||||
downloadNew && (
|
||||
categoriesToDownload.isEmpty() ||
|
||||
mangaToUpdateMap[source]!![count].category in categoriesToDownload ||
|
||||
db.getCategoriesForManga(mangaToUpdateMap[source]!![count])
|
||||
.executeOnIO().any { (it.id ?: -1) in categoriesToDownload }
|
||||
)
|
||||
)
|
||||
if (updateMangaChapters(mangaToUpdateMap[source]!![count], this.count.andIncrement, shouldDownload)) {
|
||||
val manga = mangaToUpdateMap[source]!![count]
|
||||
val shouldDownload = manga.shouldDownloadNewChapters(db, preferences)
|
||||
if (updateMangaChapters(manga, this.count.andIncrement, shouldDownload)) {
|
||||
hasDownloads = true
|
||||
}
|
||||
count++
|
||||
|
@ -80,7 +80,7 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
||||
category.name = text
|
||||
if (this.category == null) {
|
||||
val categories = db.getCategories().executeAsBlocking()
|
||||
category.order = categories.maxOf { it.order } + 1
|
||||
category.order = (categories.maxOfOrNull { it.order } ?: 0) + 1
|
||||
category.mangaSort = LibrarySort.Title.categoryValue
|
||||
val dbCategory = db.insertCategory(category).executeAsBlocking()
|
||||
category.id = dbCategory.insertedId()?.toInt()
|
||||
@ -124,7 +124,6 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
||||
fun onViewCreated() {
|
||||
if (category?.id ?: 0 <= 0 && category != null) {
|
||||
binding.categoryTextLayout.isVisible = false
|
||||
binding.downloadNew.isVisible = false
|
||||
}
|
||||
binding.editCategories.isVisible = category != null
|
||||
binding.editCategories.setOnClickListener {
|
||||
@ -134,23 +133,22 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
||||
binding.title.addTextChangedListener {
|
||||
binding.categoryTextLayout.error = null
|
||||
}
|
||||
binding.title.hint = category?.name ?: binding.editCategories.context.getString(R.string.category)
|
||||
binding.title.hint =
|
||||
category?.name ?: binding.editCategories.context.getString(R.string.category)
|
||||
binding.title.append(category?.name ?: "")
|
||||
if (binding.downloadNew.isVisible) {
|
||||
val downloadNew = preferences.downloadNew().get()
|
||||
setCheckbox(
|
||||
binding.downloadNew,
|
||||
preferences.downloadNewCategories(),
|
||||
true
|
||||
)
|
||||
if (downloadNew && preferences.downloadNewCategories().get().isEmpty()) {
|
||||
binding.downloadNew.isVisible = false
|
||||
} else if (!downloadNew) {
|
||||
binding.downloadNew.isVisible = true
|
||||
}
|
||||
binding.downloadNew.isChecked =
|
||||
preferences.downloadNew().get() && binding.downloadNew.isChecked
|
||||
val downloadNew = preferences.downloadNew().get()
|
||||
setCheckbox(
|
||||
binding.downloadNew,
|
||||
preferences.downloadNewCategories(),
|
||||
true
|
||||
)
|
||||
if (downloadNew && preferences.downloadNewCategories().get().isEmpty()) {
|
||||
binding.downloadNew.isVisible = false
|
||||
} else if (!downloadNew) {
|
||||
binding.downloadNew.isVisible = true
|
||||
}
|
||||
binding.downloadNew.isChecked =
|
||||
preferences.downloadNew().get() && binding.downloadNew.isChecked
|
||||
setCheckbox(
|
||||
binding.includeGlobal,
|
||||
preferences.libraryUpdateCategories(),
|
||||
|
@ -15,6 +15,7 @@ import com.afollestad.materialdialogs.list.listItemsSingleChoice
|
||||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
@ -78,6 +79,7 @@ class SettingsDownloadController : SettingsController() {
|
||||
}
|
||||
|
||||
val dbCategories = db.getCategories().executeAsBlocking()
|
||||
val categories = listOf(Category.createDefault(context)) + dbCategories
|
||||
|
||||
preferenceCategory {
|
||||
titleRes = R.string.download_new_chapters
|
||||
@ -90,8 +92,8 @@ class SettingsDownloadController : SettingsController() {
|
||||
multiSelectListPreferenceMat(activity) {
|
||||
key = Keys.downloadNewCategories
|
||||
titleRes = R.string.categories_to_include_in_download
|
||||
entries = dbCategories.map { it.name }
|
||||
entryValues = dbCategories.map { it.id.toString() }
|
||||
entries = categories.map { it.name }
|
||||
entryValues = categories.map { it.id.toString() }
|
||||
allSelectionRes = R.string.all
|
||||
|
||||
preferences.downloadNew().asImmediateFlowIn(viewScope) { isVisible = it }
|
||||
|
Loading…
Reference in New Issue
Block a user