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 Nov 3, 2023
1 parent 429fa8f commit 5662c4f
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 @@ -18,6 +18,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 @@ -29,7 +30,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 @@ -40,7 +41,7 @@ fun HomeScreen(
@Composable
private fun HomeScreenContent(
title: String,
uiModels: List<UiModel>
uiModels: ImmutableList<UiModel>
) {
Column(
modifier = Modifier.fillMaxSize(),
Expand All @@ -63,7 +64,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 5662c4f

Please sign in to comment.