Skip to content

Commit

Permalink
Allow searching contacts when adding to existing
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Mar 1, 2023
1 parent 74a636f commit 238ebd5
Showing 1 changed file with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.bnyro.contacts.ui.components.dialogs

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -28,6 +31,7 @@ import com.bnyro.contacts.ui.models.ContactsModel
import com.bnyro.contacts.ui.screens.EditorScreen
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AddToContactDialog(
newNumber: String
Expand All @@ -46,6 +50,10 @@ fun AddToContactDialog(
val scope = rememberCoroutineScope()

if (showDialog) {
var searchQuery by remember {
mutableStateOf("")
}

AlertDialog(
onDismissRequest = { showDialog = false },
confirmButton = {
Expand All @@ -57,27 +65,47 @@ fun AddToContactDialog(
Text(text = stringResource(R.string.add_to_contact))
},
text = {
LazyColumn(
modifier = Modifier.height(400.dp)
) {
items(contactsModel.contacts.orEmpty()) {
Text(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(20.dp))
.clickable {
scope.launch {
contactToEdit = contactsModel.loadAdvancedContactData(it).apply {
it.numbers = it.numbers.toMutableList().apply {
add(ValueWithType(newNumber, 0))
Column {
OutlinedTextField(
modifier = Modifier.padding(bottom = 10.dp),
value = searchQuery,
onValueChange = { searchQuery = it },
label = {
Text(stringResource(R.string.search))
}
)

LazyColumn(
modifier = Modifier.height(400.dp)
) {
items(
contactsModel.contacts.orEmpty()
.filter {
it.displayName.orEmpty().lowercase().contains(
searchQuery.lowercase()
)
}
) {
Text(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(20.dp))
.clickable {
scope.launch {
contactToEdit = contactsModel.loadAdvancedContactData(
it
).apply {
it.numbers = it.numbers.toMutableList().apply {
add(ValueWithType(newNumber, 0))
}
}
}
showDialog = false
}
showDialog = false
}
.padding(vertical = 15.dp, horizontal = 20.dp),
text = it.displayName.orEmpty()
)
.padding(vertical = 15.dp, horizontal = 20.dp),
text = it.displayName.orEmpty()
)
}
}
}
}
Expand Down

0 comments on commit 238ebd5

Please sign in to comment.