feat: added templates search
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
package ru.omni_devel.cards
|
package ru.omni_devel.cards
|
||||||
|
|
||||||
const val TEMPLATES_URL = "https://gitea.omni-devel.ru/omni/OmniCardsRepo/raw/branch/main/templates.json"
|
const val TEMPLATES_URL = "https://gitea.omni-devel.ru/omni/OmniCardsRepo/raw/branch/main/templates.json"
|
||||||
|
|
||||||
|
val SPACE_SYMBOLS = listOf(" ", "-", "_")
|
||||||
|
|||||||
@@ -79,8 +79,6 @@ fun FillTemplatePage(template: Template, innerPadding: PaddingValues) {
|
|||||||
selectTemplateNameViaLanguage(template.names, language),
|
selectTemplateNameViaLanguage(template.names, language),
|
||||||
innerPadding
|
innerPadding
|
||||||
) {
|
) {
|
||||||
val fieldModifier = Modifier.fillMaxWidth()
|
|
||||||
|
|
||||||
for (field in template.fields) {
|
for (field in template.fields) {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = filledFields[field.id]!!,
|
value = filledFields[field.id]!!,
|
||||||
@@ -89,7 +87,7 @@ fun FillTemplatePage(template: Template, innerPadding: PaddingValues) {
|
|||||||
this[field.id] = newValue
|
this[field.id] = newValue
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
modifier = fieldModifier,
|
modifier = Modifier.fillMaxWidth(),
|
||||||
label = { Text((if (field.maybeEmpty) "" else "*") + selectTemplateNameViaLanguage(field.names, language)) }
|
label = { Text((if (field.maybeEmpty) "" else "*") + selectTemplateNameViaLanguage(field.names, language)) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,19 +9,15 @@ 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.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.rememberScrollState
|
|
||||||
import androidx.compose.foundation.verticalScroll
|
|
||||||
import androidx.compose.material3.Button
|
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -66,6 +62,8 @@ fun SelectTemplatePage(innerPadding: PaddingValues) {
|
|||||||
|
|
||||||
val language = getLanguage(context)
|
val language = getLanguage(context)
|
||||||
|
|
||||||
|
var searchQuery by rememberSaveable { mutableStateOf("") }
|
||||||
|
|
||||||
var templates by remember { mutableStateOf<List<Template>?>(null) }
|
var templates by remember { mutableStateOf<List<Template>?>(null) }
|
||||||
var loadingError by remember { mutableStateOf<String?>(null) }
|
var loadingError by remember { mutableStateOf<String?>(null) }
|
||||||
|
|
||||||
@@ -100,14 +98,25 @@ fun SelectTemplatePage(innerPadding: PaddingValues) {
|
|||||||
stringResource(R.string.choosing_template),
|
stringResource(R.string.choosing_template),
|
||||||
innerPadding
|
innerPadding
|
||||||
) {
|
) {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = searchQuery,
|
||||||
|
onValueChange = { newValue ->
|
||||||
|
searchQuery = newValue
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
label = { Text(stringResource(R.string.search_templates)) }
|
||||||
|
)
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
|
val currentTemplates = templates
|
||||||
|
|
||||||
if (loadingError != null) {
|
if (loadingError != null) {
|
||||||
item {
|
item {
|
||||||
Text(loadingError!!)
|
Text(loadingError!!)
|
||||||
}
|
}
|
||||||
} else if (templates == null) {
|
} else if (currentTemplates == null) {
|
||||||
item {
|
item {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
@@ -119,12 +128,36 @@ fun SelectTemplatePage(innerPadding: PaddingValues) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (templates!!.isEmpty()) {
|
} else {
|
||||||
|
val searchResults = currentTemplates.filter { template ->
|
||||||
|
var queryCleaned = searchQuery.lowercase()
|
||||||
|
|
||||||
|
if (queryCleaned.isEmpty()) {
|
||||||
|
return@filter true
|
||||||
|
}
|
||||||
|
|
||||||
|
for (name in template.names.values) {
|
||||||
|
var nameCleaned = name.lowercase()
|
||||||
|
|
||||||
|
for (spaceSymbol in SPACE_SYMBOLS) {
|
||||||
|
nameCleaned = nameCleaned.replace(spaceSymbol, "")
|
||||||
|
queryCleaned = queryCleaned.replace(spaceSymbol, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nameCleaned.contains(queryCleaned)) {
|
||||||
|
return@filter true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return@filter false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (searchResults.isEmpty()) {
|
||||||
item {
|
item {
|
||||||
Text(stringResource(R.string.templates_not_found))
|
Text(stringResource(R.string.templates_not_found))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (template in templates) {
|
for (template in searchResults) {
|
||||||
item {
|
item {
|
||||||
AdaptiveButton(
|
AdaptiveButton(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
@@ -143,4 +176,5 @@ fun SelectTemplatePage(innerPadding: PaddingValues) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
<string name="choosing_template">Выбор шаблона</string>
|
<string name="choosing_template">Выбор шаблона</string>
|
||||||
<string name="error_in_data">Ошибка в данных. Пожалуйста, заполните все необходимые (*) поля</string>
|
<string name="error_in_data">Ошибка в данных. Пожалуйста, заполните все необходимые (*) поля</string>
|
||||||
<string name="templates_not_found">Шаблоны не найдены</string>
|
<string name="templates_not_found">Шаблоны не найдены</string>
|
||||||
|
<string name="search_templates">Поиск шаблонов</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>
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
<string name="choosing_template">Choosing template</string>
|
<string name="choosing_template">Choosing template</string>
|
||||||
<string name="error_in_data">Error in data. Please, fill all required (*) fields</string>
|
<string name="error_in_data">Error in data. Please, fill all required (*) fields</string>
|
||||||
<string name="templates_not_found">Templates not found</string>
|
<string name="templates_not_found">Templates not found</string>
|
||||||
|
<string name="search_templates">Search templates</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