From 74a9b38fc3afb585b794ab3c99dd46a6d7b28f6e Mon Sep 17 00:00:00 2001 From: droid Date: Thu, 25 Jul 2024 14:34:07 +0200 Subject: [PATCH] feat: added ability update the primary course on the learn tab --- .../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 10c28fc9e..afdf59919 100644 --- a/dashboard/src/main/java/org/openedx/courses/presentation/DashboardGalleryView.kt +++ b/dashboard/src/main/java/org/openedx/courses/presentation/DashboardGalleryView.kt @@ -54,6 +54,7 @@ import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.vector.rememberVectorPainter import androidx.compose.ui.layout.ContentScale 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 @@ -64,6 +65,7 @@ import androidx.compose.ui.tooling.preview.Devices import androidx.compose.ui.tooling.preview.Preview 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 @@ -116,6 +118,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)