mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-23 12:45:01 +01:00
Properly select and deselect contact items
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
5f3d73efce
commit
ff63bcd855
@ -11,6 +11,7 @@ import android.annotation.SuppressLint
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
@ -49,7 +50,9 @@ import androidx.compose.material3.TopAppBar
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
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
|
||||||
@ -88,7 +91,6 @@ class ContactsActivityCompose : BaseActivity() {
|
|||||||
contactsViewModel = ViewModelProvider(this, viewModelFactory)[ContactsViewModel::class.java]
|
contactsViewModel = ViewModelProvider(this, viewModelFactory)[ContactsViewModel::class.java]
|
||||||
setContent {
|
setContent {
|
||||||
val isAddParticipants = intent.getBooleanExtra("isAddParticipants", false)
|
val isAddParticipants = intent.getBooleanExtra("isAddParticipants", false)
|
||||||
val isAddParticipantsEdit = intent.getBooleanExtra("isAddParticipantsEdit", false)
|
|
||||||
contactsViewModel.updateIsAddParticipants(isAddParticipants)
|
contactsViewModel.updateIsAddParticipants(isAddParticipants)
|
||||||
if (isAddParticipants) {
|
if (isAddParticipants) {
|
||||||
contactsViewModel.updateShareTypes(
|
contactsViewModel.updateShareTypes(
|
||||||
@ -102,11 +104,12 @@ class ContactsActivityCompose : BaseActivity() {
|
|||||||
}
|
}
|
||||||
val colorScheme = viewThemeUtils.getColorScheme(this)
|
val colorScheme = viewThemeUtils.getColorScheme(this)
|
||||||
val uiState = contactsViewModel.contactsViewState.collectAsState()
|
val uiState = contactsViewModel.contactsViewState.collectAsState()
|
||||||
val selectedParticipants: List<AutocompleteUser> = remember {
|
val selectedParticipants = remember {
|
||||||
if (isAddParticipants) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
intent.getParcelableArrayListExtra("selected participants") ?: emptyList()
|
intent.getParcelableArrayListExtra("selectedParticipants", AutocompleteUser::class.java) ?: emptyList()
|
||||||
} else {
|
} else {
|
||||||
emptyList()
|
@Suppress("DEPRECATION")
|
||||||
|
intent.getParcelableArrayListExtra("selectedParticipants") ?: emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val participants = selectedParticipants.toSet().toMutableList()
|
val participants = selectedParticipants.toSet().toMutableList()
|
||||||
@ -147,13 +150,14 @@ fun ContactItemRow(
|
|||||||
context: Context,
|
context: Context,
|
||||||
selectedContacts: MutableList<AutocompleteUser>
|
selectedContacts: MutableList<AutocompleteUser>
|
||||||
) {
|
) {
|
||||||
val isSelected = selectedContacts.contains(contact)
|
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(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable {
|
.clickable(
|
||||||
|
onClick = {
|
||||||
if (!isAddParticipants.value) {
|
if (!isAddParticipants.value) {
|
||||||
contactsViewModel.createRoom(
|
contactsViewModel.createRoom(
|
||||||
CompanionClass.ROOM_TYPE_ONE_ONE,
|
CompanionClass.ROOM_TYPE_ONE_ONE,
|
||||||
@ -162,14 +166,18 @@ fun ContactItemRow(
|
|||||||
null
|
null
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
isSelected = !isSelected
|
||||||
|
selectedContacts.apply {
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
selectedContacts.remove(contact)
|
add(contact)
|
||||||
} else {
|
} else {
|
||||||
selectedContacts.add(contact)
|
remove(contact)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
contactsViewModel.updateSelectedParticipants(selectedContacts)
|
contactsViewModel.updateSelectedParticipants(selectedContacts)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
val imageUri = contact.id?.let { contactsViewModel.getImageUri(it, true) }
|
val imageUri = contact.id?.let { contactsViewModel.getImageUri(it, true) }
|
||||||
@ -181,7 +189,8 @@ fun ContactItemRow(
|
|||||||
modifier = Modifier.size(width = 45.dp, height = 45.dp)
|
modifier = Modifier.size(width = 45.dp, height = 45.dp)
|
||||||
)
|
)
|
||||||
Text(modifier = Modifier.padding(16.dp), text = contact.label!!)
|
Text(modifier = Modifier.padding(16.dp), text = contact.label!!)
|
||||||
if (isAddParticipants.value && isSelected) {
|
if (isAddParticipants.value) {
|
||||||
|
if (isSelected) {
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = ImageVector.vectorResource(id = R.drawable.ic_check_circle),
|
imageVector = ImageVector.vectorResource(id = R.drawable.ic_check_circle),
|
||||||
@ -191,6 +200,7 @@ fun ContactItemRow(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
when (roomUiState) {
|
when (roomUiState) {
|
||||||
is RoomUiState.Success -> {
|
is RoomUiState.Success -> {
|
||||||
val conversation = (roomUiState as RoomUiState.Success).conversation
|
val conversation = (roomUiState as RoomUiState.Success).conversation
|
||||||
@ -238,17 +248,17 @@ fun AppBar(title: String, context: Context, contactsViewModel: ContactsViewModel
|
|||||||
Text(
|
Text(
|
||||||
text = stringResource(id = R.string.nc_contacts_done),
|
text = stringResource(id = R.string.nc_contacts_done),
|
||||||
modifier = Modifier.clickable {
|
modifier = Modifier.clickable {
|
||||||
val activity = context as? Activity
|
|
||||||
val resultIntent = Intent().apply {
|
val resultIntent = Intent().apply {
|
||||||
putParcelableArrayListExtra(
|
putParcelableArrayListExtra(
|
||||||
"selectedParticipants",
|
"selectedParticipants",
|
||||||
|
ArrayList(
|
||||||
contactsViewModel
|
contactsViewModel
|
||||||
.selectedParticipantsList as
|
.selectedParticipantsList.value
|
||||||
ArrayList<AutocompleteUser>
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
activity?.setResult(Activity.RESULT_OK, resultIntent)
|
(context as? Activity)?.setResult(Activity.RESULT_OK, resultIntent)
|
||||||
activity?.finish()
|
(context as? Activity)?.finish()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ class ContactsViewModel @Inject constructor(
|
|||||||
val shareTypeList: List<String> = shareTypes
|
val shareTypeList: List<String> = shareTypes
|
||||||
private val _searchState = MutableStateFlow(false)
|
private val _searchState = MutableStateFlow(false)
|
||||||
val searchState: StateFlow<Boolean> = _searchState
|
val searchState: StateFlow<Boolean> = _searchState
|
||||||
private val selectedParticipants = mutableListOf<AutocompleteUser>()
|
private val _selectedParticipants = MutableStateFlow<List<AutocompleteUser>>(emptyList())
|
||||||
val selectedParticipantsList: List<AutocompleteUser> = selectedParticipants
|
val selectedParticipantsList: StateFlow<List<AutocompleteUser>> = _selectedParticipants
|
||||||
private val _isAddParticipantsView = MutableStateFlow(false)
|
private val _isAddParticipantsView = MutableStateFlow(false)
|
||||||
val isAddParticipantsView: StateFlow<Boolean> = _isAddParticipantsView
|
val isAddParticipantsView: StateFlow<Boolean> = _isAddParticipantsView
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class ContactsViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateSelectedParticipants(participants: List<AutocompleteUser>) {
|
fun updateSelectedParticipants(participants: List<AutocompleteUser>) {
|
||||||
selectedParticipants.addAll(participants)
|
_selectedParticipants.value = participants
|
||||||
}
|
}
|
||||||
fun updateSearchState(searchState: Boolean) {
|
fun updateSearchState(searchState: Boolean) {
|
||||||
_searchState.value = searchState
|
_searchState.value = searchState
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@file:Suppress("DEPRECATION")
|
||||||
|
|
||||||
package com.nextcloud.talk.conversationcreation
|
package com.nextcloud.talk.conversationcreation
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
@ -267,7 +269,7 @@ fun AddParticipants(
|
|||||||
.clickable {
|
.clickable {
|
||||||
val intent = Intent(context, ContactsActivityCompose::class.java)
|
val intent = Intent(context, ContactsActivityCompose::class.java)
|
||||||
intent.putParcelableArrayListExtra(
|
intent.putParcelableArrayListExtra(
|
||||||
"selected participants",
|
"selectedParticipants",
|
||||||
participants as ArrayList<AutocompleteUser>
|
participants as ArrayList<AutocompleteUser>
|
||||||
)
|
)
|
||||||
intent.putExtra("isAddParticipants", true)
|
intent.putExtra("isAddParticipants", true)
|
||||||
@ -278,10 +280,7 @@ fun AddParticipants(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
participants.toSet().forEach { participant ->
|
||||||
val participant = participants.toSet()
|
|
||||||
|
|
||||||
participant.forEach { participant ->
|
|
||||||
Row(modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
Row(modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||||
val imageUri = participant.id?.let { conversationCreationViewModel.getImageUri(it, true) }
|
val imageUri = participant.id?.let { conversationCreationViewModel.getImageUri(it, true) }
|
||||||
val errorPlaceholderImage: Int = R.drawable.account_circle_96dp
|
val errorPlaceholderImage: Int = R.drawable.account_circle_96dp
|
||||||
@ -312,7 +311,7 @@ fun AddParticipants(
|
|||||||
},
|
},
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
if (participant.isEmpty()) {
|
if (participants.isEmpty()) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.ic_account_plus),
|
painter = painterResource(id = R.drawable.ic_account_plus),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
@ -329,17 +328,16 @@ fun AddParticipants(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RoomCreationOptions(conversationCreationViewModel: ConversationCreationViewModel) {
|
fun RoomCreationOptions(conversationCreationViewModel: ConversationCreationViewModel) {
|
||||||
var isGuestsAllowed = conversationCreationViewModel.isGuestsAllowed.value
|
val isGuestsAllowed = conversationCreationViewModel.isGuestsAllowed.value
|
||||||
var isConversationAvailableForRegisteredUsers = conversationCreationViewModel
|
val isConversationAvailableForRegisteredUsers = conversationCreationViewModel
|
||||||
.isConversationAvailableForRegisteredUsers.value
|
.isConversationAvailableForRegisteredUsers.value
|
||||||
var isOpenForGuestAppUsers = conversationCreationViewModel.openForGuestAppUsers.value
|
val isOpenForGuestAppUsers = conversationCreationViewModel.openForGuestAppUsers.value
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(id = R.string.nc_visible).uppercase(),
|
text = stringResource(id = R.string.nc_visible).uppercase(),
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
modifier = Modifier.padding(top = 24.dp, start = 16.dp, end = 16.dp)
|
modifier = Modifier.padding(top = 24.dp, start = 16.dp, end = 16.dp)
|
||||||
)
|
)
|
||||||
|
|
||||||
ConversationOptions(
|
ConversationOptions(
|
||||||
icon = R.drawable.ic_avatar_link,
|
icon = R.drawable.ic_avatar_link,
|
||||||
text = R.string.nc_guest_access_allow_title,
|
text = R.string.nc_guest_access_allow_title,
|
||||||
@ -458,17 +456,17 @@ fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: Con
|
|||||||
conversationCreationViewModel.updatePassword(password)
|
conversationCreationViewModel.updatePassword(password)
|
||||||
onDismiss()
|
onDismiss()
|
||||||
}) {
|
}) {
|
||||||
Text(text = "Save")
|
Text(text = stringResource(id = R.string.save))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
title = { Text(text = "Set Password") },
|
title = { Text(text = stringResource(id = R.string.nc_set_password)) },
|
||||||
text = {
|
text = {
|
||||||
TextField(
|
TextField(
|
||||||
value = password,
|
value = password,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
password = it
|
password = it
|
||||||
},
|
},
|
||||||
label = { Text(text = "Enter a password") }
|
label = { Text(text = stringResource(id = R.string.nc_guest_access_password_dialog_hint)) }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
package com.nextcloud.talk.conversationcreation
|
package com.nextcloud.talk.conversationcreation
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.compose.runtime.MutableState
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
@ -42,14 +41,8 @@ class ConversationCreationViewModel @Inject constructor(
|
|||||||
var isGuestsAllowed = mutableStateOf(false)
|
var isGuestsAllowed = mutableStateOf(false)
|
||||||
var isConversationAvailableForRegisteredUsers = mutableStateOf(false)
|
var isConversationAvailableForRegisteredUsers = mutableStateOf(false)
|
||||||
var openForGuestAppUsers = mutableStateOf(false)
|
var openForGuestAppUsers = mutableStateOf(false)
|
||||||
private val scope: MutableState<Int?> = mutableStateOf(null)
|
|
||||||
|
|
||||||
private val addParticipantsViewState = MutableStateFlow<AddParticipantsUiState>(AddParticipantsUiState.None)
|
private val addParticipantsViewState = MutableStateFlow<AddParticipantsUiState>(AddParticipantsUiState.None)
|
||||||
val addParticipantsUiState: StateFlow<AddParticipantsUiState> = addParticipantsViewState
|
|
||||||
|
|
||||||
private val _allowGuestsResult = MutableStateFlow<AllowGuestsUiState>(AllowGuestsUiState.None)
|
private val _allowGuestsResult = MutableStateFlow<AllowGuestsUiState>(AllowGuestsUiState.None)
|
||||||
val allowGuestsResult: StateFlow<AllowGuestsUiState> = _allowGuestsResult
|
|
||||||
|
|
||||||
fun updateRoomName(roomName: String) {
|
fun updateRoomName(roomName: String) {
|
||||||
_roomName.value = roomName
|
_roomName.value = roomName
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user