mirror of
https://github.com/SimpleMobileTools/Simple-Flashlight.git
synced 2025-04-26 16:08:43 +02:00
Clean up color picker creation code
This commit is contained in:
parent
2c99bd9c06
commit
c825bf16a2
@ -2,7 +2,6 @@ package com.simplemobiletools.flashlight.activities
|
|||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.graphics.Color
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
@ -16,7 +15,6 @@ import androidx.core.view.WindowCompat
|
|||||||
import androidx.lifecycle.AndroidViewModel
|
import androidx.lifecycle.AndroidViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.lifecycle.viewModelScope
|
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.alert_dialog.rememberAlertDialogState
|
||||||
import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple
|
import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple
|
||||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||||
@ -56,9 +54,7 @@ class BrightDisplayActivity : ComponentActivity() {
|
|||||||
enableEdgeToEdgeSimple()
|
enableEdgeToEdgeSimple()
|
||||||
setContent {
|
setContent {
|
||||||
AppThemeSurface {
|
AppThemeSurface {
|
||||||
val colorPickerDialogState = rememberAlertDialogState().apply {
|
val colorPickerDialogState = getColorPickerDialogState()
|
||||||
ColorPicker(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
ScreenContent(colorPickerDialogState::show)
|
ScreenContent(colorPickerDialogState::show)
|
||||||
}
|
}
|
||||||
@ -70,13 +66,11 @@ class BrightDisplayActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ColorPicker(
|
private fun getColorPickerDialogState() = rememberAlertDialogState().apply {
|
||||||
alertDialogState: AlertDialogState
|
|
||||||
) {
|
|
||||||
val brightDisplayColor by preferences.brightDisplayColorFlow.collectAsStateWithLifecycle(preferences.brightDisplayColor)
|
val brightDisplayColor by preferences.brightDisplayColorFlow.collectAsStateWithLifecycle(preferences.brightDisplayColor)
|
||||||
alertDialogState.DialogMember {
|
DialogMember {
|
||||||
ColorPickerAlertDialog(
|
ColorPickerAlertDialog(
|
||||||
alertDialogState = alertDialogState,
|
alertDialogState = this,
|
||||||
color = brightDisplayColor,
|
color = brightDisplayColor,
|
||||||
removeDimmedBackground = true,
|
removeDimmedBackground = true,
|
||||||
onActiveColorChange = viewModel::updateBackgroundColor,
|
onActiveColorChange = viewModel::updateBackgroundColor,
|
||||||
|
@ -43,9 +43,7 @@ class WidgetBrightDisplayConfigureActivity : ComponentActivity() {
|
|||||||
val widgetColor by viewModel.widgetColor.collectAsStateWithLifecycle()
|
val widgetColor by viewModel.widgetColor.collectAsStateWithLifecycle()
|
||||||
val widgetAlpha by viewModel.widgetAlpha.collectAsStateWithLifecycle()
|
val widgetAlpha by viewModel.widgetAlpha.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
val colorPickerDialogState = rememberAlertDialogState().apply {
|
val colorPickerDialogState = getColorPickerDialogState()
|
||||||
ColorPicker(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
WidgetConfigureScreen(
|
WidgetConfigureScreen(
|
||||||
widgetDrawable = R.drawable.ic_bright_display_vector,
|
widgetDrawable = R.drawable.ic_bright_display_vector,
|
||||||
@ -63,13 +61,11 @@ class WidgetBrightDisplayConfigureActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ColorPicker(
|
private fun getColorPickerDialogState() = rememberAlertDialogState().apply {
|
||||||
alertDialogState: AlertDialogState
|
|
||||||
) {
|
|
||||||
val brightDisplayColor by viewModel.widgetColor.collectAsStateWithLifecycle()
|
val brightDisplayColor by viewModel.widgetColor.collectAsStateWithLifecycle()
|
||||||
alertDialogState.DialogMember {
|
DialogMember {
|
||||||
ColorPickerAlertDialog(
|
ColorPickerAlertDialog(
|
||||||
alertDialogState = alertDialogState,
|
alertDialogState = this,
|
||||||
color = brightDisplayColor,
|
color = brightDisplayColor,
|
||||||
removeDimmedBackground = true,
|
removeDimmedBackground = true,
|
||||||
onActiveColorChange = {},
|
onActiveColorChange = {},
|
||||||
|
@ -10,7 +10,6 @@ import androidx.activity.viewModels
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
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.alert_dialog.rememberAlertDialogState
|
||||||
import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple
|
import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple
|
||||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||||
@ -44,9 +43,7 @@ class WidgetTorchConfigureActivity : ComponentActivity() {
|
|||||||
val widgetColor by viewModel.widgetColor.collectAsStateWithLifecycle()
|
val widgetColor by viewModel.widgetColor.collectAsStateWithLifecycle()
|
||||||
val widgetAlpha by viewModel.widgetAlpha.collectAsStateWithLifecycle()
|
val widgetAlpha by viewModel.widgetAlpha.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
val colorPickerDialogState = rememberAlertDialogState().apply {
|
val colorPickerDialogState = getColorPickerDialogState()
|
||||||
ColorPicker(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
WidgetConfigureScreen(
|
WidgetConfigureScreen(
|
||||||
widgetDrawable = R.drawable.ic_flashlight_vector,
|
widgetDrawable = R.drawable.ic_flashlight_vector,
|
||||||
@ -63,13 +60,11 @@ class WidgetTorchConfigureActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ColorPicker(
|
private fun getColorPickerDialogState() = rememberAlertDialogState().apply {
|
||||||
alertDialogState: AlertDialogState
|
|
||||||
) {
|
|
||||||
val brightDisplayColor by viewModel.widgetColor.collectAsStateWithLifecycle()
|
val brightDisplayColor by viewModel.widgetColor.collectAsStateWithLifecycle()
|
||||||
alertDialogState.DialogMember {
|
DialogMember {
|
||||||
ColorPickerAlertDialog(
|
ColorPickerAlertDialog(
|
||||||
alertDialogState = alertDialogState,
|
alertDialogState = this,
|
||||||
color = brightDisplayColor,
|
color = brightDisplayColor,
|
||||||
removeDimmedBackground = true,
|
removeDimmedBackground = true,
|
||||||
onActiveColorChange = {},
|
onActiveColorChange = {},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user