mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 05:25:08 +01:00
Dynamic categories can now be updated seperately
This commit is contained in:
parent
3eb1cc1f17
commit
b5702e715a
@ -132,6 +132,11 @@ class LibraryUpdateService(
|
||||
*/
|
||||
const val KEY_TARGET = "target"
|
||||
|
||||
/**
|
||||
* Key for list of manga to be updated. (For dynamic categories)
|
||||
*/
|
||||
const val KEY_MANGAS = "mangas"
|
||||
|
||||
/**
|
||||
* Returns the status of the service.
|
||||
*
|
||||
@ -149,12 +154,21 @@ class LibraryUpdateService(
|
||||
* @param category a specific category to update, or null for global update.
|
||||
* @param target defines what should be updated.
|
||||
*/
|
||||
fun start(context: Context, category: Category? = null, target: Target = Target.CHAPTERS) {
|
||||
fun start(
|
||||
context: Context,
|
||||
category: Category? = null,
|
||||
target: Target = Target.CHAPTERS,
|
||||
mangaToUse: List<LibraryManga>? = null
|
||||
) {
|
||||
if (!isRunning()) {
|
||||
val intent = Intent(context, LibraryUpdateService::class.java).apply {
|
||||
putExtra(KEY_TARGET, target)
|
||||
category?.id?.let { id ->
|
||||
putExtra(KEY_CATEGORY, id)
|
||||
if (mangaToUse != null) putExtra(
|
||||
KEY_MANGAS,
|
||||
mangaToUse.mapNotNull { it.id }.toLongArray()
|
||||
)
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
@ -164,7 +178,8 @@ class LibraryUpdateService(
|
||||
}
|
||||
} else {
|
||||
if (target == Target.CHAPTERS) category?.id?.let {
|
||||
instance?.addCategory(it)
|
||||
if (mangaToUse != null) instance?.addMangaToQueue(it, mangaToUse)
|
||||
else instance?.addCategory(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -227,6 +242,13 @@ class LibraryUpdateService(
|
||||
}
|
||||
}
|
||||
|
||||
private fun addMangaToQueue(categoryId: Int, manga: List<LibraryManga>) {
|
||||
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault()
|
||||
val mangas = manga.sortedWith(rankingScheme[selectedScheme])
|
||||
categoryIds.add(categoryId)
|
||||
addManga(mangas)
|
||||
}
|
||||
|
||||
private fun addCategory(categoryId: Int) {
|
||||
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault()
|
||||
val mangas =
|
||||
@ -322,7 +344,18 @@ class LibraryUpdateService(
|
||||
instance = this
|
||||
|
||||
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault()
|
||||
val mangaList = getMangaToUpdate(intent, target).sortedWith(rankingScheme[selectedScheme])
|
||||
val savedMangasList = intent.getLongArrayExtra(KEY_MANGAS)?.asList()
|
||||
|
||||
val mangaList = (if (savedMangasList != null) {
|
||||
val mangas = db.getLibraryMangas().executeAsBlocking().filter {
|
||||
it.id in savedMangasList
|
||||
}.distinctBy { it.id }
|
||||
val categoryId = intent.getIntExtra(KEY_CATEGORY, -1)
|
||||
if (categoryId > -1) categoryIds.add(categoryId)
|
||||
mangas
|
||||
} else {
|
||||
getMangaToUpdate(intent, target)
|
||||
}).sortedWith(rankingScheme[selectedScheme])
|
||||
// Update favorite manga. Destroy service when completed or in case of an error.
|
||||
launchTarget(target, mangaList, startId)
|
||||
return START_REDELIVER_INTENT
|
||||
|
@ -1140,8 +1140,8 @@ class LibraryController(
|
||||
|
||||
override fun openCategoriesBackdrop() = showCategories(true)
|
||||
|
||||
override fun updateCategory(catId: Int): Boolean {
|
||||
val category = (adapter.getItem(catId) as? LibraryHeaderItem)?.category ?: return false
|
||||
override fun updateCategory(position: Int): Boolean {
|
||||
val category = (adapter.getItem(position) as? LibraryHeaderItem)?.category ?: return false
|
||||
val inQueue = LibraryUpdateService.categoryInQueue(category.id)
|
||||
snack?.dismiss()
|
||||
snack = view?.snack(
|
||||
@ -1157,10 +1157,19 @@ class LibraryController(
|
||||
view.elevation = 15f.dpToPx
|
||||
setAction(R.string.cancel) {
|
||||
LibraryUpdateService.stop(context)
|
||||
Handler().post { NotificationReceiver.dismissNotification(context, Notifications.ID_LIBRARY_PROGRESS) }
|
||||
Handler().post {
|
||||
NotificationReceiver.dismissNotification(
|
||||
context,
|
||||
Notifications.ID_LIBRARY_PROGRESS
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!inQueue) LibraryUpdateService.start(view!!.context, category)
|
||||
if (!inQueue) LibraryUpdateService.start(
|
||||
view!!.context, category, mangaToUse = if (category.isDynamic) {
|
||||
presenter.getMangaInCategories(category.id)
|
||||
} else null
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -116,20 +116,20 @@ class LibraryHeaderHolder(val view: View, private val adapter: LibraryCategoryAd
|
||||
catProgress.gone()
|
||||
setSelection()
|
||||
}
|
||||
category.isDynamic -> {
|
||||
category.id ?: -1 < 0 -> {
|
||||
expandImage.gone()
|
||||
checkboxImage.gone()
|
||||
catProgress.gone()
|
||||
updateButton.gone()
|
||||
}
|
||||
LibraryUpdateService.categoryInQueue(category.id) -> {
|
||||
expandImage.visibleIf(!adapter.isSingleCategory)
|
||||
expandImage.visibleIf(!adapter.isSingleCategory && !category.isDynamic)
|
||||
checkboxImage.gone()
|
||||
catProgress.visible()
|
||||
updateButton.invisible()
|
||||
}
|
||||
else -> {
|
||||
expandImage.visibleIf(!adapter.isSingleCategory)
|
||||
expandImage.visibleIf(!adapter.isSingleCategory && !category.isDynamic)
|
||||
catProgress.gone()
|
||||
checkboxImage.gone()
|
||||
updateButton.visibleIf(!adapter.isSingleCategory)
|
||||
|
@ -152,6 +152,11 @@ class LibraryPresenter(
|
||||
)
|
||||
}
|
||||
|
||||
fun getMangaInCategories(catId: Int?): List<LibraryManga>? {
|
||||
catId ?: return null
|
||||
return allLibraryItems.filter { it.header.category.id == catId }.map { it.manga }
|
||||
}
|
||||
|
||||
private suspend fun sectionLibrary(items: List<LibraryItem>, freshStart: Boolean = false) {
|
||||
libraryItems = items
|
||||
val showAll = showAllCategories || !libraryIsGrouped ||
|
||||
|
Loading…
Reference in New Issue
Block a user