forked from omni/OmniCards
feat: moved card color choosing to new screen
This commit is contained in:
@@ -16,6 +16,10 @@
|
|||||||
android:name=".EditCardActivity"
|
android:name=".EditCardActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:theme="@style/Theme.OmniCards" />
|
android:theme="@style/Theme.OmniCards" />
|
||||||
|
<activity
|
||||||
|
android:name=".SelectColorActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:theme="@style/Theme.OmniCards" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".ShowCardActivity"
|
android:name=".ShowCardActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package ru.omni_devel.cards
|
package ru.omni_devel.cards
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
@@ -7,6 +9,7 @@ import androidx.activity.compose.LocalActivity
|
|||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
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
|
@Composable
|
||||||
fun CardEditable(
|
fun CardEditable(
|
||||||
cardName: String,
|
cardName: String,
|
||||||
@@ -84,10 +149,8 @@ fun CardEditable(
|
|||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
var isCodeTypeDropdownExpanded by rememberSaveable { mutableStateOf(false) }
|
var isCodeTypeDropdownExpanded by rememberSaveable { mutableStateOf(false) }
|
||||||
var isColorPickerExpanded by rememberSaveable { mutableStateOf(false) }
|
|
||||||
var isColorEnabled by rememberSaveable { mutableStateOf(color != null) }
|
var isColorEnabled by rememberSaveable { mutableStateOf(color != null) }
|
||||||
|
var currentColor by rememberSaveable { mutableStateOf(color) }
|
||||||
val colorPickerController = rememberColorPickerController()
|
|
||||||
|
|
||||||
val fieldModifier = Modifier.fillMaxWidth()
|
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(
|
OutlinedTextField(
|
||||||
value = cardName,
|
value = cardName,
|
||||||
onValueChange = onCardNameChange,
|
onValueChange = onCardNameChange,
|
||||||
@@ -177,11 +251,16 @@ fun CardEditable(
|
|||||||
Button(
|
Button(
|
||||||
enabled = isColorEnabled,
|
enabled = isColorEnabled,
|
||||||
onClick = {
|
onClick = {
|
||||||
isColorPickerExpanded = !isColorPickerExpanded
|
val intent = Intent(context, SelectColorActivity::class.java)
|
||||||
|
|
||||||
|
intent.putExtra("currentColor", currentColor)
|
||||||
|
|
||||||
|
editColorLauncher.launch(intent)
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Text(stringResource(R.string.do_choose_color))
|
Text(stringResource(R.string.do_choose_color))
|
||||||
}
|
}
|
||||||
|
|
||||||
Switch(
|
Switch(
|
||||||
checked = isColorEnabled,
|
checked = isColorEnabled,
|
||||||
onCheckedChange = {
|
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
|
@Composable
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
<string name="scan_your_card">Отсканируйте вашу карту</string>
|
<string name="scan_your_card">Отсканируйте вашу карту</string>
|
||||||
<string name="card_code_type">Тип кода карты</string>
|
<string name="card_code_type">Тип кода карты</string>
|
||||||
<string name="do_choose_color">Выбрать цвет</string>
|
<string name="do_choose_color">Выбрать цвет</string>
|
||||||
|
<string name="choosing_color">Выбор цвета</string>
|
||||||
<string name="card_name_should_not_be_empty">Имя карты не должно быть пустым</string>
|
<string name="card_name_should_not_be_empty">Имя карты не должно быть пустым</string>
|
||||||
<string name="card_value_should_not_be_empty">Значение карты не должно быть пустым</string>
|
<string name="card_value_should_not_be_empty">Значение карты не должно быть пустым</string>
|
||||||
<string name="name_must_be_shorter_than_32_symbols">Имя карты должно быть короче 32 символов</string>
|
<string name="name_must_be_shorter_than_32_symbols">Имя карты должно быть короче 32 символов</string>
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
<string name="scan_your_card">Scan your card</string>
|
<string name="scan_your_card">Scan your card</string>
|
||||||
<string name="card_code_type">Card code type</string>
|
<string name="card_code_type">Card code type</string>
|
||||||
<string name="do_choose_color">Choose color</string>
|
<string name="do_choose_color">Choose color</string>
|
||||||
|
<string name="choosing_color">Choosing color</string>
|
||||||
<string name="card_name_should_not_be_empty">Card name must not be empty</string>
|
<string name="card_name_should_not_be_empty">Card name must not be empty</string>
|
||||||
<string name="card_value_should_not_be_empty">Card value must not be empty</string>
|
<string name="card_value_should_not_be_empty">Card value must not be empty</string>
|
||||||
<string name="name_must_be_shorter_than_32_symbols">Card name must be shorter than 32 characters</string>
|
<string name="name_must_be_shorter_than_32_symbols">Card name must be shorter than 32 characters</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user