|
@@ -1,5 +1,6 @@
|
|
|
package com.fastest.pass.home.presentation.ui.components
|
|
|
|
|
|
+import android.util.Log
|
|
|
import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.border
|
|
|
import androidx.compose.foundation.clickable
|
|
@@ -50,12 +51,26 @@ 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
|
|
|
|
|
|
@Composable
|
|
|
-fun AddPaymentCardFormScreen() {
|
|
|
+fun AddPaymentCardFormScreen(
|
|
|
+ basePreferenceHelper: BasePreferenceHelper,
|
|
|
+ onPaymentCardFormList: (ArrayList<NewItemFormField>, Boolean) -> Unit
|
|
|
+) {
|
|
|
val keyboardController = LocalSoftwareKeyboardController.current
|
|
|
val focusManager = LocalFocusManager.current
|
|
|
|
|
|
+ var payment_cards_title by remember { mutableStateOf("") }
|
|
|
+ var payment_cards_name_on_card by remember { mutableStateOf("") }
|
|
|
+ var payment_cards_type by remember { mutableStateOf("") }
|
|
|
+ var payment_cards_number by remember { mutableStateOf("") }
|
|
|
+ var payment_cards_security_code by remember { mutableStateOf("") }
|
|
|
+ var payment_cards_start_date by remember { mutableStateOf("") }
|
|
|
+ var payment_cards_expiration_date by remember { mutableStateOf("") }
|
|
|
+ var payment_cards_notes by remember { mutableStateOf("") }
|
|
|
+
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
|
.fillMaxSize()
|
|
@@ -64,7 +79,35 @@ fun AddPaymentCardFormScreen() {
|
|
|
.background(Color.Transparent)
|
|
|
.imePadding(),
|
|
|
) {
|
|
|
- SaveButtonAPCFS(buttonText = R.string.save)
|
|
|
+ SaveButtonAPCFS(
|
|
|
+ buttonText = R.string.save,
|
|
|
+ onSaveButtonClick = {
|
|
|
+ val paymentCardFormList = ArrayList<NewItemFormField>()
|
|
|
+ val saltKey = basePreferenceHelper.getCustomSaltKey()
|
|
|
+ val secretKey = basePreferenceHelper.getCustomSecretKey()
|
|
|
+ val isTitleEmpty = payment_cards_title.isEmpty()
|
|
|
+
|
|
|
+ payment_cards_title = encryptIfNotEmpty(payment_cards_title, secretKey, saltKey)
|
|
|
+ payment_cards_name_on_card = encryptIfNotEmpty(payment_cards_name_on_card, secretKey, saltKey)
|
|
|
+ payment_cards_type = encryptIfNotEmpty(payment_cards_type, secretKey, saltKey)
|
|
|
+ payment_cards_number = encryptIfNotEmpty(payment_cards_number, secretKey, saltKey)
|
|
|
+ payment_cards_security_code = encryptIfNotEmpty(payment_cards_security_code, secretKey, saltKey)
|
|
|
+ payment_cards_start_date = encryptIfNotEmpty(payment_cards_start_date, secretKey, saltKey)
|
|
|
+ payment_cards_expiration_date = encryptIfNotEmpty(payment_cards_expiration_date, secretKey, saltKey)
|
|
|
+ payment_cards_notes = encryptIfNotEmpty(payment_cards_notes, secretKey, saltKey)
|
|
|
+
|
|
|
+ paymentCardFormList.add(NewItemFormField("payment-cards_title", payment_cards_title))
|
|
|
+ paymentCardFormList.add(NewItemFormField("payment-cards_name_on_card", payment_cards_name_on_card))
|
|
|
+ paymentCardFormList.add(NewItemFormField("payment-cards_type", payment_cards_type))
|
|
|
+ paymentCardFormList.add(NewItemFormField("payment-cards_number", payment_cards_number))
|
|
|
+ paymentCardFormList.add(NewItemFormField("payment-cards_security_code", payment_cards_security_code))
|
|
|
+ paymentCardFormList.add(NewItemFormField("payment-cards_start_date", payment_cards_start_date))
|
|
|
+ paymentCardFormList.add(NewItemFormField("payment-cards_expiration_date", payment_cards_expiration_date))
|
|
|
+ paymentCardFormList.add(NewItemFormField("payment-cards_notes", payment_cards_notes))
|
|
|
+
|
|
|
+ onPaymentCardFormList.invoke(paymentCardFormList, isTitleEmpty)
|
|
|
+ }
|
|
|
+ )
|
|
|
|
|
|
Column(
|
|
|
modifier = Modifier
|
|
@@ -78,52 +121,61 @@ fun AddPaymentCardFormScreen() {
|
|
|
NameTextFieldAPCFS(
|
|
|
keyboardController = keyboardController,
|
|
|
focusManager = focusManager,
|
|
|
- labelText = R.string.title
|
|
|
+ labelText = R.string.title,
|
|
|
+ onText = { payment_cards_title = it }
|
|
|
)
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
NameTextFieldAPCFS(
|
|
|
keyboardController = keyboardController,
|
|
|
focusManager = focusManager,
|
|
|
- labelText = R.string.name_on_card
|
|
|
+ labelText = R.string.name_on_card,
|
|
|
+ onText = { payment_cards_name_on_card = it }
|
|
|
)
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
NameTextFieldAPCFS(
|
|
|
keyboardController = keyboardController,
|
|
|
focusManager = focusManager,
|
|
|
- labelText = R.string.type
|
|
|
+ labelText = R.string.type,
|
|
|
+ onText = { payment_cards_type = it }
|
|
|
)
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
NumberTextFieldAPCFS(
|
|
|
keyboardController = keyboardController,
|
|
|
focusManager = focusManager,
|
|
|
labelText = R.string.number,
|
|
|
- placeholder = "1234 1234 1234 1234"
|
|
|
+ placeholder = "1234 1234 1234 1234",
|
|
|
+ onText = { payment_cards_number = it }
|
|
|
)
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
NumberTextFieldAPCFS(
|
|
|
keyboardController = keyboardController,
|
|
|
focusManager = focusManager,
|
|
|
labelText = R.string.security_code,
|
|
|
- placeholder = "CVV"
|
|
|
+ placeholder = "CVV",
|
|
|
+ onText = { payment_cards_security_code = it }
|
|
|
)
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
NumberDateFieldAPCFS(
|
|
|
keyboardController = keyboardController,
|
|
|
focusManager = focusManager,
|
|
|
labelText = R.string.start_date,
|
|
|
- placeholder = "MM/YY"
|
|
|
+ placeholder = "MM/YY",
|
|
|
+ onText = { payment_cards_start_date = it }
|
|
|
)
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
NumberDateFieldAPCFS(
|
|
|
keyboardController = keyboardController,
|
|
|
focusManager = focusManager,
|
|
|
labelText = R.string.expiration_date,
|
|
|
- placeholder = "MM/YY"
|
|
|
+ placeholder = "MM/YY",
|
|
|
+ onText = { payment_cards_expiration_date = it }
|
|
|
)
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
- NotesTextFieldAPCFS(keyboardController, focusManager)
|
|
|
-// Spacer(modifier = Modifier.height(25.dp))
|
|
|
-// SaveButtonAPCFS(buttonText = R.string.save)
|
|
|
+ NotesTextFieldAPCFS(
|
|
|
+ keyboardController,
|
|
|
+ focusManager,
|
|
|
+ onText = { payment_cards_notes = it }
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -133,7 +185,8 @@ fun AddPaymentCardFormScreen() {
|
|
|
fun ColumnScope.NameTextFieldAPCFS(
|
|
|
keyboardController: SoftwareKeyboardController?,
|
|
|
focusManager: FocusManager,
|
|
|
- labelText: Int
|
|
|
+ labelText: Int,
|
|
|
+ onText: (String) -> Unit
|
|
|
) {
|
|
|
var text by remember { mutableStateOf("") }
|
|
|
|
|
@@ -141,6 +194,7 @@ fun ColumnScope.NameTextFieldAPCFS(
|
|
|
value = text,
|
|
|
onValueChange = {
|
|
|
text = it
|
|
|
+ onText.invoke(text)
|
|
|
},
|
|
|
textStyle = MaterialTheme.typography.displayMedium,
|
|
|
modifier = Modifier
|
|
@@ -204,7 +258,8 @@ fun ColumnScope.NumberTextFieldAPCFS(
|
|
|
keyboardController: SoftwareKeyboardController?,
|
|
|
focusManager: FocusManager,
|
|
|
labelText: Int,
|
|
|
- placeholder: String
|
|
|
+ placeholder: String,
|
|
|
+ onText: (String) -> Unit
|
|
|
) {
|
|
|
var text by remember { mutableStateOf("") }
|
|
|
|
|
@@ -212,6 +267,7 @@ fun ColumnScope.NumberTextFieldAPCFS(
|
|
|
value = text,
|
|
|
onValueChange = {
|
|
|
text = it
|
|
|
+ onText.invoke(text)
|
|
|
},
|
|
|
textStyle = MaterialTheme.typography.displayMedium,
|
|
|
modifier = Modifier
|
|
@@ -276,7 +332,8 @@ fun ColumnScope.NumberDateFieldAPCFS(
|
|
|
keyboardController: SoftwareKeyboardController?,
|
|
|
focusManager: FocusManager,
|
|
|
labelText: Int,
|
|
|
- placeholder: String
|
|
|
+ placeholder: String,
|
|
|
+ onText: (String) -> Unit
|
|
|
) {
|
|
|
var text by remember { mutableStateOf("") }
|
|
|
val maxLength = 4
|
|
@@ -286,6 +343,7 @@ fun ColumnScope.NumberDateFieldAPCFS(
|
|
|
onValueChange = { input ->
|
|
|
if (input.length <= maxLength) {
|
|
|
text = input.filter { it.isDigit() }
|
|
|
+ onText.invoke(text)
|
|
|
}
|
|
|
},
|
|
|
textStyle = MaterialTheme.typography.displayMedium,
|
|
@@ -382,7 +440,8 @@ fun dateFilter(text: AnnotatedString): TransformedText {
|
|
|
@Composable
|
|
|
fun ColumnScope.NotesTextFieldAPCFS(
|
|
|
keyboardController: SoftwareKeyboardController?,
|
|
|
- focusManager: FocusManager
|
|
|
+ focusManager: FocusManager,
|
|
|
+ onText: (String) -> Unit
|
|
|
) {
|
|
|
var notesText by remember { mutableStateOf("") }
|
|
|
|
|
@@ -390,6 +449,7 @@ fun ColumnScope.NotesTextFieldAPCFS(
|
|
|
value = notesText,
|
|
|
onValueChange = {
|
|
|
notesText = it
|
|
|
+ onText.invoke(notesText)
|
|
|
},
|
|
|
textStyle = MaterialTheme.typography.displayMedium,
|
|
|
modifier = Modifier
|
|
@@ -450,7 +510,10 @@ fun ColumnScope.NotesTextFieldAPCFS(
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun BoxScope.SaveButtonAPCFS(buttonText: Int) {
|
|
|
+fun BoxScope.SaveButtonAPCFS(
|
|
|
+ buttonText: Int,
|
|
|
+ onSaveButtonClick: () -> Unit
|
|
|
+ ) {
|
|
|
Button(
|
|
|
modifier = Modifier
|
|
|
.background(colorResource(id = R.color.transparent))
|
|
@@ -458,7 +521,9 @@ fun BoxScope.SaveButtonAPCFS(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(
|