Favorites sync show currently processing title after 5 seconds in case of issues
This commit is contained in:
parent
9af351e0dd
commit
104e200b4a
@ -50,9 +50,12 @@ import exh.source.mangaDexSourceIds
|
||||
import exh.source.nHentaiSourceIds
|
||||
import exh.ui.LoaderManager
|
||||
import exh.util.milliseconds
|
||||
import exh.util.seconds
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.mapLatest
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.sample
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
@ -697,7 +700,7 @@ class LibraryController(
|
||||
favoritesSyncJob =
|
||||
presenter.favoritesSync.status
|
||||
.sample(100.milliseconds)
|
||||
.onEach {
|
||||
.mapLatest {
|
||||
updateSyncStatus(it)
|
||||
}
|
||||
.launchIn(viewScope)
|
||||
@ -764,7 +767,7 @@ class LibraryController(
|
||||
activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
|
||||
private fun updateSyncStatus(status: FavoritesSyncStatus) {
|
||||
private suspend fun updateSyncStatus(status: FavoritesSyncStatus) {
|
||||
when (status) {
|
||||
is FavoritesSyncStatus.Idle -> {
|
||||
releaseSyncLocks()
|
||||
@ -832,6 +835,10 @@ class LibraryController(
|
||||
}
|
||||
}
|
||||
oldSyncStatus = status
|
||||
if (status is FavoritesSyncStatus.Processing && status.delayedMessage != null) {
|
||||
delay(5.seconds)
|
||||
favSyncDialog?.message(text = status.delayedMessage)
|
||||
}
|
||||
}
|
||||
|
||||
fun startReading(manga: Manga, adapter: LibraryCategoryAdapter) {
|
||||
|
@ -365,7 +365,8 @@ class FavoritesSyncHelper(val context: Context) {
|
||||
status.value = FavoritesSyncStatus.Processing(
|
||||
context.getString(R.string.favorites_sync_add_to_local, index + 1, changeSet.added.size),
|
||||
needWarnThrottle(),
|
||||
context
|
||||
context,
|
||||
it.title
|
||||
)
|
||||
|
||||
throttleManager.throttle()
|
||||
@ -441,12 +442,14 @@ sealed class FavoritesSyncStatus(val message: String) {
|
||||
BadLibraryState(context.getString(R.string.favorites_sync_manga_in_multiple_categories, manga.title, categories.joinToString { it.name }))
|
||||
}
|
||||
class Initializing(context: Context) : FavoritesSyncStatus(context.getString(R.string.favorites_sync_initializing))
|
||||
class Processing(message: String, isThrottle: Boolean = false, context: Context) : FavoritesSyncStatus(
|
||||
class Processing(message: String, isThrottle: Boolean = false, context: Context, val title: String? = null) : FavoritesSyncStatus(
|
||||
if (isThrottle) {
|
||||
context.getString(R.string.favorites_sync_processing_throttle, message)
|
||||
} else {
|
||||
message
|
||||
}
|
||||
)
|
||||
) {
|
||||
val delayedMessage get() = if (title != null) this.message + "\n\n" + title else null
|
||||
}
|
||||
class CompleteWithErrors(messages: List<String>) : FavoritesSyncStatus(messages.joinToString("\n"))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user