|
@@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
import androidx.compose.foundation.layout.imePadding
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
+import androidx.compose.foundation.layout.size
|
|
|
import androidx.compose.foundation.layout.wrapContentHeight
|
|
|
import androidx.compose.foundation.rememberScrollState
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
@@ -51,6 +52,7 @@ import androidx.compose.ui.platform.LocalFocusManager
|
|
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
|
|
import androidx.compose.ui.platform.SoftwareKeyboardController
|
|
|
import androidx.compose.ui.res.colorResource
|
|
|
+import androidx.compose.ui.res.painterResource
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
import androidx.compose.ui.text.input.ImeAction
|
|
|
import androidx.compose.ui.text.input.KeyboardType
|
|
@@ -58,17 +60,49 @@ import androidx.compose.ui.text.style.TextAlign
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
import com.fastest.pass.R
|
|
|
+import com.fastest.pass.helpers.BasePreferenceHelper
|
|
|
+import com.fastest.pass.home.data.model.NewItemFormField
|
|
|
import com.fastest.pass.home.domain.model.CountryInfo
|
|
|
|
|
|
@Composable
|
|
|
fun AddPassportFormScreen(
|
|
|
onCountryList: (List<CountryInfo>, String) -> Unit,
|
|
|
- countryListDisplayed: List<CountryInfo>
|
|
|
+ countryListDisplayed: List<CountryInfo>,
|
|
|
+ basePreferenceHelper: BasePreferenceHelper,
|
|
|
+ onPassportFormList: (List<NewItemFormField>, Boolean) -> Unit
|
|
|
) {
|
|
|
val keyboardController = LocalSoftwareKeyboardController.current
|
|
|
val focusManager = LocalFocusManager.current
|
|
|
val gender = listOf("Please Select", "Male", "Female", "Other")
|
|
|
|
|
|
+ var passports_title by remember { mutableStateOf("") }
|
|
|
+ var passports_type by remember { mutableStateOf("") }
|
|
|
+ var passports_name by remember { mutableStateOf("") }
|
|
|
+ var passports_country by remember { mutableStateOf("") }
|
|
|
+ var passports_number by remember { mutableStateOf("") }
|
|
|
+ var passports_gender by remember { mutableStateOf("") }
|
|
|
+ var passports_nationality by remember { mutableStateOf("") }
|
|
|
+ var passports_issuing_authority by remember { mutableStateOf("") }
|
|
|
+ var passports_date_of_birth by remember { mutableStateOf("") }
|
|
|
+ var passports_issued_date by remember { mutableStateOf("") }
|
|
|
+ var passports_expiration_date by remember { mutableStateOf("") }
|
|
|
+ var passports_notes by remember { mutableStateOf("") }
|
|
|
+
|
|
|
+ val passportFormList = mutableListOf(
|
|
|
+ NewItemFormField("passports_title", passports_title),
|
|
|
+ NewItemFormField("passports_type", passports_type),
|
|
|
+ NewItemFormField("passports_name", passports_name),
|
|
|
+ NewItemFormField("passports_country", passports_country),
|
|
|
+ NewItemFormField("passports_number", passports_number),
|
|
|
+ NewItemFormField("passports_gender", passports_gender),
|
|
|
+ NewItemFormField("passports_nationality", passports_nationality),
|
|
|
+ NewItemFormField("passports_issuing_authority", passports_issuing_authority),
|
|
|
+ NewItemFormField("passports_date_of_birth", passports_date_of_birth),
|
|
|
+ NewItemFormField("passports_issued_date", passports_issued_date),
|
|
|
+ NewItemFormField("passports_expiration_date", passports_expiration_date),
|
|
|
+ NewItemFormField("passports_notes", passports_notes),
|
|
|
+ )
|
|
|
+
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
|
.fillMaxSize()
|
|
@@ -77,7 +111,24 @@ fun AddPassportFormScreen(
|
|
|
.background(Color.Transparent)
|
|
|
.imePadding()
|
|
|
) {
|
|
|
- SaveButtonAPFS(buttonText = R.string.save)
|
|
|
+ SaveButtonAPFS(
|
|
|
+ buttonText = R.string.save,
|
|
|
+ onSaveButtonClick = {
|
|
|
+ val saltKey = basePreferenceHelper.getCustomSaltKey()
|
|
|
+ val secretKey = basePreferenceHelper.getCustomSecretKey()
|
|
|
+ val isTitleEmpty = passports_title.isEmpty()
|
|
|
+
|
|
|
+ passportFormList.forEachIndexed { index, newItemFormField ->
|
|
|
+ newItemFormField.value = encryptIfNotEmpty(newItemFormField.value, secretKey, saltKey)
|
|
|
+ }
|
|
|
+
|
|
|
+ val passportFormData = passportFormList.map { field ->
|
|
|
+ NewItemFormField(field.key, field.value)
|
|
|
+ }
|
|
|
+
|
|
|
+ onPassportFormList.invoke(passportFormData, isTitleEmpty)
|
|
|
+ }
|
|
|
+ )
|
|
|
|
|
|
Column(
|
|
|
modifier = Modifier
|
|
@@ -88,12 +139,26 @@ fun AddPassportFormScreen(
|
|
|
.verticalScroll(rememberScrollState())
|
|
|
) {
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
- NameTextFieldAPFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.title)
|
|
|
-
|
|
|
+ NameTextFieldAPFS(
|
|
|
+ keyboardController = keyboardController,
|
|
|
+ focusManager = focusManager,
|
|
|
+ labelText = R.string.title,
|
|
|
+ onText = { passports_title = it }
|
|
|
+ )
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
- NameTextFieldAPFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.type)
|
|
|
+ NameTextFieldAPFS(
|
|
|
+ keyboardController = keyboardController,
|
|
|
+ focusManager = focusManager,
|
|
|
+ labelText = R.string.type,
|
|
|
+ onText = { passports_type = it }
|
|
|
+ )
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
- NameTextFieldAPFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.name)
|
|
|
+ NameTextFieldAPFS(
|
|
|
+ keyboardController = keyboardController,
|
|
|
+ focusManager = focusManager,
|
|
|
+ labelText = R.string.name,
|
|
|
+ onText = { passports_name = it }
|
|
|
+ )
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
SelectCountryInfoPassport(
|
|
|
labelText = R.string.country,
|
|
@@ -102,43 +167,76 @@ fun AddPassportFormScreen(
|
|
|
onCountryList = { list, text ->
|
|
|
onCountryList.invoke(list, text)
|
|
|
},
|
|
|
- countryListDisplayed = countryListDisplayed
|
|
|
+ countryListDisplayed = countryListDisplayed,
|
|
|
+ onText = { passports_country = it }
|
|
|
)
|
|
|
// NameTextFieldAPFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.country)
|
|
|
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
- TextNumberTextFieldAPFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.number, placeholder = "P12345678")
|
|
|
+ TextNumberTextFieldAPFS(
|
|
|
+ keyboardController = keyboardController,
|
|
|
+ focusManager = focusManager,
|
|
|
+ labelText = R.string.number,
|
|
|
+ placeholder = "P12345678",
|
|
|
+ onText = { passports_number = it }
|
|
|
+ )
|
|
|
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
DropDownFieldPassport(
|
|
|
keyboardController = keyboardController,
|
|
|
focusManager = focusManager,
|
|
|
labelText = R.string.gender,
|
|
|
- titles = gender
|
|
|
+ titles = gender,
|
|
|
+ onText = { passports_gender = it }
|
|
|
)
|
|
|
// NameTextFieldAPFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.sex)
|
|
|
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
- NameTextFieldAPFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.nationality)
|
|
|
+ NameTextFieldAPFS(
|
|
|
+ keyboardController = keyboardController,
|
|
|
+ focusManager = focusManager,
|
|
|
+ labelText = R.string.nationality,
|
|
|
+ onText = { passports_nationality = it }
|
|
|
+ )
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
- NameTextFieldAPFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.issuing_authority)
|
|
|
+ NameTextFieldAPFS(
|
|
|
+ keyboardController = keyboardController,
|
|
|
+ focusManager = focusManager,
|
|
|
+ labelText = R.string.issuing_authority,
|
|
|
+ onText = { passports_issuing_authority = it }
|
|
|
+ )
|
|
|
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
- DatePickerAPFS(labelText = R.string.date_of_birth) {}
|
|
|
+ DatePickerAPFS(
|
|
|
+ labelText = R.string.date_of_birth,
|
|
|
+ onDateSelected = { passports_date_of_birth = it }
|
|
|
+ )
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
- DatePickerAPFS(labelText = R.string.issued_date) {}
|
|
|
+ DatePickerAPFS(
|
|
|
+ labelText = R.string.issued_date,
|
|
|
+ onDateSelected = { passports_issued_date = it }
|
|
|
+ )
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
- DatePickerAPFS(labelText = R.string.expiration_date) {}
|
|
|
+ DatePickerAPFS(
|
|
|
+ labelText = R.string.expiration_date,
|
|
|
+ onDateSelected = { passports_expiration_date = it }
|
|
|
+ )
|
|
|
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
- NotesTextFieldAPFS(keyboardController = keyboardController, focusManager = focusManager)
|
|
|
-
|
|
|
+ NotesTextFieldAPFS(
|
|
|
+ keyboardController = keyboardController,
|
|
|
+ focusManager = focusManager,
|
|
|
+ onText = { passports_notes = it }
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun BoxScope.SaveButtonAPFS(buttonText: Int) {
|
|
|
+fun BoxScope.SaveButtonAPFS(
|
|
|
+ buttonText: Int,
|
|
|
+ onSaveButtonClick: () -> Unit
|
|
|
+) {
|
|
|
Button(
|
|
|
modifier = Modifier
|
|
|
.background(colorResource(id = R.color.transparent))
|
|
@@ -146,7 +244,9 @@ fun BoxScope.SaveButtonAPFS(buttonText: Int) {
|
|
|
.height(60.dp)
|
|
|
.align(Alignment.BottomCenter)
|
|
|
.clickable() { },
|
|
|
- onClick = {},
|
|
|
+ onClick = {
|
|
|
+ onSaveButtonClick.invoke()
|
|
|
+ },
|
|
|
shape = RoundedCornerShape(15.dp),
|
|
|
// border = BorderStroke(25.dp, colorResource(id = R.color.black)),
|
|
|
colors = ButtonDefaults.buttonColors(
|
|
@@ -170,7 +270,8 @@ fun BoxScope.SaveButtonAPFS(buttonText: Int) {
|
|
|
fun ColumnScope.NameTextFieldAPFS(
|
|
|
keyboardController: SoftwareKeyboardController?,
|
|
|
focusManager: FocusManager,
|
|
|
- labelText: Int
|
|
|
+ labelText: Int,
|
|
|
+ onText: (String) -> Unit
|
|
|
) {
|
|
|
var text by remember { mutableStateOf("") }
|
|
|
|
|
@@ -178,6 +279,7 @@ fun ColumnScope.NameTextFieldAPFS(
|
|
|
value = text,
|
|
|
onValueChange = {
|
|
|
text = it
|
|
|
+ onText.invoke(text)
|
|
|
},
|
|
|
textStyle = MaterialTheme.typography.displayMedium,
|
|
|
modifier = Modifier
|
|
@@ -241,7 +343,8 @@ fun ColumnScope.TextNumberTextFieldAPFS(
|
|
|
keyboardController: SoftwareKeyboardController?,
|
|
|
focusManager: FocusManager,
|
|
|
labelText: Int,
|
|
|
- placeholder: String
|
|
|
+ placeholder: String,
|
|
|
+ onText: (String) -> Unit
|
|
|
) {
|
|
|
var text by remember { mutableStateOf("") }
|
|
|
|
|
@@ -249,6 +352,7 @@ fun ColumnScope.TextNumberTextFieldAPFS(
|
|
|
value = text,
|
|
|
onValueChange = {
|
|
|
text = it
|
|
|
+ onText.invoke(text)
|
|
|
},
|
|
|
textStyle = MaterialTheme.typography.displayMedium,
|
|
|
modifier = Modifier
|
|
@@ -343,6 +447,14 @@ fun ColumnScope.DatePickerAPFS(
|
|
|
tint = colorResource(id = R.color.gray_text)
|
|
|
)
|
|
|
},
|
|
|
+ trailingIcon = {
|
|
|
+ Icon(
|
|
|
+ painter = painterResource(id = R.drawable.arrow_right),
|
|
|
+ contentDescription = "description",
|
|
|
+ modifier = Modifier.size(24.dp),
|
|
|
+ tint = colorResource(id = R.color.gray_text)
|
|
|
+ )
|
|
|
+ },
|
|
|
modifier = Modifier
|
|
|
.align(Alignment.Start)
|
|
|
.fillMaxWidth()
|
|
@@ -417,7 +529,8 @@ fun ColumnScope.DatePickerAPFS(
|
|
|
@Composable
|
|
|
fun ColumnScope.NotesTextFieldAPFS(
|
|
|
keyboardController: SoftwareKeyboardController?,
|
|
|
- focusManager: FocusManager
|
|
|
+ focusManager: FocusManager,
|
|
|
+ onText: (String) -> Unit
|
|
|
) {
|
|
|
var notesText by remember { mutableStateOf("") }
|
|
|
|
|
@@ -425,6 +538,7 @@ fun ColumnScope.NotesTextFieldAPFS(
|
|
|
value = notesText,
|
|
|
onValueChange = {
|
|
|
notesText = it
|
|
|
+ onText.invoke(notesText)
|
|
|
},
|
|
|
textStyle = MaterialTheme.typography.displayMedium,
|
|
|
modifier = Modifier
|
|
@@ -490,7 +604,8 @@ fun ColumnScope.SelectCountryInfoPassport(
|
|
|
keyboardController: SoftwareKeyboardController?,
|
|
|
focusManager: FocusManager,
|
|
|
onCountryList: (List<CountryInfo>, String) -> Unit,
|
|
|
- countryListDisplayed: List<CountryInfo>
|
|
|
+ countryListDisplayed: List<CountryInfo>,
|
|
|
+ onText: (String) -> Unit
|
|
|
) {
|
|
|
var selectedCountry by remember { mutableStateOf("Please Select") }
|
|
|
var isSheetOpened by remember { mutableStateOf(false) }
|
|
@@ -510,6 +625,14 @@ fun ColumnScope.SelectCountryInfoPassport(
|
|
|
color = colorResource(id = R.color.gray_text)
|
|
|
)
|
|
|
) },
|
|
|
+ trailingIcon = {
|
|
|
+ Icon(
|
|
|
+ painter = painterResource(id = R.drawable.arrow_right),
|
|
|
+ contentDescription = "description",
|
|
|
+ modifier = Modifier.size(24.dp),
|
|
|
+ tint = colorResource(id = R.color.gray_text)
|
|
|
+ )
|
|
|
+ },
|
|
|
modifier = Modifier
|
|
|
.align(Alignment.Start)
|
|
|
.fillMaxWidth()
|
|
@@ -548,6 +671,7 @@ fun ColumnScope.SelectCountryInfoPassport(
|
|
|
isSheetOpened = {isSheetOpened = false},
|
|
|
onSelectedCountry = { countryName ->
|
|
|
selectedCountry = countryName
|
|
|
+ onText.invoke(selectedCountry)
|
|
|
},
|
|
|
onSearchTextChanged = {},
|
|
|
onCountryList = { list , text ->
|
|
@@ -565,7 +689,8 @@ fun ColumnScope.DropDownFieldPassport(
|
|
|
focusManager: FocusManager,
|
|
|
labelText: Int,
|
|
|
titles: List<String>,
|
|
|
- topPadding: Int = 0
|
|
|
+ topPadding: Int = 0,
|
|
|
+ onText: (String) -> Unit
|
|
|
) {
|
|
|
var isExpanded by remember { mutableStateOf(false) }
|
|
|
var selectedText by remember { mutableStateOf(titles[0]) }
|
|
@@ -648,6 +773,7 @@ fun ColumnScope.DropDownFieldPassport(
|
|
|
onClick = {
|
|
|
selectedText = s
|
|
|
isExpanded = false
|
|
|
+ onText.invoke(selectedText)
|
|
|
},
|
|
|
modifier = Modifier
|
|
|
.background(colorResource(id = R.color.white))
|