From 4be5197c40981c3d6d12a12fd679764521738900 Mon Sep 17 00:00:00 2001 From: junkfood <69683722+JunkFood02@users.noreply.github.com> Date: Sat, 23 Nov 2024 18:12:57 +0800 Subject: [PATCH] fix(ui): commit diffs before running in background --- .../java/me/ash/reader/ui/page/home/flow/FlowPage.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt b/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt index b0b19b63..feb4804b 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt @@ -48,6 +48,9 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.eventFlow +import androidx.lifecycle.repeatOnLifecycle import androidx.navigation.NavHostController import androidx.paging.compose.collectAsLazyPagingItems import androidx.work.WorkInfo @@ -169,6 +172,13 @@ fun FlowPage( } DisposableEffect(owner) { + scope.launch { + owner.lifecycle.eventFlow.collect { + if (it == Lifecycle.Event.ON_PAUSE) { + flowViewModel.commitDiff() + } + } + } homeViewModel.syncWorkLiveData.observe(owner) { workInfoList -> workInfoList.let { isSyncing = it.any { workInfo -> workInfo.state == WorkInfo.State.RUNNING }