feat: added templates
This commit is contained in:
@@ -78,4 +78,6 @@ dependencies {
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0")
|
||||
implementation(libs.compose.colorpicker)
|
||||
implementation("org.burnoutcrew.composereorderable:reorderable:0.9.6")
|
||||
implementation("io.ktor:ktor-client-core:3.5.0")
|
||||
implementation("io.ktor:ktor-client-cio:3.5.0")
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
@@ -8,6 +10,21 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.OmniCards">
|
||||
<activity
|
||||
android:name=".FillTemplateActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/title_activity_fill_template"
|
||||
android:theme="@style/Theme.OmniCards" />
|
||||
<activity
|
||||
android:name=".SelectTemplateActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/title_activity_select_template"
|
||||
android:theme="@style/Theme.OmniCards" />
|
||||
<activity
|
||||
android:name=".ChooseColorActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/title_activity_choose_color"
|
||||
android:theme="@style/Theme.OmniCards" />
|
||||
<activity
|
||||
android:name=".BackupActivity"
|
||||
android:exported="false"
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
package ru.omni_devel.cards
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.LocalActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
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.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.graphics.toColorInt
|
||||
import com.github.skydoves.colorpicker.compose.ColorEnvelope
|
||||
import com.github.skydoves.colorpicker.compose.HsvColorPicker
|
||||
import com.github.skydoves.colorpicker.compose.rememberColorPickerController
|
||||
import ru.omni_devel.cards.ui.theme.OmniCardsTheme
|
||||
|
||||
class ChooseColorActivity : 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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package ru.omni_devel.cards
|
||||
|
||||
const val TEMPLATES_URL = "https://gitea.omni-devel.ru/omni/OmniCardsRepo/raw/branch/main/templates.json"
|
||||
@@ -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,23 +121,32 @@ 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),
|
||||
modifier = fieldModifier,
|
||||
label = { Text(stringResource(R.string.card_value)) }
|
||||
)
|
||||
|
||||
Button(
|
||||
modifier = Modifier.align(Alignment.CenterVertically),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
onClick = {
|
||||
scanLauncher.launch(
|
||||
ScanOptions().apply {
|
||||
@@ -229,6 +159,16 @@ fun CardEditable(
|
||||
) {
|
||||
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)
|
||||
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
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
|
||||
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.background
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.cio.CIO
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import kotlinx.serialization.json.Json
|
||||
import ru.omni_devel.cards.ui.theme.OmniCardsTheme
|
||||
|
||||
class FillTemplateActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
|
||||
val templateJson = intent.getStringExtra("templateJson") ?: ""
|
||||
val template = Template.parseTemplateFromJson(templateJson)
|
||||
|
||||
setContent {
|
||||
OmniCardsTheme {
|
||||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
||||
FillTemplatePage(template, innerPadding)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun FillTemplatePage(template: Template, innerPadding: PaddingValues) {
|
||||
val activityContext = LocalActivity.current
|
||||
val context = LocalContext.current
|
||||
|
||||
var filledFields by rememberSaveable { mutableStateOf(template.fields.associate { field ->
|
||||
field.id to (field.default ?: "")
|
||||
}) }
|
||||
|
||||
Page(
|
||||
template.name,
|
||||
innerPadding
|
||||
) {
|
||||
val fieldModifier = Modifier.fillMaxWidth()
|
||||
|
||||
for (field in template.fields) {
|
||||
OutlinedTextField(
|
||||
value = filledFields[field.id]!!,
|
||||
onValueChange = { newValue ->
|
||||
filledFields = filledFields.toMutableMap().apply {
|
||||
this[field.id] = newValue
|
||||
}
|
||||
},
|
||||
modifier = fieldModifier,
|
||||
label = { Text((if (field.maybeEmpty) "" else "* ") + field.name) }
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
onClick = {
|
||||
var isSuccess = true
|
||||
|
||||
for (field in template.fields) {
|
||||
if (filledFields[field.id]!!.isEmpty() && !field.maybeEmpty) {
|
||||
isSuccess = false
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSuccess) {
|
||||
Toast.makeText(context, context.getString(R.string.error_in_data), Toast.LENGTH_LONG).show()
|
||||
|
||||
return@Button
|
||||
}
|
||||
|
||||
var result = template.template
|
||||
|
||||
for ((id, value) in filledFields) {
|
||||
result = result.replace("$$id$", value)
|
||||
}
|
||||
|
||||
val resultIntent = Intent()
|
||||
|
||||
resultIntent.putExtra("codeValue", result)
|
||||
|
||||
activityContext!!.setResult(Activity.RESULT_OK, resultIntent)
|
||||
activityContext.finish()
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.do_save))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package ru.omni_devel.cards
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
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.background
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.cio.CIO
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import kotlinx.serialization.json.Json
|
||||
import ru.omni_devel.cards.ui.theme.OmniCardsTheme
|
||||
|
||||
class SelectTemplateActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
|
||||
setContent {
|
||||
OmniCardsTheme {
|
||||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
||||
SelectTemplatePage(innerPadding)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SelectTemplatePage(innerPadding: PaddingValues) {
|
||||
val activityContext = LocalActivity.current
|
||||
val context = LocalContext.current
|
||||
|
||||
var templates by remember { mutableStateOf<List<Template>?>(null) }
|
||||
var loadingError by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
try {
|
||||
val client = HttpClient(CIO)
|
||||
|
||||
val response: HttpResponse = client.get(TEMPLATES_URL)
|
||||
|
||||
templates = Template.parseTemplatesFromJson(response.bodyAsText())
|
||||
} catch (e: Exception) {
|
||||
loadingError = e.toString()
|
||||
}
|
||||
}
|
||||
|
||||
val fillTemplateLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.StartActivityForResult()
|
||||
) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
val codeValue = result.data?.getStringExtra("codeValue")
|
||||
|
||||
val resultIntent = Intent()
|
||||
|
||||
resultIntent.putExtra("codeValue", codeValue)
|
||||
|
||||
activityContext!!.setResult(Activity.RESULT_OK, resultIntent)
|
||||
activityContext.finish()
|
||||
}
|
||||
}
|
||||
|
||||
Page(
|
||||
stringResource(R.string.choosing_template),
|
||||
innerPadding
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
if (loadingError != null) {
|
||||
Text(loadingError!!)
|
||||
} else if (templates == null) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(48.dp),
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
} else {
|
||||
for (template in templates) {
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.primaryContainer),
|
||||
onClick = {
|
||||
val intent = Intent(context, FillTemplateActivity::class.java)
|
||||
|
||||
intent.putExtra("templateJson", Json.encodeToString(template))
|
||||
|
||||
fillTemplateLauncher.launch(intent)
|
||||
}
|
||||
) {
|
||||
Text(template.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package ru.omni_devel.cards
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
||||
@Serializable
|
||||
class Field(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val default: String? = null,
|
||||
val maybeEmpty: Boolean = false
|
||||
)
|
||||
|
||||
@Serializable
|
||||
class Template(
|
||||
val name: String,
|
||||
val fields: List<Field>,
|
||||
val template: String
|
||||
) {
|
||||
companion object {
|
||||
fun parseTemplateFromJson(json: String): Template {
|
||||
val obj = JSONObject(json)
|
||||
|
||||
val fieldsArray = obj.getJSONArray("fields")
|
||||
val fields = mutableListOf<Field>()
|
||||
|
||||
for (fi in 0 until fieldsArray.length()) {
|
||||
val fieldObj = fieldsArray.getJSONObject(fi)
|
||||
|
||||
fields.add(Field(
|
||||
id = fieldObj.getString("id"),
|
||||
name = fieldObj.getString("name"),
|
||||
default = fieldObj.optString("default"),
|
||||
maybeEmpty = fieldObj.optBoolean("maybeEmpty")
|
||||
))
|
||||
}
|
||||
|
||||
return Template(
|
||||
name = obj.getString("name"),
|
||||
fields = fields,
|
||||
template = obj.getString("template")
|
||||
)
|
||||
}
|
||||
|
||||
fun parseTemplatesFromJson(json: String): List<Template> {
|
||||
val array = JSONArray(json)
|
||||
val templates = mutableListOf<Template>()
|
||||
|
||||
for (i in 0 until array.length()) {
|
||||
val obj = array.getJSONObject(i)
|
||||
|
||||
val fieldsArray = obj.getJSONArray("fields")
|
||||
val fields = mutableListOf<Field>()
|
||||
|
||||
for (fi in 0 until fieldsArray.length()) {
|
||||
val fieldObj = fieldsArray.getJSONObject(fi)
|
||||
|
||||
fields.add(Field(
|
||||
id = fieldObj.getString("id"),
|
||||
name = fieldObj.getString("name"),
|
||||
default = fieldObj.optString("default"),
|
||||
maybeEmpty = fieldObj.optBoolean("maybeEmpty")
|
||||
))
|
||||
}
|
||||
|
||||
templates.add(Template(
|
||||
name = obj.getString("name"),
|
||||
fields = fields,
|
||||
template = obj.getString("template")
|
||||
))
|
||||
}
|
||||
|
||||
return templates
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,10 +31,13 @@
|
||||
<string name="card_name">Название карты</string>
|
||||
<string name="card_value">Значение карты</string>
|
||||
<string name="do_scan_card">Сканировать карту</string>
|
||||
<string name="card_from_template">Из шаблона</string>
|
||||
<string name="scan_your_card">Отсканируйте вашу карту</string>
|
||||
<string name="card_code_type">Тип кода карты</string>
|
||||
<string name="do_choose_color">Выбрать цвет</string>
|
||||
<string name="choosing_color">Выбор цвета</string>
|
||||
<string name="choosing_template">Выбор шаблона</string>
|
||||
<string name="error_in_data">Ошибка в данных</string>
|
||||
<string name="card_name_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>
|
||||
|
||||
@@ -36,13 +36,19 @@
|
||||
<string name="card_name">Card name</string>
|
||||
<string name="card_value">Card value</string>
|
||||
<string name="do_scan_card">Scan card</string>
|
||||
<string name="card_from_template">From template</string>
|
||||
<string name="scan_your_card">Scan your card</string>
|
||||
<string name="card_code_type">Card code type</string>
|
||||
<string name="do_choose_color">Choose color</string>
|
||||
<string name="choosing_color">Choosing color</string>
|
||||
<string name="choosing_template">Choosing template</string>
|
||||
<string name="error_in_data">Error in data</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="name_must_be_shorter_than_32_symbols">Card name must be shorter than 32 characters</string>
|
||||
|
||||
<string name="failed_to_generate_card_code">Failed to generate card code. Check the card data</string>
|
||||
<string name="title_activity_choose_color">ChooseColorActivity</string>
|
||||
<string name="title_activity_select_template">SelectTemplateActivity</string>
|
||||
<string name="title_activity_fill_template">FillTemplateActivity</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user