Move colors to parameters of dialog state functions

This commit is contained in:
Ensar Sarajčić 2023-10-13 11:15:15 +02:00
parent d9d3928705
commit 4b7c4350d4
3 changed files with 21 additions and 11 deletions

View File

@ -7,6 +7,7 @@ import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.annotation.ColorInt
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
@ -54,7 +55,8 @@ class BrightDisplayActivity : ComponentActivity() {
enableEdgeToEdgeSimple()
setContent {
AppThemeSurface {
val colorPickerDialogState = getColorPickerDialogState()
val brightDisplayColor by preferences.brightDisplayColorFlow.collectAsStateWithLifecycle(preferences.brightDisplayColor)
val colorPickerDialogState = getColorPickerDialogState(brightDisplayColor)
ScreenContent(colorPickerDialogState::show)
}
@ -66,8 +68,10 @@ class BrightDisplayActivity : ComponentActivity() {
}
@Composable
private fun getColorPickerDialogState() = rememberAlertDialogState().apply {
val brightDisplayColor by preferences.brightDisplayColorFlow.collectAsStateWithLifecycle(preferences.brightDisplayColor)
private fun getColorPickerDialogState(
@ColorInt
brightDisplayColor: Int
) = rememberAlertDialogState().apply {
DialogMember {
ColorPickerAlertDialog(
alertDialogState = this,

View File

@ -7,6 +7,7 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.annotation.ColorInt
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@ -42,7 +43,7 @@ class WidgetBrightDisplayConfigureActivity : ComponentActivity() {
val widgetColor by viewModel.widgetColor.collectAsStateWithLifecycle()
val widgetAlpha by viewModel.widgetAlpha.collectAsStateWithLifecycle()
val colorPickerDialogState = getColorPickerDialogState()
val colorPickerDialogState = getColorPickerDialogState(widgetColor)
WidgetConfigureScreen(
widgetDrawable = R.drawable.ic_bright_display_vector,
@ -60,12 +61,14 @@ class WidgetBrightDisplayConfigureActivity : ComponentActivity() {
}
@Composable
private fun getColorPickerDialogState() = rememberAlertDialogState().apply {
val brightDisplayColor by viewModel.widgetColor.collectAsStateWithLifecycle()
private fun getColorPickerDialogState(
@ColorInt
widgetColor: Int
) = rememberAlertDialogState().apply {
DialogMember {
ColorPickerAlertDialog(
alertDialogState = this,
color = brightDisplayColor,
color = widgetColor,
removeDimmedBackground = true,
onActiveColorChange = {},
onButtonPressed = { wasPositivePressed, color ->

View File

@ -7,6 +7,7 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.annotation.ColorInt
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@ -43,7 +44,7 @@ class WidgetTorchConfigureActivity : ComponentActivity() {
val widgetColor by viewModel.widgetColor.collectAsStateWithLifecycle()
val widgetAlpha by viewModel.widgetAlpha.collectAsStateWithLifecycle()
val colorPickerDialogState = getColorPickerDialogState()
val colorPickerDialogState = getColorPickerDialogState(widgetColor)
WidgetConfigureScreen(
widgetDrawable = R.drawable.ic_flashlight_vector,
@ -60,12 +61,14 @@ class WidgetTorchConfigureActivity : ComponentActivity() {
}
@Composable
private fun getColorPickerDialogState() = rememberAlertDialogState().apply {
val brightDisplayColor by viewModel.widgetColor.collectAsStateWithLifecycle()
private fun getColorPickerDialogState(
@ColorInt
widgetColor: Int
) = rememberAlertDialogState().apply {
DialogMember {
ColorPickerAlertDialog(
alertDialogState = this,
color = brightDisplayColor,
color = widgetColor,
removeDimmedBackground = true,
onActiveColorChange = {},
onButtonPressed = { wasPositivePressed, color ->