Skip to content

Commit

Permalink
[#541] Handle unstable collections detekt warning
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-conway committed Dec 15, 2023
1 parent be92fe1 commit 391946a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import co.nimblehq.template.compose.ui.models.UiModel
import co.nimblehq.template.compose.ui.showToast
import co.nimblehq.template.compose.ui.theme.AppTheme.dimensions
import co.nimblehq.template.compose.ui.theme.ComposeTheme
import kotlinx.collections.immutable.*
import timber.log.Timber

@Composable
Expand All @@ -33,7 +34,7 @@ fun HomeScreen(
viewModel.error.collectAsEffect { e -> e.showToast(context) }
viewModel.navigator.collectAsEffect { destination -> navigator(destination) }

val uiModels: List<UiModel> by viewModel.uiModels.collectAsStateWithLifecycle()
val uiModels: ImmutableList<UiModel> by viewModel.uiModels.collectAsStateWithLifecycle()

HomeScreenContent(
title = stringResource(id = R.string.app_name),
Expand All @@ -44,7 +45,7 @@ fun HomeScreen(
@Composable
private fun HomeScreenContent(
title: String,
uiModels: List<UiModel>
uiModels: ImmutableList<UiModel>
) {
Column(
modifier = Modifier.fillMaxSize(),
Expand All @@ -67,7 +68,7 @@ private fun HomeScreenPreview() {
ComposeTheme {
HomeScreenContent(
title = stringResource(id = R.string.app_name),
uiModels = listOf(UiModel(1), UiModel(2), UiModel(3))
uiModels = persistentListOf(UiModel(1), UiModel(2), UiModel(3))
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import co.nimblehq.template.compose.ui.models.UiModel
import co.nimblehq.template.compose.ui.models.toUiModel
import co.nimblehq.template.compose.util.DispatchersProvider
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.*
import kotlinx.coroutines.flow.*
import javax.inject.Inject

Expand All @@ -16,15 +17,15 @@ class HomeViewModel @Inject constructor(
useCase: UseCase,
) : BaseViewModel() {

private val _uiModels = MutableStateFlow<List<UiModel>>(emptyList())
private val _uiModels = MutableStateFlow<ImmutableList<UiModel>>(persistentListOf())
val uiModels = _uiModels.asStateFlow()

init {
useCase()
.injectLoading()
.onEach { result ->
val uiModels = result.map { it.toUiModel() }
_uiModels.emit(uiModels)
_uiModels.emit(uiModels.toImmutableList())
}
.flowOn(dispatchersProvider.io)
.catch { e -> _error.emit(e) }
Expand Down

0 comments on commit 391946a

Please sign in to comment.