mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
Make contacts select and deselect via search
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
f374e6fe50
commit
9fcb1427db
@ -52,9 +52,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.DisposableEffect
|
import androidx.compose.runtime.DisposableEffect
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
@ -116,9 +114,9 @@ class ContactsActivityCompose : BaseActivity() {
|
|||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
intent.getParcelableArrayListExtra("selectedParticipants") ?: emptyList()
|
intent.getParcelableArrayListExtra("selectedParticipants") ?: emptyList()
|
||||||
}
|
}
|
||||||
}
|
}.toSet().toMutableList()
|
||||||
val participants = selectedParticipants.toSet().toMutableList()
|
contactsViewModel.updateSelectedParticipants(selectedParticipants)
|
||||||
contactsViewModel.updateSelectedParticipants(participants)
|
|
||||||
MaterialTheme(
|
MaterialTheme(
|
||||||
colorScheme = colorScheme
|
colorScheme = colorScheme
|
||||||
) {
|
) {
|
||||||
@ -137,8 +135,7 @@ class ContactsActivityCompose : BaseActivity() {
|
|||||||
ContactsList(
|
ContactsList(
|
||||||
contactsUiState = uiState.value,
|
contactsUiState = uiState.value,
|
||||||
contactsViewModel = contactsViewModel,
|
contactsViewModel = contactsViewModel,
|
||||||
context = context,
|
context = context
|
||||||
selectedParticipants = selectedParticipants.toMutableList()
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,13 +165,8 @@ class ContactsActivityCompose : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ContactItemRow(
|
fun ContactItemRow(contact: AutocompleteUser, contactsViewModel: ContactsViewModel, context: Context) {
|
||||||
contact: AutocompleteUser,
|
var isSelected = remember(contact) { contactsViewModel.selectedParticipantsList.value.contains(contact) }
|
||||||
contactsViewModel: ContactsViewModel,
|
|
||||||
context: Context,
|
|
||||||
selectedContacts: MutableList<AutocompleteUser>
|
|
||||||
) {
|
|
||||||
var isSelected by remember { mutableStateOf(selectedContacts.contains(contact)) }
|
|
||||||
val roomUiState by contactsViewModel.roomViewState.collectAsState()
|
val roomUiState by contactsViewModel.roomViewState.collectAsState()
|
||||||
val isAddParticipants = contactsViewModel.isAddParticipantsView.collectAsState()
|
val isAddParticipants = contactsViewModel.isAddParticipantsView.collectAsState()
|
||||||
Row(
|
Row(
|
||||||
@ -191,15 +183,12 @@ fun ContactItemRow(
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
isSelected = !isSelected
|
isSelected = !isSelected
|
||||||
selectedContacts.apply {
|
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
add(contact)
|
contactsViewModel.selectContact(contact)
|
||||||
} else {
|
} else {
|
||||||
remove(contact)
|
contactsViewModel.deselectContact(contact)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
contactsViewModel.updateSelectedParticipants(selectedContacts)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
@ -363,12 +352,7 @@ fun ConversationCreationOptions(context: Context, contactsViewModel: ContactsVie
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ContactsList(
|
fun ContactsList(contactsUiState: ContactsUiState, contactsViewModel: ContactsViewModel, context: Context) {
|
||||||
contactsUiState: ContactsUiState,
|
|
||||||
contactsViewModel: ContactsViewModel,
|
|
||||||
context: Context,
|
|
||||||
selectedParticipants: MutableList<AutocompleteUser>
|
|
||||||
) {
|
|
||||||
when (contactsUiState) {
|
when (contactsUiState) {
|
||||||
is ContactsUiState.None -> {
|
is ContactsUiState.None -> {
|
||||||
}
|
}
|
||||||
@ -381,7 +365,7 @@ fun ContactsList(
|
|||||||
val contacts = contactsUiState.contacts
|
val contacts = contactsUiState.contacts
|
||||||
Log.d(CompanionClass.TAG, "Contacts:$contacts")
|
Log.d(CompanionClass.TAG, "Contacts:$contacts")
|
||||||
if (contacts != null) {
|
if (contacts != null) {
|
||||||
ContactsItem(contacts, contactsViewModel, context, selectedParticipants)
|
ContactsItem(contacts, contactsViewModel, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is ContactsUiState.Error -> {
|
is ContactsUiState.Error -> {
|
||||||
@ -395,12 +379,7 @@ fun ContactsList(
|
|||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ContactsItem(
|
fun ContactsItem(contacts: List<AutocompleteUser>, contactsViewModel: ContactsViewModel, context: Context) {
|
||||||
contacts: List<AutocompleteUser>,
|
|
||||||
contactsViewModel: ContactsViewModel,
|
|
||||||
context: Context,
|
|
||||||
selectedParticipants: MutableList<AutocompleteUser>
|
|
||||||
) {
|
|
||||||
val groupedContacts: Map<String, List<AutocompleteUser>> = contacts.groupBy { contact ->
|
val groupedContacts: Map<String, List<AutocompleteUser>> = contacts.groupBy { contact ->
|
||||||
(
|
(
|
||||||
if (contact.source == "users") {
|
if (contact.source == "users") {
|
||||||
@ -432,8 +411,7 @@ fun ContactsItem(
|
|||||||
ContactItemRow(
|
ContactItemRow(
|
||||||
contact = contact,
|
contact = contact,
|
||||||
contactsViewModel = contactsViewModel,
|
contactsViewModel = contactsViewModel,
|
||||||
context = context,
|
context = context
|
||||||
selectedContacts = selectedParticipants
|
|
||||||
)
|
)
|
||||||
Log.d(CompanionClass.TAG, "Contacts:$contact")
|
Log.d(CompanionClass.TAG, "Contacts:$contact")
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser
|
|||||||
import com.nextcloud.talk.models.json.conversations.Conversation
|
import com.nextcloud.talk.models.json.conversations.Conversation
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ class ContactsViewModel @Inject constructor(
|
|||||||
private val _searchState = MutableStateFlow(false)
|
private val _searchState = MutableStateFlow(false)
|
||||||
val searchState: StateFlow<Boolean> = _searchState
|
val searchState: StateFlow<Boolean> = _searchState
|
||||||
private val selectedParticipants = MutableStateFlow<List<AutocompleteUser>>(emptyList())
|
private val selectedParticipants = MutableStateFlow<List<AutocompleteUser>>(emptyList())
|
||||||
val selectedParticipantsList: StateFlow<List<AutocompleteUser>> = selectedParticipants
|
val selectedParticipantsList: StateFlow<List<AutocompleteUser>> = selectedParticipants.asStateFlow()
|
||||||
private val _isAddParticipantsView = MutableStateFlow(false)
|
private val _isAddParticipantsView = MutableStateFlow(false)
|
||||||
val isAddParticipantsView: StateFlow<Boolean> = _isAddParticipantsView
|
val isAddParticipantsView: StateFlow<Boolean> = _isAddParticipantsView
|
||||||
|
|
||||||
@ -43,6 +44,16 @@ class ContactsViewModel @Inject constructor(
|
|||||||
_searchQuery.value = query
|
_searchQuery.value = query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun selectContact(contact: AutocompleteUser) {
|
||||||
|
val updatedParticipants = selectedParticipants.value + contact
|
||||||
|
selectedParticipants.value = updatedParticipants
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deselectContact(contact: AutocompleteUser) {
|
||||||
|
val updatedParticipants = selectedParticipants.value - contact
|
||||||
|
selectedParticipants.value = updatedParticipants
|
||||||
|
}
|
||||||
|
|
||||||
fun updateSelectedParticipants(participants: List<AutocompleteUser>) {
|
fun updateSelectedParticipants(participants: List<AutocompleteUser>) {
|
||||||
selectedParticipants.value = participants
|
selectedParticipants.value = participants
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ import androidx.compose.material3.IconButton
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextField
|
import androidx.compose.material3.TextField
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@ -31,7 +30,6 @@ import com.nextcloud.talk.R
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DisplaySearch(text: String, onTextChange: (String) -> Unit, contactsViewModel: ContactsViewModel) {
|
fun DisplaySearch(text: String, onTextChange: (String) -> Unit, contactsViewModel: ContactsViewModel) {
|
||||||
val isAddParticipants = contactsViewModel.isAddParticipantsView.collectAsState()
|
|
||||||
val keyboardController = LocalSoftwareKeyboardController.current
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
TextField(
|
TextField(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
Loading…
Reference in New Issue
Block a user