mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Adjust distinct checker in WidgetManager and run on default dispatcher
Co-authored-by: p
This commit is contained in:
parent
3bddb55385
commit
9b8ab6acc2
1 changed files with 8 additions and 2 deletions
|
@ -4,8 +4,10 @@ import android.content.Context
|
||||||
import androidx.glance.appwidget.updateAll
|
import androidx.glance.appwidget.updateAll
|
||||||
import androidx.lifecycle.LifecycleCoroutineScope
|
import androidx.lifecycle.LifecycleCoroutineScope
|
||||||
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
|
@ -21,9 +23,12 @@ class WidgetManager(
|
||||||
combine(
|
combine(
|
||||||
getUpdates.subscribe(read = false, after = BaseUpdatesGridGlanceWidget.DateLimit.toEpochMilli()),
|
getUpdates.subscribe(read = false, after = BaseUpdatesGridGlanceWidget.DateLimit.toEpochMilli()),
|
||||||
securityPreferences.useAuthenticator().changes(),
|
securityPreferences.useAuthenticator().changes(),
|
||||||
transform = { a, _ -> a },
|
transform = { a, b -> a to b },
|
||||||
)
|
)
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged { old, new ->
|
||||||
|
old.second == new.second &&
|
||||||
|
old.first.map { it.chapterId }.toSet() == new.first.map { it.chapterId }.toSet()
|
||||||
|
}
|
||||||
.onEach {
|
.onEach {
|
||||||
try {
|
try {
|
||||||
UpdatesGridGlanceWidget().updateAll(this)
|
UpdatesGridGlanceWidget().updateAll(this)
|
||||||
|
@ -32,6 +37,7 @@ class WidgetManager(
|
||||||
logcat(LogPriority.ERROR, e) { "Failed to update widget" }
|
logcat(LogPriority.ERROR, e) { "Failed to update widget" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.flowOn(Dispatchers.Default)
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue