From c825bf16a211c0e105dbec0cd6c534b1b4d9d58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 5 Oct 2023 14:36:20 +0200 Subject: [PATCH] Clean up color picker creation code --- .../flashlight/activities/BrightDisplayActivity.kt | 14 ++++---------- .../WidgetBrightDisplayConfigureActivity.kt | 12 ++++-------- .../activities/WidgetTorchConfigureActivity.kt | 13 ++++--------- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/BrightDisplayActivity.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/BrightDisplayActivity.kt index fbc7cc4..2635e77 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/BrightDisplayActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/BrightDisplayActivity.kt @@ -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, diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetBrightDisplayConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetBrightDisplayConfigureActivity.kt index 0a4dab5..a27703f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetBrightDisplayConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetBrightDisplayConfigureActivity.kt @@ -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 = {}, diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetTorchConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetTorchConfigureActivity.kt index fb25845..b16bba3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetTorchConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetTorchConfigureActivity.kt @@ -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 = {},