feat: added icons for cards

This commit is contained in:
2026-06-22 22:33:11 +03:00
parent d3ef728007
commit bb57ab007c
16 changed files with 455 additions and 80 deletions
@@ -10,6 +10,7 @@ import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -18,10 +19,13 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Switch
@@ -31,7 +35,9 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
@@ -73,13 +79,16 @@ fun CardEditable(
codeType: BarcodeFormat,
onCodeTypeChange: (BarcodeFormat) -> Unit,
color: String?,
onColorChange: (String?) -> Unit
onColorChange: (String?) -> Unit,
icon: String?,
onIconChange: (String?) -> Unit
) {
val context = LocalContext.current
var isCodeTypeDropdownExpanded by rememberSaveable { mutableStateOf(false) }
var isColorEnabled by rememberSaveable { mutableStateOf(color != null) }
var currentColor by rememberSaveable { mutableStateOf(color) }
var currentIcon by rememberSaveable { mutableStateOf(icon) }
val fieldModifier = Modifier.fillMaxWidth()
@@ -118,6 +127,16 @@ fun CardEditable(
}
}
val selectIconLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
) { result ->
if (result.resultCode == Activity.RESULT_OK) {
val icon = result.data?.getStringExtra("icon")
onIconChange(icon)
}
}
OutlinedTextField(
value = cardName,
onValueChange = onCardNameChange,
@@ -221,6 +240,29 @@ fun CardEditable(
}
)
}
AdaptiveButton(
modifier = Modifier.fillMaxWidth().height(64.dp),
contentPadding = PaddingValues(horizontal = 0.dp),
onClick = {
val intent = Intent(context, SelectIconActivity::class.java)
selectIconLauncher.launch(intent)
}
) {
Row(
modifier = Modifier
.fillMaxSize()
.background(Color.Transparent)
.padding(horizontal = 8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
CardIcon(if (icon == null) null else base64ToImageBitmap(icon), MaterialTheme.colorScheme.primary)
Text(stringResource(R.string.do_select_icon))
}
}
}
@Composable
@@ -229,6 +271,7 @@ fun AddCard(innerPadding: PaddingValues, getDbFun: () -> DbHelper) {
var codeValue by rememberSaveable { mutableStateOf("") }
var codeType by rememberSaveable { mutableStateOf(BarcodeFormat.QR_CODE) }
var color by rememberSaveable { mutableStateOf<String?>(null) }
var icon by rememberSaveable { mutableStateOf<String?>(null) }
val context = LocalActivity.current
@@ -248,7 +291,9 @@ fun AddCard(innerPadding: PaddingValues, getDbFun: () -> DbHelper) {
codeType = codeType,
onCodeTypeChange = { codeType = it },
color = color,
onColorChange = { color = it }
onColorChange = { color = it },
icon = icon,
onIconChange = { icon = it }
)
AdaptiveButton(
@@ -259,7 +304,7 @@ fun AddCard(innerPadding: PaddingValues, getDbFun: () -> DbHelper) {
val err = checkCardData(cardName, codeValue)
if (err == null) {
getDbFun().addCard(cardName, codeValue, codeType, color)
getDbFun().addCard(cardName, codeValue, codeType, color, icon)
context!!.finish()
} else {
Toast.makeText(context, context!!.getString(err), Toast.LENGTH_SHORT).show()
@@ -278,6 +323,7 @@ fun EditCard(cardInfo: CardInfo, innerPadding: PaddingValues, getDbFun: () -> Db
var codeValue by rememberSaveable { mutableStateOf(cardInfo.codeValue) }
var codeType by rememberSaveable { mutableStateOf(cardInfo.codeType) }
var color by rememberSaveable { mutableStateOf(cardInfo.color) }
var icon by rememberSaveable { mutableStateOf(cardInfo.icon) }
val context = LocalActivity.current
@@ -297,7 +343,9 @@ fun EditCard(cardInfo: CardInfo, innerPadding: PaddingValues, getDbFun: () -> Db
codeType = codeType,
onCodeTypeChange = { codeType = it },
color = color,
onColorChange = { color = it }
onColorChange = { color = it },
icon = icon,
onIconChange = { icon = it }
)
AdaptiveButton(
@@ -308,7 +356,7 @@ fun EditCard(cardInfo: CardInfo, innerPadding: PaddingValues, getDbFun: () -> Db
val err = checkCardData(cardName, codeValue)
if (err == null) {
getDbFun().editCard(cardInfo.id, cardName, codeValue, codeType, color)
getDbFun().editCard(cardInfo.id, cardName, codeValue, codeType, color, icon)
context!!.finish()
} else {
Toast.makeText(context, context!!.getString(err), Toast.LENGTH_SHORT).show()