Skip to content

Commit

Permalink
feat: added ability update the primary course on the learn tab (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
dixidroid authored Jul 30, 2024
1 parent d9f2da8 commit 90f976b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -243,7 +243,7 @@ class DashboardGalleryViewModel(
iapNotifier.notifier.onEach { event ->
when (event) {
is UpdateCourseData -> {
updateCourses(true)
updateCourses(isIAPFlow = true)
}
}
}.distinctUntilChanged().launchIn(viewModelScope)
Expand Down

0 comments on commit 90f976b

Please sign in to comment.