Clean up color picker creation code

This commit is contained in:
Ensar Sarajčić 2023-10-05 14:36:20 +02:00
parent 2c99bd9c06
commit c825bf16a2
3 changed files with 12 additions and 27 deletions

View File

@ -2,7 +2,6 @@ package com.simplemobiletools.flashlight.activities
import android.app.Application
import android.content.pm.ActivityInfo
import android.graphics.Color
import android.os.Bundle
import android.view.WindowManager
import androidx.activity.ComponentActivity
@ -16,7 +15,6 @@ import androidx.core.view.WindowCompat
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewModelScope
import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState
import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState
import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
@ -56,9 +54,7 @@ class BrightDisplayActivity : ComponentActivity() {
enableEdgeToEdgeSimple()
setContent {
AppThemeSurface {
val colorPickerDialogState = rememberAlertDialogState().apply {
ColorPicker(this)
}
val colorPickerDialogState = getColorPickerDialogState()
ScreenContent(colorPickerDialogState::show)
}
@ -70,13 +66,11 @@ class BrightDisplayActivity : ComponentActivity() {
}
@Composable
private fun ColorPicker(
alertDialogState: AlertDialogState
) {
private fun getColorPickerDialogState() = rememberAlertDialogState().apply {
val brightDisplayColor by preferences.brightDisplayColorFlow.collectAsStateWithLifecycle(preferences.brightDisplayColor)
alertDialogState.DialogMember {
DialogMember {
ColorPickerAlertDialog(
alertDialogState = alertDialogState,
alertDialogState = this,
color = brightDisplayColor,
removeDimmedBackground = true,
onActiveColorChange = viewModel::updateBackgroundColor,

View File

@ -43,9 +43,7 @@ class WidgetBrightDisplayConfigureActivity : ComponentActivity() {
val widgetColor by viewModel.widgetColor.collectAsStateWithLifecycle()
val widgetAlpha by viewModel.widgetAlpha.collectAsStateWithLifecycle()
val colorPickerDialogState = rememberAlertDialogState().apply {
ColorPicker(this)
}
val colorPickerDialogState = getColorPickerDialogState()
WidgetConfigureScreen(
widgetDrawable = R.drawable.ic_bright_display_vector,
@ -63,13 +61,11 @@ class WidgetBrightDisplayConfigureActivity : ComponentActivity() {
}
@Composable
private fun ColorPicker(
alertDialogState: AlertDialogState
) {
private fun getColorPickerDialogState() = rememberAlertDialogState().apply {
val brightDisplayColor by viewModel.widgetColor.collectAsStateWithLifecycle()
alertDialogState.DialogMember {
DialogMember {
ColorPickerAlertDialog(
alertDialogState = alertDialogState,
alertDialogState = this,
color = brightDisplayColor,
removeDimmedBackground = true,
onActiveColorChange = {},

View File

@ -10,7 +10,6 @@ import androidx.activity.viewModels
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState
import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState
import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
@ -44,9 +43,7 @@ class WidgetTorchConfigureActivity : ComponentActivity() {
val widgetColor by viewModel.widgetColor.collectAsStateWithLifecycle()
val widgetAlpha by viewModel.widgetAlpha.collectAsStateWithLifecycle()
val colorPickerDialogState = rememberAlertDialogState().apply {
ColorPicker(this)
}
val colorPickerDialogState = getColorPickerDialogState()
WidgetConfigureScreen(
widgetDrawable = R.drawable.ic_flashlight_vector,
@ -63,13 +60,11 @@ class WidgetTorchConfigureActivity : ComponentActivity() {
}
@Composable
private fun ColorPicker(
alertDialogState: AlertDialogState
) {
private fun getColorPickerDialogState() = rememberAlertDialogState().apply {
val brightDisplayColor by viewModel.widgetColor.collectAsStateWithLifecycle()
alertDialogState.DialogMember {
DialogMember {
ColorPickerAlertDialog(
alertDialogState = alertDialogState,
alertDialogState = this,
color = brightDisplayColor,
removeDimmedBackground = true,
onActiveColorChange = {},