mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-25 00:31:13 +01:00
Added snack messages to show category is already in queue
Also removed the weird enabling logic of the swipe refresh for categories
This commit is contained in:
parent
755ce656b2
commit
f91e66269f
@ -131,6 +131,10 @@ class LibraryUpdateService(
|
|||||||
|
|
||||||
private val mangaToUpdate = mutableListOf<LibraryManga>()
|
private val mangaToUpdate = mutableListOf<LibraryManga>()
|
||||||
|
|
||||||
|
private val categoryIds = mutableSetOf<Int>()
|
||||||
|
|
||||||
|
fun categoryInQueue(id: Int?) = categoryIds.contains(id)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key that defines what should be updated.
|
* Key that defines what should be updated.
|
||||||
*/
|
*/
|
||||||
@ -158,7 +162,10 @@ class LibraryUpdateService(
|
|||||||
if (!isRunning(context)) {
|
if (!isRunning(context)) {
|
||||||
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?.let { putExtra(KEY_CATEGORY, it.id) }
|
category?.id?.let { id ->
|
||||||
|
putExtra(KEY_CATEGORY, id)
|
||||||
|
categoryIds.add(id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||||
context.startService(intent)
|
context.startService(intent)
|
||||||
@ -168,6 +175,7 @@ class LibraryUpdateService(
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (target == Target.CHAPTERS) category?.id?.let {
|
if (target == Target.CHAPTERS) category?.id?.let {
|
||||||
|
categoryIds.add(it)
|
||||||
val preferences: PreferencesHelper = Injekt.get()
|
val preferences: PreferencesHelper = Injekt.get()
|
||||||
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault()
|
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault()
|
||||||
addManga(getMangaToUpdate(it, target).sortedWith(
|
addManga(getMangaToUpdate(it, target).sortedWith(
|
||||||
@ -206,6 +214,7 @@ class LibraryUpdateService(
|
|||||||
db.getLibraryMangas().executeAsBlocking().filter { it.category == categoryId }
|
db.getLibraryMangas().executeAsBlocking().filter { it.category == categoryId }
|
||||||
else {
|
else {
|
||||||
val categoriesToUpdate = preferences.libraryUpdateCategories().getOrDefault().map(String::toInt)
|
val categoriesToUpdate = preferences.libraryUpdateCategories().getOrDefault().map(String::toInt)
|
||||||
|
categoryIds.addAll(categoriesToUpdate)
|
||||||
if (categoriesToUpdate.isNotEmpty())
|
if (categoriesToUpdate.isNotEmpty())
|
||||||
db.getLibraryMangas().executeAsBlocking()
|
db.getLibraryMangas().executeAsBlocking()
|
||||||
.filter { it.category in categoriesToUpdate }
|
.filter { it.category in categoriesToUpdate }
|
||||||
@ -250,6 +259,7 @@ class LibraryUpdateService(
|
|||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
subscription?.unsubscribe()
|
subscription?.unsubscribe()
|
||||||
mangaToUpdate.clear()
|
mangaToUpdate.clear()
|
||||||
|
categoryIds.clear()
|
||||||
if (wakeLock.isHeld) {
|
if (wakeLock.isHeld) {
|
||||||
wakeLock.release()
|
wakeLock.release()
|
||||||
}
|
}
|
||||||
@ -315,6 +325,7 @@ class LibraryUpdateService(
|
|||||||
job = GlobalScope.launch(Dispatchers.IO, CoroutineStart.DEFAULT) {
|
job = GlobalScope.launch(Dispatchers.IO, CoroutineStart.DEFAULT) {
|
||||||
updateChaptersJob()
|
updateChaptersJob()
|
||||||
mangaToUpdate.clear()
|
mangaToUpdate.clear()
|
||||||
|
categoryIds.clear()
|
||||||
stopSelf(startId)
|
stopSelf(startId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,15 +97,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
swipe_refresh.addView(recycler)
|
swipe_refresh.addView(recycler)
|
||||||
adapter.fastScroller = fast_scroller
|
adapter.fastScroller = fast_scroller
|
||||||
|
|
||||||
recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
|
||||||
override fun onScrollStateChanged(recycler: RecyclerView, newState: Int) {
|
|
||||||
// Disable swipe refresh when view is not at the top
|
|
||||||
val firstPos = (recycler.layoutManager as LinearLayoutManager)
|
|
||||||
.findFirstCompletelyVisibleItemPosition()
|
|
||||||
swipe_refresh.isEnabled = firstPos <= 0 && !preferences.hideCategories()
|
|
||||||
.getOrDefault()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
fast_scroller.addOnScrollStateChangeListener {
|
fast_scroller.addOnScrollStateChangeListener {
|
||||||
controller.lockFilterBar(it)
|
controller.lockFilterBar(it)
|
||||||
}
|
}
|
||||||
@ -120,9 +111,17 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
// Double the distance required to trigger sync
|
// Double the distance required to trigger sync
|
||||||
swipe_refresh.setDistanceToTriggerSync((2 * 64 * resources.displayMetrics.density).toInt())
|
swipe_refresh.setDistanceToTriggerSync((2 * 64 * resources.displayMetrics.density).toInt())
|
||||||
swipe_refresh.setOnRefreshListener {
|
swipe_refresh.setOnRefreshListener {
|
||||||
LibraryUpdateService.start(context, category)
|
val inQueue = LibraryUpdateService.categoryInQueue(category.id)
|
||||||
controller.snack?.dismiss()
|
controller.snack?.dismiss()
|
||||||
controller.snack = swipe_refresh.snack(R.string.updating_category)
|
controller.snack = swipe_refresh.snack(
|
||||||
|
resources.getString(
|
||||||
|
when {
|
||||||
|
inQueue -> R.string.category_already_in_queue
|
||||||
|
LibraryUpdateService.isRunning(context) -> R.string.adding_category_to_queue
|
||||||
|
else -> R.string.updating_category_x
|
||||||
|
}, category.name))
|
||||||
|
if (!inQueue)
|
||||||
|
LibraryUpdateService.start(context, category)
|
||||||
swipe_refresh.isRefreshing = false
|
swipe_refresh.isRefreshing = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -374,7 +374,9 @@
|
|||||||
|
|
||||||
<!-- Library fragment -->
|
<!-- Library fragment -->
|
||||||
<string name="updating_library">Updating library</string>
|
<string name="updating_library">Updating library</string>
|
||||||
<string name="updating_category">Updating category</string>
|
<string name="updating_category_x">Updating %1$s</string>
|
||||||
|
<string name="adding_category_to_queue">Adding %1$s to update queue</string>
|
||||||
|
<string name="category_already_in_queue">%1$s is already in queue</string>
|
||||||
<string name="local_source_badge">Local</string>
|
<string name="local_source_badge">Local</string>
|
||||||
<string name="confirm_manga_deletion">Remove from library?</string>
|
<string name="confirm_manga_deletion">Remove from library?</string>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user