Przeglądaj źródła

Add item API implemented for notes form list

Khubaib 1 tydzień temu
rodzic
commit
d5cf93e4e3

+ 49 - 8
app/src/main/java/com/fastest/pass/home/presentation/ui/components/AddSecureNoteFormScreen.kt

@@ -44,11 +44,18 @@ 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 AddSecureNoteFormScreen() {
+fun AddSecureNoteFormScreen(
+    basePreferenceHelper: BasePreferenceHelper,
+    onSecureNoteFormList: (ArrayList<NewItemFormField>, Boolean) -> Unit
+) {
     val keyboardController = LocalSoftwareKeyboardController.current
     val focusManager = LocalFocusManager.current
+    var notes_title by remember { mutableStateOf("") }
+    var notes_notes by remember { mutableStateOf("") }
 
     Column(
         modifier = Modifier
@@ -60,18 +67,44 @@ fun AddSecureNoteFormScreen() {
             .imePadding()
     ) {
         Spacer(modifier = Modifier.height(20.dp))
-        TitleTextFieldASNFS(keyboardController = keyboardController, focusManager = focusManager)
+        TitleTextFieldASNFS(
+            keyboardController = keyboardController,
+            focusManager = focusManager,
+            onText = { notes_title = it }
+        )
         Spacer(modifier = Modifier.height(20.dp))
-        NotesTextFieldASNFS(keyboardController = keyboardController, focusManager = focusManager)
+        NotesTextFieldASNFS(
+            keyboardController = keyboardController,
+            focusManager = focusManager,
+            onText = { notes_notes = it }
+        )
         Spacer(modifier = Modifier.height(25.dp))
-        SaveButtonASCFS(buttonText = R.string.save)
+        SaveButtonASCFS(
+            buttonText = R.string.save,
+            onSaveButtonClick = {
+                val secureNotesFormList = ArrayList<NewItemFormField>()
+                val saltKey = basePreferenceHelper.getCustomSaltKey()
+                val secretKey = basePreferenceHelper.getCustomSecretKey()
+
+                val isTitleEmpty = notes_title.isEmpty()
+
+                notes_title = encryptIfNotEmpty(notes_title, secretKey, saltKey)
+                notes_notes = encryptIfNotEmpty(notes_notes, secretKey, saltKey)
+
+                secureNotesFormList.add(NewItemFormField("notes_title", notes_title))
+                secureNotesFormList.add(NewItemFormField("notes_notes", notes_notes))
+
+                onSecureNoteFormList.invoke(secureNotesFormList, isTitleEmpty)
+            }
+        )
     }
 }
 
 @Composable
 fun ColumnScope.TitleTextFieldASNFS(
     keyboardController: SoftwareKeyboardController?,
-    focusManager: FocusManager
+    focusManager: FocusManager,
+    onText: (String) -> Unit
 ) {
     var titleText by remember { mutableStateOf("") }
 
@@ -79,6 +112,7 @@ fun ColumnScope.TitleTextFieldASNFS(
         value = titleText,
         onValueChange = {
             titleText = it
+            onText.invoke(titleText)
         },
         textStyle = MaterialTheme.typography.displayMedium,
         modifier = Modifier
@@ -140,7 +174,8 @@ fun ColumnScope.TitleTextFieldASNFS(
 @Composable
 fun ColumnScope.NotesTextFieldASNFS(
     keyboardController: SoftwareKeyboardController?,
-    focusManager: FocusManager
+    focusManager: FocusManager,
+    onText: (String) -> Unit
 ) {
     var notesText by remember { mutableStateOf("") }
 
@@ -148,6 +183,7 @@ fun ColumnScope.NotesTextFieldASNFS(
         value = notesText,
         onValueChange = {
             notesText = it
+            onText.invoke(notesText)
         },
         textStyle = MaterialTheme.typography.displayMedium,
         modifier = Modifier
@@ -208,14 +244,19 @@ fun ColumnScope.NotesTextFieldASNFS(
 }
 
 @Composable
-fun ColumnScope.SaveButtonASCFS(buttonText: Int) {
+fun ColumnScope.SaveButtonASCFS(
+    buttonText: Int,
+    onSaveButtonClick: () -> Unit
+    ) {
     Button(
         modifier = Modifier
             .background(colorResource(id = R.color.transparent))
             .fillMaxWidth()
             .height(60.dp)
             .clickable() { },
-        onClick = {},
+        onClick = {
+            onSaveButtonClick.invoke()
+        },
         shape = RoundedCornerShape(15.dp),
 //            border = BorderStroke(25.dp, colorResource(id = R.color.black)),
         colors = ButtonDefaults.buttonColors(

+ 7 - 1
app/src/main/java/com/fastest/pass/home/presentation/ui/components/NewItemFormScreen.kt

@@ -55,6 +55,7 @@ fun NewItemFormScreen(
     onBankAccountFormList: (ArrayList<NewItemFormField>, Boolean) -> Unit,
     onPaymentCardFormList: (ArrayList<NewItemFormField>, Boolean) -> Unit,
     onWifiPasswordFormList: (ArrayList<NewItemFormField>, Boolean) -> Unit,
+    onSecureNoteFormList: (ArrayList<NewItemFormField>, Boolean) -> Unit,
 ) {
     val keyboardController = LocalSoftwareKeyboardController.current
     val focusManager = LocalFocusManager.current
@@ -121,7 +122,12 @@ fun NewItemFormScreen(
                 )
             }
             ClickTypeAddNewItem.Note -> {
-                AddSecureNoteFormScreen()
+                AddSecureNoteFormScreen(
+                    basePreferenceHelper = basePreferenceHelper,
+                    onSecureNoteFormList = { data, boolean ->
+                        onSecureNoteFormList.invoke(data, boolean)
+                    }
+                )
             }
             ClickTypeAddNewItem.Contact -> {
                 AddContactInfoScreen(

+ 10 - 3
app/src/main/java/com/fastest/pass/home/presentation/ui/fragment/NewItemFormFragment.kt

@@ -160,9 +160,6 @@ class NewItemFormFragment : BaseFragment() {
                                     }
                                 },
                                 onWifiPasswordFormList = { wifiPasswordFormData, isTitleEmpty ->
-                                    wifiPasswordFormData.forEachIndexed { i, data ->
-                                        Log.d("wifiPasswordFormData", "data = ${data.key} , ${data.value}")
-                                    }
                                     if (isTitleEmpty) {
                                         coroutineScope.launch {
                                             snackBarStateRed.showSnackbar("Title field is empty.")
@@ -171,6 +168,16 @@ class NewItemFormFragment : BaseFragment() {
                                     else {
                                         viewmodel.addItems("wifi-password", wifiPasswordFormData)
                                     }
+                                },
+                                onSecureNoteFormList = { secureNoteFormData, isTitleEmpty ->
+                                    if (isTitleEmpty) {
+                                        coroutineScope.launch {
+                                            snackBarStateRed.showSnackbar("Title field is empty.")
+                                        }
+                                    }
+                                    else {
+                                        viewmodel.addItems("notes", secureNoteFormData)
+                                    }
                                 }
                             )