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
3 changed files with 25 additions and 13 deletions
|
@ -131,6 +131,10 @@ class LibraryUpdateService(
|
|||
|
||||
private val mangaToUpdate = mutableListOf<LibraryManga>()
|
||||
|
||||
private val categoryIds = mutableSetOf<Int>()
|
||||
|
||||
fun categoryInQueue(id: Int?) = categoryIds.contains(id)
|
||||
|
||||
/**
|
||||
* Key that defines what should be updated.
|
||||
*/
|
||||
|
@ -158,7 +162,10 @@ class LibraryUpdateService(
|
|||
if (!isRunning(context)) {
|
||||
val intent = Intent(context, LibraryUpdateService::class.java).apply {
|
||||
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) {
|
||||
context.startService(intent)
|
||||
|
@ -168,6 +175,7 @@ class LibraryUpdateService(
|
|||
}
|
||||
else {
|
||||
if (target == Target.CHAPTERS) category?.id?.let {
|
||||
categoryIds.add(it)
|
||||
val preferences: PreferencesHelper = Injekt.get()
|
||||
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault()
|
||||
addManga(getMangaToUpdate(it, target).sortedWith(
|
||||
|
@ -206,6 +214,7 @@ class LibraryUpdateService(
|
|||
db.getLibraryMangas().executeAsBlocking().filter { it.category == categoryId }
|
||||
else {
|
||||
val categoriesToUpdate = preferences.libraryUpdateCategories().getOrDefault().map(String::toInt)
|
||||
categoryIds.addAll(categoriesToUpdate)
|
||||
if (categoriesToUpdate.isNotEmpty())
|
||||
db.getLibraryMangas().executeAsBlocking()
|
||||
.filter { it.category in categoriesToUpdate }
|
||||
|
@ -250,6 +259,7 @@ class LibraryUpdateService(
|
|||
override fun onDestroy() {
|
||||
subscription?.unsubscribe()
|
||||
mangaToUpdate.clear()
|
||||
categoryIds.clear()
|
||||
if (wakeLock.isHeld) {
|
||||
wakeLock.release()
|
||||
}
|
||||
|
@ -315,6 +325,7 @@ class LibraryUpdateService(
|
|||
job = GlobalScope.launch(Dispatchers.IO, CoroutineStart.DEFAULT) {
|
||||
updateChaptersJob()
|
||||
mangaToUpdate.clear()
|
||||
categoryIds.clear()
|
||||
stopSelf(startId)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,15 +97,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||
swipe_refresh.addView(recycler)
|
||||
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 {
|
||||
controller.lockFilterBar(it)
|
||||
}
|
||||
|
@ -120,9 +111,17 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||
// Double the distance required to trigger sync
|
||||
swipe_refresh.setDistanceToTriggerSync((2 * 64 * resources.displayMetrics.density).toInt())
|
||||
swipe_refresh.setOnRefreshListener {
|
||||
LibraryUpdateService.start(context, category)
|
||||
val inQueue = LibraryUpdateService.categoryInQueue(category.id)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -374,7 +374,9 @@
|
|||
|
||||
<!-- Library fragment -->
|
||||
<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="confirm_manga_deletion">Remove from library?</string>
|
||||
|
||||
|
|
Reference in a new issue