feat: moved card color choosing to new screen

This commit is contained in:
2026-06-21 14:07:12 +03:00
parent 1272e87ccd
commit df95702247
4 changed files with 89 additions and 18 deletions
@@ -1,5 +1,7 @@
package ru.omni_devel.cards
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
@@ -7,6 +9,7 @@ import androidx.activity.compose.LocalActivity
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -70,6 +73,68 @@ class EditCardActivity : ComponentActivity() {
}
}
class SelectColorActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
val currentColor = intent.getStringExtra("currentColor")
setContent {
OmniCardsTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
EditColorPage(innerPadding, currentColor)
}
}
}
}
}
@Composable
fun EditColorPage(innerPadding: PaddingValues, currentColor: String?) {
val activityContext = LocalActivity.current
var color by rememberSaveable { mutableStateOf(currentColor) }
val colorPickerController = rememberColorPickerController()
Page(
stringResource(R.string.choosing_color),
innerPadding
) {
Column(
modifier = Modifier.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
HsvColorPicker(
modifier = Modifier
.fillMaxWidth()
.height(450.dp)
.padding(10.dp),
initialColor = currentColor?.let { Color(it.toColorInt()) },
controller = colorPickerController,
onColorChanged = { colorEnvelope: ColorEnvelope ->
color = "#${colorEnvelope.hexCode.substring(2)}"
}
)
Button(
modifier = Modifier.fillMaxWidth(),
onClick = {
val resultIntent = Intent()
resultIntent.putExtra("color", color)
activityContext!!.setResult(Activity.RESULT_OK, resultIntent)
activityContext.finish()
}
) {
Text(stringResource(R.string.do_save))
}
}
}
}
@Composable
fun CardEditable(
cardName: String,
@@ -84,10 +149,8 @@ fun CardEditable(
val context = LocalContext.current
var isCodeTypeDropdownExpanded by rememberSaveable { mutableStateOf(false) }
var isColorPickerExpanded by rememberSaveable { mutableStateOf(false) }
var isColorEnabled by rememberSaveable { mutableStateOf(color != null) }
val colorPickerController = rememberColorPickerController()
var currentColor by rememberSaveable { mutableStateOf(color) }
val fieldModifier = Modifier.fillMaxWidth()
@@ -105,6 +168,17 @@ fun CardEditable(
}
}
val editColorLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
) { result ->
if (result.resultCode == Activity.RESULT_OK) {
val color = result.data?.getStringExtra("color")
currentColor = color
onColorChange(color)
}
}
OutlinedTextField(
value = cardName,
onValueChange = onCardNameChange,
@@ -177,11 +251,16 @@ fun CardEditable(
Button(
enabled = isColorEnabled,
onClick = {
isColorPickerExpanded = !isColorPickerExpanded
val intent = Intent(context, SelectColorActivity::class.java)
intent.putExtra("currentColor", currentColor)
editColorLauncher.launch(intent)
}
) {
Text(stringResource(R.string.do_choose_color))
}
Switch(
checked = isColorEnabled,
onCheckedChange = {
@@ -193,20 +272,6 @@ fun CardEditable(
}
)
}
if (isColorPickerExpanded && isColorEnabled) {
HsvColorPicker(
modifier = Modifier
.fillMaxWidth()
.height(450.dp)
.padding(10.dp),
initialColor = color?.let { Color(it.toColorInt()) },
controller = colorPickerController,
onColorChanged = { colorEnvelope: ColorEnvelope ->
onColorChange("#${colorEnvelope.hexCode.substring(2)}")
}
)
}
}
@Composable