mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-11 13:39:11 +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"
|
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.
|
* 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 category a specific category to update, or null for global update.
|
||||||
* @param target defines what should be updated.
|
* @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()) {
|
if (!isRunning()) {
|
||||||
val intent = Intent(context, LibraryUpdateService::class.java).apply {
|
val intent = Intent(context, LibraryUpdateService::class.java).apply {
|
||||||
putExtra(KEY_TARGET, target)
|
putExtra(KEY_TARGET, target)
|
||||||
category?.id?.let { id ->
|
category?.id?.let { id ->
|
||||||
putExtra(KEY_CATEGORY, 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) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||||
@ -164,7 +178,8 @@ class LibraryUpdateService(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (target == Target.CHAPTERS) category?.id?.let {
|
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) {
|
private fun addCategory(categoryId: Int) {
|
||||||
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault()
|
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault()
|
||||||
val mangas =
|
val mangas =
|
||||||
@ -322,7 +344,18 @@ class LibraryUpdateService(
|
|||||||
instance = this
|
instance = this
|
||||||
|
|
||||||
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault()
|
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.
|
// Update favorite manga. Destroy service when completed or in case of an error.
|
||||||
launchTarget(target, mangaList, startId)
|
launchTarget(target, mangaList, startId)
|
||||||
return START_REDELIVER_INTENT
|
return START_REDELIVER_INTENT
|
||||||
|
@ -1140,8 +1140,8 @@ class LibraryController(
|
|||||||
|
|
||||||
override fun openCategoriesBackdrop() = showCategories(true)
|
override fun openCategoriesBackdrop() = showCategories(true)
|
||||||
|
|
||||||
override fun updateCategory(catId: Int): Boolean {
|
override fun updateCategory(position: Int): Boolean {
|
||||||
val category = (adapter.getItem(catId) as? LibraryHeaderItem)?.category ?: return false
|
val category = (adapter.getItem(position) as? LibraryHeaderItem)?.category ?: return false
|
||||||
val inQueue = LibraryUpdateService.categoryInQueue(category.id)
|
val inQueue = LibraryUpdateService.categoryInQueue(category.id)
|
||||||
snack?.dismiss()
|
snack?.dismiss()
|
||||||
snack = view?.snack(
|
snack = view?.snack(
|
||||||
@ -1157,10 +1157,19 @@ class LibraryController(
|
|||||||
view.elevation = 15f.dpToPx
|
view.elevation = 15f.dpToPx
|
||||||
setAction(R.string.cancel) {
|
setAction(R.string.cancel) {
|
||||||
LibraryUpdateService.stop(context)
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,20 +116,20 @@ class LibraryHeaderHolder(val view: View, private val adapter: LibraryCategoryAd
|
|||||||
catProgress.gone()
|
catProgress.gone()
|
||||||
setSelection()
|
setSelection()
|
||||||
}
|
}
|
||||||
category.isDynamic -> {
|
category.id ?: -1 < 0 -> {
|
||||||
expandImage.gone()
|
expandImage.gone()
|
||||||
checkboxImage.gone()
|
checkboxImage.gone()
|
||||||
catProgress.gone()
|
catProgress.gone()
|
||||||
updateButton.gone()
|
updateButton.gone()
|
||||||
}
|
}
|
||||||
LibraryUpdateService.categoryInQueue(category.id) -> {
|
LibraryUpdateService.categoryInQueue(category.id) -> {
|
||||||
expandImage.visibleIf(!adapter.isSingleCategory)
|
expandImage.visibleIf(!adapter.isSingleCategory && !category.isDynamic)
|
||||||
checkboxImage.gone()
|
checkboxImage.gone()
|
||||||
catProgress.visible()
|
catProgress.visible()
|
||||||
updateButton.invisible()
|
updateButton.invisible()
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
expandImage.visibleIf(!adapter.isSingleCategory)
|
expandImage.visibleIf(!adapter.isSingleCategory && !category.isDynamic)
|
||||||
catProgress.gone()
|
catProgress.gone()
|
||||||
checkboxImage.gone()
|
checkboxImage.gone()
|
||||||
updateButton.visibleIf(!adapter.isSingleCategory)
|
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) {
|
private suspend fun sectionLibrary(items: List<LibraryItem>, freshStart: Boolean = false) {
|
||||||
libraryItems = items
|
libraryItems = items
|
||||||
val showAll = showAllCategories || !libraryIsGrouped ||
|
val showAll = showAllCategories || !libraryIsGrouped ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user