From 90f976b43100d6bfc93915110b9f8a42eadb55b3 Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 30 Jul 2024 09:08:58 +0200 Subject: [PATCH] feat: added ability update the primary course on the learn tab (#20) --- .../openedx/courses/presentation/DashboardGalleryView.kt | 9 +++++++++ .../courses/presentation/DashboardGalleryViewModel.kt | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dashboard/src/main/java/org/openedx/courses/presentation/DashboardGalleryView.kt b/dashboard/src/main/java/org/openedx/courses/presentation/DashboardGalleryView.kt index d208e7a3f..a4d5dd20d 100644 --- a/dashboard/src/main/java/org/openedx/courses/presentation/DashboardGalleryView.kt +++ b/dashboard/src/main/java/org/openedx/courses/presentation/DashboardGalleryView.kt @@ -56,6 +56,7 @@ import androidx.compose.ui.graphics.vector.rememberVectorPainter import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.pluralStringResource @@ -67,6 +68,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Lifecycle import coil.compose.AsyncImage import coil.request.ImageRequest import org.koin.androidx.compose.koinViewModel @@ -119,6 +121,13 @@ fun DashboardGalleryView( val uiState by viewModel.uiState.collectAsState(DashboardGalleryUIState.Loading) val iapUiState by viewModel.iapUiState.collectAsState(IAPUIState.Clear) + val lifecycleState by LocalLifecycleOwner.current.lifecycle.currentStateFlow.collectAsState() + LaunchedEffect(lifecycleState) { + if (lifecycleState == Lifecycle.State.RESUMED) { + viewModel.updateCourses(isUpdating = false) + } + } + DashboardGalleryView( uiMessage = uiMessage, uiState = uiState, diff --git a/dashboard/src/main/java/org/openedx/courses/presentation/DashboardGalleryViewModel.kt b/dashboard/src/main/java/org/openedx/courses/presentation/DashboardGalleryViewModel.kt index 615d16619..53e7bf8e8 100644 --- a/dashboard/src/main/java/org/openedx/courses/presentation/DashboardGalleryViewModel.kt +++ b/dashboard/src/main/java/org/openedx/courses/presentation/DashboardGalleryViewModel.kt @@ -138,11 +138,11 @@ class DashboardGalleryViewModel( } } - fun updateCourses(isIAPFlow: Boolean = false) { + fun updateCourses(isUpdating: Boolean = true, isIAPFlow: Boolean = false) { if (isLoading) { return } - _updating.value = true + _updating.value = isUpdating getCourses(isIAPFlow = isIAPFlow) } @@ -243,7 +243,7 @@ class DashboardGalleryViewModel( iapNotifier.notifier.onEach { event -> when (event) { is UpdateCourseData -> { - updateCourses(true) + updateCourses(isIAPFlow = true) } } }.distinctUntilChanged().launchIn(viewModelScope)