mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 03:29:28 +01:00
enable add button only when you select contacts
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
e689e4f7f8
commit
96541b7ad8
@ -29,6 +29,7 @@ fun ContactsScreen(contactsViewModel: ContactsViewModel, uiState: ContactsUiStat
|
||||
val isSearchActive by contactsViewModel.isSearchActive.collectAsStateWithLifecycle()
|
||||
val isAddParticipants by contactsViewModel.isAddParticipantsView.collectAsStateWithLifecycle()
|
||||
val autocompleteUsers by contactsViewModel.selectedParticipantsList.collectAsStateWithLifecycle()
|
||||
val enableAddButton by contactsViewModel.enableAddButton.collectAsStateWithLifecycle()
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@ -49,7 +50,8 @@ fun ContactsScreen(contactsViewModel: ContactsViewModel, uiState: ContactsUiStat
|
||||
},
|
||||
onUpdateAutocompleteUsers = {
|
||||
contactsViewModel.getContactsFromSearchParams()
|
||||
}
|
||||
},
|
||||
enableAddButton = enableAddButton
|
||||
)
|
||||
},
|
||||
content = {
|
||||
|
@ -36,6 +36,11 @@ class ContactsViewModel @Inject constructor(
|
||||
private val _isAddParticipantsView = MutableStateFlow(false)
|
||||
val isAddParticipantsView: StateFlow<Boolean> = _isAddParticipantsView
|
||||
|
||||
private val _enableAddButton = MutableStateFlow(false)
|
||||
val enableAddButton: StateFlow<Boolean> = _enableAddButton
|
||||
|
||||
private val _selectedContacts = MutableStateFlow<List<AutocompleteUser>>(emptyList())
|
||||
|
||||
private var hideAlreadyAddedParticipants: Boolean = false
|
||||
|
||||
init {
|
||||
@ -49,11 +54,21 @@ class ContactsViewModel @Inject constructor(
|
||||
fun selectContact(contact: AutocompleteUser) {
|
||||
val updatedParticipants = selectedParticipants.value + contact
|
||||
selectedParticipants.value = updatedParticipants
|
||||
_selectedContacts.value = _selectedContacts.value + contact
|
||||
}
|
||||
|
||||
fun updateAddButtonState() {
|
||||
if (_selectedContacts.value.isEmpty()) {
|
||||
_enableAddButton.value = false
|
||||
} else {
|
||||
_enableAddButton.value = true
|
||||
}
|
||||
}
|
||||
|
||||
fun deselectContact(contact: AutocompleteUser) {
|
||||
val updatedParticipants = selectedParticipants.value - contact
|
||||
selectedParticipants.value = updatedParticipants
|
||||
_selectedContacts.value = _selectedContacts.value - contact
|
||||
}
|
||||
|
||||
fun updateSelectedParticipants(participants: List<AutocompleteUser>) {
|
||||
|
@ -42,7 +42,8 @@ fun AppBar(
|
||||
onEnableSearch: () -> Unit,
|
||||
onDisableSearch: () -> Unit,
|
||||
onUpdateSearchQuery: (String) -> Unit,
|
||||
onUpdateAutocompleteUsers: () -> Unit
|
||||
onUpdateAutocompleteUsers: () -> Unit,
|
||||
enableAddButton: Boolean
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
@ -96,11 +97,11 @@ fun AppBar(
|
||||
onClick = {
|
||||
onDisableSearch()
|
||||
onUpdateSearchQuery("")
|
||||
}
|
||||
},
|
||||
enabled = enableAddButton
|
||||
) {
|
||||
Text(text = context.getString(R.string.add_participants))
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,8 +65,10 @@ fun ContactItemRow(contact: AutocompleteUser, contactsViewModel: ContactsViewMod
|
||||
isSelected = !isSelected
|
||||
if (isSelected) {
|
||||
contactsViewModel.selectContact(contact)
|
||||
contactsViewModel.updateAddButtonState()
|
||||
} else {
|
||||
contactsViewModel.deselectContact(contact)
|
||||
contactsViewModel.updateAddButtonState()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,9 +109,3 @@ fun searchKeyboardActions(text: String, keyboardController: SoftwareKeyboardCont
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
class SearchComponentCompanionClass {
|
||||
companion object {
|
||||
const val WIDTH_RATIO = 0.85f
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user