Migrate color picker in `WidgetTorchConfigureActivity` to compose
This commit is contained in:
parent
a1bdd65dbc
commit
2c99bd9c06
|
@ -7,11 +7,14 @@ import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
|
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.extensions.enableEdgeToEdgeSimple
|
import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple
|
||||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||||
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
import com.simplemobiletools.commons.dialogs.ColorPickerAlertDialog
|
||||||
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
|
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
|
||||||
import com.simplemobiletools.flashlight.R
|
import com.simplemobiletools.flashlight.R
|
||||||
import com.simplemobiletools.flashlight.activities.viewmodel.WidgetConfigureViewModel
|
import com.simplemobiletools.flashlight.activities.viewmodel.WidgetConfigureViewModel
|
||||||
|
@ -41,12 +44,16 @@ 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 {
|
||||||
|
ColorPicker(this)
|
||||||
|
}
|
||||||
|
|
||||||
WidgetConfigureScreen(
|
WidgetConfigureScreen(
|
||||||
widgetDrawable = R.drawable.ic_flashlight_vector,
|
widgetDrawable = R.drawable.ic_flashlight_vector,
|
||||||
widgetColor = widgetColor,
|
widgetColor = widgetColor,
|
||||||
widgetAlpha = widgetAlpha,
|
widgetAlpha = widgetAlpha,
|
||||||
onSliderChanged = viewModel::changeAlpha,
|
onSliderChanged = viewModel::changeAlpha,
|
||||||
onColorPressed = ::pickBackgroundColor,
|
onColorPressed = colorPickerDialogState::show,
|
||||||
onSavePressed = ::saveConfig
|
onSavePressed = ::saveConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -55,6 +62,26 @@ class WidgetTorchConfigureActivity : ComponentActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ColorPicker(
|
||||||
|
alertDialogState: AlertDialogState
|
||||||
|
) {
|
||||||
|
val brightDisplayColor by viewModel.widgetColor.collectAsStateWithLifecycle()
|
||||||
|
alertDialogState.DialogMember {
|
||||||
|
ColorPickerAlertDialog(
|
||||||
|
alertDialogState = alertDialogState,
|
||||||
|
color = brightDisplayColor,
|
||||||
|
removeDimmedBackground = true,
|
||||||
|
onActiveColorChange = {},
|
||||||
|
onButtonPressed = { wasPositivePressed, color ->
|
||||||
|
if (wasPositivePressed) {
|
||||||
|
viewModel.updateColor(color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
window.decorView.setBackgroundColor(0)
|
window.decorView.setBackgroundColor(0)
|
||||||
|
@ -71,14 +98,6 @@ class WidgetTorchConfigureActivity : ComponentActivity() {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun pickBackgroundColor() {
|
|
||||||
ColorPickerDialog(this, viewModel.widgetColor.value) { wasPositivePressed, color ->
|
|
||||||
if (wasPositivePressed) {
|
|
||||||
viewModel.updateColor(color)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun requestWidgetUpdate() {
|
private fun requestWidgetUpdate() {
|
||||||
Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetTorchProvider::class.java).apply {
|
Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetTorchProvider::class.java).apply {
|
||||||
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(viewModel.widgetId.value))
|
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(viewModel.widgetId.value))
|
||||||
|
|
Loading…
Reference in New Issue