From 9b8ab6acc25a5f99c9c5eebf9cc250975931c57c Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Sat, 12 Oct 2024 05:09:51 +0600 Subject: [PATCH] Adjust distinct checker in WidgetManager and run on default dispatcher Co-authored-by: p --- .../tachiyomi/presentation/widget/WidgetManager.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/presentation-widget/src/main/java/tachiyomi/presentation/widget/WidgetManager.kt b/presentation-widget/src/main/java/tachiyomi/presentation/widget/WidgetManager.kt index eda0ff0a1..f54ab702c 100644 --- a/presentation-widget/src/main/java/tachiyomi/presentation/widget/WidgetManager.kt +++ b/presentation-widget/src/main/java/tachiyomi/presentation/widget/WidgetManager.kt @@ -4,8 +4,10 @@ import android.content.Context import androidx.glance.appwidget.updateAll import androidx.lifecycle.LifecycleCoroutineScope import eu.kanade.tachiyomi.core.security.SecurityPreferences +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import logcat.LogPriority @@ -21,9 +23,12 @@ class WidgetManager( combine( getUpdates.subscribe(read = false, after = BaseUpdatesGridGlanceWidget.DateLimit.toEpochMilli()), 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 { try { UpdatesGridGlanceWidget().updateAll(this) @@ -32,6 +37,7 @@ class WidgetManager( logcat(LogPriority.ERROR, e) { "Failed to update widget" } } } + .flowOn(Dispatchers.Default) .launchIn(scope) } }