Update Glance v1.0.0-beta01 (#9551)

This commit is contained in:
Ivan Iskandar
2023-05-28 09:59:21 +07:00
committed by GitHub
parent ed5a56be60
commit a458bd9fdb
5 changed files with 35 additions and 35 deletions
@@ -1,29 +1,34 @@
package tachiyomi.presentation.widget
import android.content.Context
import androidx.glance.appwidget.GlanceAppWidgetManager
import androidx.glance.appwidget.updateAll
import androidx.lifecycle.LifecycleCoroutineScope
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import logcat.LogPriority
import tachiyomi.core.util.system.logcat
import tachiyomi.domain.updates.interactor.GetUpdates
class TachiyomiWidgetManager(
private val getUpdates: GetUpdates,
private val securityPreferences: SecurityPreferences,
) {
fun Context.init(scope: LifecycleCoroutineScope) {
getUpdates.subscribe(
read = false,
after = UpdatesGridGlanceWidget.DateLimit.timeInMillis,
combine(
getUpdates.subscribe(read = false, after = UpdatesGridGlanceWidget.DateLimit.timeInMillis),
securityPreferences.useAuthenticator().changes(),
transform = { a, _ -> a },
)
.drop(1)
.distinctUntilChanged()
.onEach {
val manager = GlanceAppWidgetManager(this)
if (manager.getGlanceIds(UpdatesGridGlanceWidget::class.java).isNotEmpty()) {
UpdatesGridGlanceWidget().loadData(it)
try {
UpdatesGridGlanceWidget().updateAll(this)
} catch (e: Exception) {
logcat(LogPriority.ERROR, e) { "Failed to update widget" }
}
}
.launchIn(scope)