feat: added templates
This commit is contained in:
@@ -77,85 +77,6 @@ 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
|
||||
val configuration = LocalConfiguration.current
|
||||
|
||||
val screenHeight = configuration.screenHeightDp.dp
|
||||
val isPortrait = configuration.orientation == Configuration.ORIENTATION_PORTRAIT
|
||||
|
||||
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),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
var colorPickerModifier = Modifier
|
||||
.padding(10.dp)
|
||||
|
||||
if (isPortrait) {
|
||||
colorPickerModifier = colorPickerModifier
|
||||
.fillMaxWidth()
|
||||
.height(450.dp)
|
||||
} else {
|
||||
val size = screenHeight * 0.5f
|
||||
|
||||
colorPickerModifier = colorPickerModifier
|
||||
.height(size)
|
||||
.width(size)
|
||||
}
|
||||
|
||||
HsvColorPicker(
|
||||
modifier = colorPickerModifier,
|
||||
initialColor = color?.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,
|
||||
@@ -184,7 +105,7 @@ fun CardEditable(
|
||||
result.formatName?.let { formatName ->
|
||||
try {
|
||||
onCodeTypeChange(BarcodeFormat.valueOf(formatName))
|
||||
} catch (e: IllegalArgumentException) {}
|
||||
} catch (_: IllegalArgumentException) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,35 +121,54 @@ fun CardEditable(
|
||||
}
|
||||
}
|
||||
|
||||
val selectTemplateLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.StartActivityForResult()
|
||||
) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
val codeValue = result.data?.getStringExtra("codeValue") ?: ""
|
||||
|
||||
onCodeValueChange(codeValue)
|
||||
}
|
||||
}
|
||||
|
||||
OutlinedTextField(
|
||||
value = cardName,
|
||||
onValueChange = onCardNameChange,
|
||||
modifier = fieldModifier,
|
||||
label = { Text(stringResource(R.string.card_name)) }
|
||||
)
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = codeValue,
|
||||
onValueChange = onCodeValueChange,
|
||||
modifier = Modifier.weight(1f),
|
||||
label = { Text(stringResource(R.string.card_value)) }
|
||||
)
|
||||
Button(
|
||||
modifier = Modifier.align(Alignment.CenterVertically),
|
||||
onClick = {
|
||||
scanLauncher.launch(
|
||||
ScanOptions().apply {
|
||||
setPrompt(context.getString(R.string.scan_your_card))
|
||||
setBeepEnabled(true)
|
||||
setOrientationLocked(false)
|
||||
}
|
||||
)
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.do_scan_card))
|
||||
|
||||
OutlinedTextField(
|
||||
value = codeValue,
|
||||
onValueChange = onCodeValueChange,
|
||||
modifier = fieldModifier,
|
||||
label = { Text(stringResource(R.string.card_value)) }
|
||||
)
|
||||
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
onClick = {
|
||||
scanLauncher.launch(
|
||||
ScanOptions().apply {
|
||||
setPrompt(context.getString(R.string.scan_your_card))
|
||||
setBeepEnabled(true)
|
||||
setOrientationLocked(false)
|
||||
}
|
||||
)
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.do_scan_card))
|
||||
}
|
||||
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
onClick = {
|
||||
val intent = Intent(context, SelectTemplateActivity::class.java)
|
||||
|
||||
selectTemplateLauncher.launch(intent)
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.card_from_template))
|
||||
}
|
||||
|
||||
Box(
|
||||
@@ -272,7 +212,7 @@ fun CardEditable(
|
||||
Button(
|
||||
enabled = isColorEnabled,
|
||||
onClick = {
|
||||
val intent = Intent(context, SelectColorActivity::class.java)
|
||||
val intent = Intent(context, ChooseColorActivity::class.java)
|
||||
|
||||
intent.putExtra("currentColor", currentColor)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user