Selaa lähdekoodia

Worked on add contact info screen and created drop down menu title

Khubaib 4 kuukautta sitten
vanhempi
commit
76a04f70a2

+ 256 - 0
app/src/main/java/com/fastest/pass/home/presentation/ui/components/AddContactInfoScreen.kt

@@ -0,0 +1,256 @@
+package com.fastest.pass.home.presentation.ui.components
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.ColumnScope
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.defaultMinSize
+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.wrapContentHeight
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.foundation.text.KeyboardActions
+import androidx.compose.foundation.text.KeyboardOptions
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material3.DropdownMenu
+import androidx.compose.material3.DropdownMenuItem
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.ExposedDropdownMenuBox
+import androidx.compose.material3.ExposedDropdownMenuDefaults
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextField
+import androidx.compose.material3.TextFieldDefaults
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusManager
+import androidx.compose.ui.graphics.Color
+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.stringResource
+import androidx.compose.ui.text.input.ImeAction
+import androidx.compose.ui.text.input.KeyboardType
+import androidx.compose.ui.unit.dp
+import com.fastest.pass.R
+
+@Composable
+fun AddContactInfoScreen() {
+    val keyboardController = LocalSoftwareKeyboardController.current
+    val focusManager = LocalFocusManager.current
+
+    val titles = listOf("Please Select", "Mr", "Mrs", "Ms", "Dr")
+
+    Column(
+        modifier = Modifier
+            .fillMaxSize()
+            .padding(horizontal = 30.dp)
+            .padding(bottom = 15.dp)
+            .background(Color.Transparent)
+            .verticalScroll(rememberScrollState())
+    ) {
+        Spacer(modifier = Modifier.height(20.dp))
+        NameTextFieldACIFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.item_title)
+
+        Spacer(modifier = Modifier.height(20.dp))
+        DropDownFieldACIFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.title, titles)
+
+        Spacer(modifier = Modifier.height(20.dp))
+        NameTextFieldACIFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.first_name)
+        Spacer(modifier = Modifier.height(20.dp))
+        NameTextFieldACIFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.middle_name)
+        Spacer(modifier = Modifier.height(20.dp))
+        NameTextFieldACIFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.last_name)
+
+        Spacer(modifier = Modifier.height(20.dp))
+        NameTextFieldACIFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.address1)
+        Spacer(modifier = Modifier.height(20.dp))
+        NameTextFieldACIFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.address2)
+        Spacer(modifier = Modifier.height(20.dp))
+        NameTextFieldACIFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.address3)
+
+        Spacer(modifier = Modifier.height(20.dp))
+        NameTextFieldACIFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.city_town)
+        Spacer(modifier = Modifier.height(20.dp))
+        NameTextFieldACIFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.country)
+        Spacer(modifier = Modifier.height(20.dp))
+        NameTextFieldACIFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.state)
+        Spacer(modifier = Modifier.height(20.dp))
+        NameTextFieldACIFS(keyboardController = keyboardController, focusManager = focusManager, labelText = R.string.zip_postal_code)
+    }
+}
+
+@Composable
+fun ColumnScope.NameTextFieldACIFS(
+    keyboardController: SoftwareKeyboardController?,
+    focusManager: FocusManager,
+    labelText: Int
+) {
+    var text by remember { mutableStateOf("") }
+
+    TextField(
+        value = text,
+        onValueChange = {
+            text = it
+        },
+        textStyle = MaterialTheme.typography.displayMedium,
+        modifier = Modifier
+            .align(Alignment.Start)
+            .fillMaxWidth()
+            .defaultMinSize(minHeight = 60.dp)
+            .wrapContentHeight()
+            .border(
+                1.dp,
+                color = colorResource(id = R.color.gray_border_textfield),
+                shape = RoundedCornerShape(16.dp)
+            )
+            .background(color = colorResource(id = R.color.transparent)),
+        shape = RoundedCornerShape(16.dp),
+//        placeholder = {
+//            Text(
+//                text = stringResource(id = R.string.enter_email_address),
+//                color = colorResource(id = R.color.gray_splash),
+//                style = MaterialTheme.typography.displayMedium
+//            )
+//        },
+        label = {
+            Text(text = stringResource(id = labelText),
+                style = MaterialTheme.typography.titleSmall.copy(
+                    color = colorResource(id = R.color.gray_text)
+                )
+            )
+        },
+//        leadingIcon = {
+//            Image(
+//                painter = painterResource(id = R.drawable.profile_circle),
+//                contentDescription = "Title Logo",
+//                modifier = Modifier
+//                    .size(24.dp, 24.dp)
+//            )
+//        },
+        colors = TextFieldDefaults.colors(
+            focusedLabelColor = colorResource(id = R.color.gray_splash),
+            unfocusedContainerColor = colorResource(id = R.color.transparent),
+            focusedContainerColor = colorResource(id = R.color.transparent),
+            focusedIndicatorColor = colorResource(id = R.color.transparent),
+            disabledIndicatorColor = colorResource(id = R.color.transparent),
+            unfocusedIndicatorColor = colorResource(id = R.color.transparent),
+            cursorColor = colorResource(id = R.color.gray_splash),
+        ),
+        keyboardOptions = KeyboardOptions(
+            keyboardType = KeyboardType.Text,
+            imeAction = ImeAction.Next
+        ),
+        keyboardActions = KeyboardActions(
+            onDone = {
+                focusManager.clearFocus()
+                keyboardController?.hide()
+            }
+        ),
+    )
+}
+
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun ColumnScope.DropDownFieldACIFS(
+    keyboardController: SoftwareKeyboardController?,
+    focusManager: FocusManager,
+    labelText: Int,
+    titles: List<String>
+) {
+    var isExpanded by remember { mutableStateOf(false) }
+    var selectedText by remember { mutableStateOf(titles[0]) }
+
+    Column(
+        modifier = Modifier
+            .fillMaxWidth()
+            .background(color = colorResource(id = R.color.white)),
+    ) {
+       Box(
+           modifier = Modifier
+               .fillMaxWidth()
+               .background(colorResource(id = R.color.white))
+       ) {
+           ExposedDropdownMenuBox(
+               expanded = isExpanded,
+               onExpandedChange = { isExpanded = !isExpanded },
+               modifier = Modifier
+                   .fillMaxWidth()
+                   .height(60.dp)
+                   .border(
+                       1.dp,
+                       color = colorResource(id = R.color.gray_border_textfield),
+                       shape = RoundedCornerShape(16.dp)
+                   )
+                   .background(color = colorResource(id = R.color.white)),
+           ) {
+               TextField(
+                   value = selectedText,
+                   onValueChange = {},
+                   textStyle = MaterialTheme.typography.displayMedium,
+                   readOnly = true,
+                   label = { Text(
+                       stringResource(id = labelText),
+                       style = MaterialTheme.typography.titleSmall.copy(
+                           color = colorResource(id = R.color.gray_text)
+                       )
+                       ) },
+                   trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(isExpanded) },
+                   modifier = Modifier
+                       .menuAnchor()
+                       .fillMaxWidth()
+                       .background(color = colorResource(id = R.color.white)),
+                        colors = ExposedDropdownMenuDefaults.textFieldColors(
+                            focusedLabelColor = colorResource(id = R.color.gray_splash),
+                            unfocusedContainerColor = colorResource(id = R.color.transparent),
+                            focusedContainerColor = colorResource(id = R.color.transparent),
+                            focusedIndicatorColor = colorResource(id = R.color.transparent),
+                            disabledIndicatorColor = colorResource(id = R.color.transparent),
+                            unfocusedIndicatorColor = colorResource(id = R.color.transparent),
+                            cursorColor = colorResource(id = R.color.gray_splash),
+                   ),
+                   keyboardOptions = KeyboardOptions(
+                       keyboardType = KeyboardType.Password
+                   )
+               )
+
+               ExposedDropdownMenu(
+                   expanded = isExpanded,
+                   onDismissRequest = { isExpanded = !isExpanded },
+                   modifier = Modifier
+                       .background(colorResource(id = R.color.white))
+               ) {
+                   titles.forEachIndexed { _, s ->
+                       DropdownMenuItem(
+                           text = {
+                               Text(
+                                   text = s,
+                                   style = MaterialTheme.typography.titleSmall.copy(
+                                       color = colorResource(id = R.color.gray_splash)
+                                   )
+                               )
+                                  },
+                           onClick = {
+                               selectedText = s
+                               isExpanded = false
+                           },
+                           modifier = Modifier
+                               .background(colorResource(id = R.color.white))
+                       )
+                   }
+               }
+           }
+       }
+    }
+}

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

@@ -73,6 +73,7 @@ fun NewItemFormScreen(screenName: String, screenNameType: ClickTypeAddNewItem, c
                 AddSecureNoteFormScreen()
             }
             ClickTypeAddNewItem.Contact -> {
+                AddContactInfoScreen()
             }
             ClickTypeAddNewItem.Driver -> {
 

+ 13 - 0
app/src/main/res/values/strings.xml

@@ -55,6 +55,7 @@
     <string name="keep_track_online">Keep track of your online security</string>
     <string name="add_password">Add Password</string>
     <string name="title">Title</string>
+    <string name="item_title">Item\'s Title</string>
     <string name="url">URL</string>
     <string name="username">Username</string>
     <string name="password">Password</string>
@@ -96,5 +97,17 @@
     <string name="no">No</string>
     <string name="logout_account">Logout Account</string>
     <string name="sure_logout_account">Are you sure to logout the account?</string>
+    <string name="first_name">First Name</string>
+    <string name="middle_name">Middle Name</string>
+    <string name="last_name">Last Name</string>
+    <string name="address1">Address 1</string>
+    <string name="address2">Address 2</string>
+    <string name="address3">Address 3</string>
+    <string name="city_town">City / Town</string>
+    <string name="country">Country</string>
+    <string name="state">State</string>
+    <string name="zip_postal_code">ZIP / Postal Code</string>
+    <string name="please_select">Please Select</string>
+
 
 </resources>