Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-20.0] Select contacts from search #4187

Merged
merged 7 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .idea/inspectionProfiles/ktlint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 8 additions & 13 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2546,19 +2546,14 @@ class ChatActivity :

private fun isScrolledToBottom() = layoutManager?.findFirstVisibleItemPosition() == 0

private fun shouldInsertNewMessagesNotice(
newMessagesAvailable: Boolean,
chatMessageList: List<ChatMessage>
) = if (newMessagesAvailable) {
chatMessageList.any { it.actorId != conversationUser!!.userId }
} else {
false
}

private fun updateUnreadMessageInfos(
chatMessageList: List<ChatMessage>,
scrollToEndOnUpdate: Boolean
) {
private fun shouldInsertNewMessagesNotice(newMessagesAvailable: Boolean, chatMessageList: List<ChatMessage>) =
if (newMessagesAvailable) {
chatMessageList.any { it.actorId != conversationUser!!.userId }
} else {
false
}

private fun updateUnreadMessageInfos(chatMessageList: List<ChatMessage>, scrollToEndOnUpdate: Boolean) {
val unreadChatMessage = ChatMessage()
unreadChatMessage.jsonMessageId = -1
unreadChatMessage.actorId = "-1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class ContactsActivityCompose : BaseActivity() {
@Suppress("DEPRECATION")
intent.getParcelableArrayListExtra("selectedParticipants") ?: emptyList()
}
}
val participants = selectedParticipants.toSet().toMutableList()
contactsViewModel.updateSelectedParticipants(participants)
}.toSet().toMutableList()
contactsViewModel.updateSelectedParticipants(selectedParticipants)

MaterialTheme(
colorScheme = colorScheme
) {
Expand All @@ -137,8 +137,7 @@ class ContactsActivityCompose : BaseActivity() {
ContactsList(
contactsUiState = uiState.value,
contactsViewModel = contactsViewModel,
context = context,
selectedParticipants = selectedParticipants.toMutableList()
context = context
)
}
}
Expand Down Expand Up @@ -168,13 +167,8 @@ class ContactsActivityCompose : BaseActivity() {
}

@Composable
fun ContactItemRow(
contact: AutocompleteUser,
contactsViewModel: ContactsViewModel,
context: Context,
selectedContacts: MutableList<AutocompleteUser>
) {
var isSelected by remember { mutableStateOf(selectedContacts.contains(contact)) }
fun ContactItemRow(contact: AutocompleteUser, contactsViewModel: ContactsViewModel, context: Context) {
var isSelected by remember { mutableStateOf(contactsViewModel.selectedParticipantsList.value.contains(contact)) }
val roomUiState by contactsViewModel.roomViewState.collectAsState()
val isAddParticipants = contactsViewModel.isAddParticipantsView.collectAsState()
Row(
Expand All @@ -191,14 +185,11 @@ fun ContactItemRow(
)
} else {
isSelected = !isSelected
selectedContacts.apply {
if (isSelected) {
add(contact)
} else {
remove(contact)
}
if (isSelected) {
contactsViewModel.selectContact(contact)
} else {
contactsViewModel.deselectContact(contact)
}
contactsViewModel.updateSelectedParticipants(selectedContacts)
}
}
),
Expand Down Expand Up @@ -363,12 +354,7 @@ fun ConversationCreationOptions(context: Context, contactsViewModel: ContactsVie
}

@Composable
fun ContactsList(
contactsUiState: ContactsUiState,
contactsViewModel: ContactsViewModel,
context: Context,
selectedParticipants: MutableList<AutocompleteUser>
) {
fun ContactsList(contactsUiState: ContactsUiState, contactsViewModel: ContactsViewModel, context: Context) {
when (contactsUiState) {
is ContactsUiState.None -> {
}
Expand All @@ -381,7 +367,7 @@ fun ContactsList(
val contacts = contactsUiState.contacts
Log.d(CompanionClass.TAG, "Contacts:$contacts")
if (contacts != null) {
ContactsItem(contacts, contactsViewModel, context, selectedParticipants)
ContactsItem(contacts, contactsViewModel, context)
}
}
is ContactsUiState.Error -> {
Expand All @@ -395,12 +381,7 @@ fun ContactsList(

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun ContactsItem(
contacts: List<AutocompleteUser>,
contactsViewModel: ContactsViewModel,
context: Context,
selectedParticipants: MutableList<AutocompleteUser>
) {
fun ContactsItem(contacts: List<AutocompleteUser>, contactsViewModel: ContactsViewModel, context: Context) {
val groupedContacts: Map<String, List<AutocompleteUser>> = contacts.groupBy { contact ->
(
if (contact.source == "users") {
Expand Down Expand Up @@ -432,8 +413,7 @@ fun ContactsItem(
ContactItemRow(
contact = contact,
contactsViewModel = contactsViewModel,
context = context,
selectedContacts = selectedParticipants
context = context
)
Log.d(CompanionClass.TAG, "Contacts:$contact")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser
import com.nextcloud.talk.models.json.conversations.Conversation
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand All @@ -31,7 +32,7 @@ class ContactsViewModel @Inject constructor(
private val _searchState = MutableStateFlow(false)
val searchState: StateFlow<Boolean> = _searchState
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)
val isAddParticipantsView: StateFlow<Boolean> = _isAddParticipantsView

Expand All @@ -43,6 +44,16 @@ class ContactsViewModel @Inject constructor(
_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>) {
selectedParticipants.value = participants
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.nextcloud.talk.contacts

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.text.KeyboardActions
Expand All @@ -19,9 +20,9 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.ImeAction
Expand All @@ -31,12 +32,12 @@ import com.nextcloud.talk.R

@Composable
fun DisplaySearch(text: String, onTextChange: (String) -> Unit, contactsViewModel: ContactsViewModel) {
val isAddParticipants = contactsViewModel.isAddParticipantsView.collectAsState()
val keyboardController = LocalSoftwareKeyboardController.current
TextField(
modifier = Modifier
.fillMaxWidth()
.height(60.dp),
.height(60.dp)
.background(color = colorResource(id = R.color.appbar)),
value = text,
onValueChange = { onTextChange(it) },
placeholder = {
Expand Down
Loading
Loading