From afaff5edea23b084fbe04983b64549e1a06c488d Mon Sep 17 00:00:00 2001 From: Drjacky Date: Sat, 15 Jun 2024 20:25:27 +0100 Subject: [PATCH] Fix detekt mutable params --- .../products/productlist/ProductRowView.kt | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/presentation/src/main/kotlin/app/web/drjackycv/presentation/products/productlist/ProductRowView.kt b/presentation/src/main/kotlin/app/web/drjackycv/presentation/products/productlist/ProductRowView.kt index 502d728..e14c12f 100644 --- a/presentation/src/main/kotlin/app/web/drjackycv/presentation/products/productlist/ProductRowView.kt +++ b/presentation/src/main/kotlin/app/web/drjackycv/presentation/products/productlist/ProductRowView.kt @@ -21,7 +21,6 @@ import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.ExperimentalComposeUiApi @@ -58,7 +57,7 @@ fun ProductRowView( ) { val defaultColor = MaterialTheme.colors.surface val cardColor = remember { mutableStateOf(defaultColor) } - val animatedCardColor = animateColorAsState(cardColor.value) + val animatedCardColor = animateColorAsState(cardColor.value, label = "animatedCardColor") val isDark = remember { mutableStateOf(MainActivity.ThemeState.darkModeState.value) } Card( @@ -95,11 +94,12 @@ fun ProductRowView( when (imagePainter.state) { is AsyncImagePainter.State.Success -> { - ChangeCardColor( + val newCardColor = changeCardColor( imagePainter = imagePainter, - cardColor = cardColor, - isDark = isDark + cardColor = cardColor.value, + isDark = isDark.value ) + cardColor.value = newCardColor } is AsyncImagePainter.State.Loading -> { CircularProgressIndicator(modifier = Modifier.padding(8.dp)) @@ -138,13 +138,14 @@ fun ProductRowView( } @Composable -private fun ChangeCardColor( +private fun changeCardColor( imagePainter: AsyncImagePainter, - cardColor: MutableState, - isDark: MutableState -) { + cardColor: Color, + isDark: Boolean +): Color { val context = LocalContext.current val imageLoader = ImageLoader(context) + var newCardColor = cardColor LaunchedEffect(key1 = imagePainter) { val result = imageLoader.execute(imagePainter.request) @@ -152,14 +153,14 @@ private fun ChangeCardColor( if (result is SuccessResult) { val bitmap = (result.drawable as BitmapDrawable).bitmap - if (isDark.value) { + if (isDark) { val vibrant = Palette.from(bitmap) .generate() //.vibrantSwatch .darkVibrantSwatch vibrant?.let { - cardColor.value = Color(it.rgb) + newCardColor = Color(it.rgb) } } else { val vibrant = Palette.from(bitmap) @@ -168,11 +169,13 @@ private fun ChangeCardColor( .lightVibrantSwatch vibrant?.let { - cardColor.value = Color(it.rgb) + newCardColor = Color(it.rgb) } } } } + + return newCardColor }