From 36c82dd38ca2e2f93bf2682a2ffc53df059a2b64 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Mon, 19 Aug 2024 23:48:44 +0200 Subject: [PATCH] Start ContactsActivity to edit participants Signed-off-by: sowjanyakch --- .../talk/contacts/ContactsActivityCompose.kt | 156 +++++++-- .../talk/contacts/ContactsViewModel.kt | 2 +- .../nextcloud/talk/contacts/ContentItem.kt | 118 ------- .../ConversationCreationActivity.kt | 304 ++++++++---------- .../ConversationCreationRepository.kt | 1 + .../ConversationCreationRepositoryImpl.kt | 8 + .../ConversationCreationViewModel.kt | 11 + 7 files changed, 296 insertions(+), 304 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/talk/contacts/ContentItem.kt diff --git a/app/src/main/java/com/nextcloud/talk/contacts/ContactsActivityCompose.kt b/app/src/main/java/com/nextcloud/talk/contacts/ContactsActivityCompose.kt index f8d7f6f25b5..aae3316a30f 100644 --- a/app/src/main/java/com/nextcloud/talk/contacts/ContactsActivityCompose.kt +++ b/app/src/main/java/com/nextcloud/talk/contacts/ContactsActivityCompose.kt @@ -12,11 +12,15 @@ import android.app.Activity import android.content.Context import android.content.Intent import android.os.Bundle -import android.os.Parcelable +import android.util.Log import androidx.activity.compose.setContent +import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.background import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize @@ -26,15 +30,20 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentHeight +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.automirrored.filled.List import androidx.compose.material.icons.filled.Search +import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable @@ -48,6 +57,7 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.vectorResource +import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.lifecycle.ViewModelProvider @@ -75,21 +85,28 @@ class ContactsActivityCompose : BaseActivity() { super.onCreate(savedInstanceState) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) contactsViewModel = ViewModelProvider(this, viewModelFactory)[ContactsViewModel::class.java] - val isAddParticipants = intent.getBooleanExtra("isAddParticipants", false) - contactsViewModel.updateIsAddParticipants(isAddParticipants) - if (isAddParticipants) { - contactsViewModel.updateShareTypes( - listOf( - ShareType.Group.shareType, - ShareType.Email.shareType, - ShareType.Circle.shareType - ) - ) - contactsViewModel.getContactsFromSearchParams() - } setContent { + val isAddParticipants = intent.getBooleanExtra("isAddParticipants", false) + val isAddParticipantsEdit = intent.getBooleanExtra("isAddParticipantsEdit", false) + contactsViewModel.updateIsAddParticipants(isAddParticipants) + if (isAddParticipants) { + contactsViewModel.updateShareTypes( + listOf( + ShareType.Group.shareType, + ShareType.Email.shareType, + ShareType.Circle.shareType + ) + ) + contactsViewModel.getContactsFromSearchParams() + } val colorScheme = viewThemeUtils.getColorScheme(this) val uiState = contactsViewModel.contactsViewState.collectAsState() + val selectedParticipants: List = if (isAddParticipantsEdit) { + intent.getParcelableArrayListExtra("selectedParticipants") ?: emptyList() + } else { + emptyList() + } + contactsViewModel.updateSelectedParticipants(selectedParticipants) MaterialTheme( colorScheme = colorScheme ) { @@ -108,7 +125,8 @@ class ContactsActivityCompose : BaseActivity() { ContactsList( contactsUiState = uiState.value, contactsViewModel = contactsViewModel, - context = context + context = context, + selectedParticipants = selectedParticipants.toMutableList() ) } } @@ -218,13 +236,17 @@ fun AppBar(title: String, context: Context, contactsViewModel: ContactsViewModel Text( text = stringResource(id = R.string.nc_contacts_done), modifier = Modifier.clickable { - val selectedParticipants: List = contactsViewModel.selectedParticipantsList - val intent = Intent(context, ConversationCreationActivity::class.java) - intent.putParcelableArrayListExtra( - "selectedParticipants", - selectedParticipants as ArrayList - ) - context.startActivity(intent) + val activity = context as? Activity + val resultIntent = Intent().apply { + putParcelableArrayListExtra( + "selectedParticipants", + contactsViewModel + .selectedParticipantsList as + ArrayList + ) + } + activity?.setResult(Activity.RESULT_OK, resultIntent) + activity?.finish() } ) } @@ -304,6 +326,98 @@ fun ConversationCreationOptions(context: Context, contactsViewModel: ContactsVie } } +@Composable +fun ContactsList( + contactsUiState: ContactsUiState, + contactsViewModel: ContactsViewModel, + context: Context, + selectedParticipants: MutableList +) { + when (contactsUiState) { + is ContactsUiState.None -> { + } + is ContactsUiState.Loading -> { + Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + CircularProgressIndicator() + } + } + is ContactsUiState.Success -> { + val contacts = contactsUiState.contacts + Log.d(CompanionClass.TAG, "Contacts:$contacts") + if (contacts != null) { + ContactsItem(contacts, contactsViewModel, context, selectedParticipants) + } + } + is ContactsUiState.Error -> { + val errorMessage = contactsUiState.message + Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + Text(text = "Error: $errorMessage", color = Color.Red) + } + } + } +} + +@OptIn(ExperimentalFoundationApi::class) +@Composable +fun ContactsItem( + contacts: List, + contactsViewModel: ContactsViewModel, + context: Context, + selectedParticipants: MutableList +) { + val groupedContacts: Map> = contacts.groupBy { contact -> + ( + if (contact.source == "users") { + contact.label?.first()?.uppercase() + } else { + contact.source?.replaceFirstChar { actorType -> + actorType.uppercase() + } + } + ).toString() + } + LazyColumn( + modifier = Modifier + .padding(8.dp) + .fillMaxWidth(), + contentPadding = PaddingValues(all = 10.dp), + verticalArrangement = Arrangement.spacedBy(10.dp) + ) { + groupedContacts.forEach { (initial, contactsForInitial) -> + stickyHeader { + Column { + Surface(Modifier.fillParentMaxWidth()) { + Header(initial) + } + HorizontalDivider(thickness = 0.1.dp, color = Color.Black) + } + } + items(contactsForInitial) { contact -> + ContactItemRow( + contact = contact, + contactsViewModel = contactsViewModel, + context = context, + selectedContacts = selectedParticipants + ) + Log.d(CompanionClass.TAG, "Contacts:$contact") + } + } + } +} + +@Composable +fun Header(header: String) { + Text( + text = header, + modifier = Modifier + .fillMaxSize() + .background(Color.Transparent) + .padding(start = 60.dp), + color = Color.Blue, + fontWeight = FontWeight.Bold + ) +} + class CompanionClass { companion object { internal val TAG = ContactsActivityCompose::class.simpleName diff --git a/app/src/main/java/com/nextcloud/talk/contacts/ContactsViewModel.kt b/app/src/main/java/com/nextcloud/talk/contacts/ContactsViewModel.kt index 7cbf47db480..6de632a7e7b 100644 --- a/app/src/main/java/com/nextcloud/talk/contacts/ContactsViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/contacts/ContactsViewModel.kt @@ -31,7 +31,7 @@ class ContactsViewModel @Inject constructor( private val _searchState = MutableStateFlow(false) val searchState: StateFlow = _searchState private val selectedParticipants = mutableListOf() - val selectedParticipantsList: List = selectedParticipants + val selectedParticipantsList: MutableList = selectedParticipants private val _isAddParticipantsView = MutableStateFlow(false) val isAddParticipantsView: StateFlow = _isAddParticipantsView diff --git a/app/src/main/java/com/nextcloud/talk/contacts/ContentItem.kt b/app/src/main/java/com/nextcloud/talk/contacts/ContentItem.kt deleted file mode 100644 index e1cd47940ea..00000000000 --- a/app/src/main/java/com/nextcloud/talk/contacts/ContentItem.kt +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Nextcloud Talk - Android Client - * - * SPDX-FileCopyrightText: 2024 Your Name - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -package com.nextcloud.talk.contacts - -import android.content.Context -import android.util.Log -import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items -import androidx.compose.material3.CircularProgressIndicator -import androidx.compose.material3.HorizontalDivider -import androidx.compose.material3.Surface -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.mutableStateListOf -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.unit.dp -import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser - -@Composable -fun ContactsList(contactsUiState: ContactsUiState, contactsViewModel: ContactsViewModel, context: Context) { - when (contactsUiState) { - is ContactsUiState.None -> { - } - is ContactsUiState.Loading -> { - Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { - CircularProgressIndicator() - } - } - is ContactsUiState.Success -> { - val contacts = contactsUiState.contacts - Log.d(CompanionClass.TAG, "Contacts:$contacts") - if (contacts != null) { - ContactsItem(contacts, contactsViewModel, context) - } - } - is ContactsUiState.Error -> { - val errorMessage = contactsUiState.message - Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { - Text(text = "Error: $errorMessage", color = Color.Red) - } - } - } -} - -@OptIn(ExperimentalFoundationApi::class) -@Composable -fun ContactsItem(contacts: List, contactsViewModel: ContactsViewModel, context: Context) { - val groupedContacts: Map> = contacts.groupBy { contact -> - ( - if (contact.source == "users") { - contact.label?.first()?.uppercase() - } else { - contact.source?.replaceFirstChar { actorType -> - actorType.uppercase() - } - } - ).toString() - } - val selectedContacts = remember { mutableStateListOf() } - LazyColumn( - modifier = Modifier - .padding(8.dp) - .fillMaxWidth(), - contentPadding = PaddingValues(all = 10.dp), - verticalArrangement = Arrangement.spacedBy(10.dp) - ) { - groupedContacts.forEach { (initial, contactsForInitial) -> - stickyHeader { - Column { - Surface(Modifier.fillParentMaxWidth()) { - Header(initial) - } - HorizontalDivider(thickness = 0.1.dp, color = Color.Black) - } - } - items(contactsForInitial) { contact -> - ContactItemRow( - contact = contact, - contactsViewModel = contactsViewModel, - context = context, - selectedContacts = selectedContacts - ) - Log.d(CompanionClass.TAG, "Contacts:$contact") - } - } - } -} - -@Composable -fun Header(header: String) { - Text( - text = header, - modifier = Modifier - .fillMaxSize() - .background(Color.Transparent) - .padding(start = 60.dp), - color = Color.Blue, - fontWeight = FontWeight.Bold - ) -} diff --git a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt index 2092eb8adaa..f7363fdd095 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt @@ -7,24 +7,29 @@ package com.nextcloud.talk.conversationcreation +import android.annotation.SuppressLint import android.app.Activity import android.content.Context import android.content.Intent -import android.os.Build import android.os.Bundle +import androidx.activity.compose.ManagedActivityResultLauncher +import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.compose.setContent +import androidx.activity.result.ActivityResult +import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material3.Button @@ -56,6 +61,7 @@ import com.nextcloud.talk.R import com.nextcloud.talk.activities.BaseActivity import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.contacts.ContactsActivityCompose +import com.nextcloud.talk.contacts.loadImage import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser import javax.inject.Inject @@ -63,58 +69,74 @@ import javax.inject.Inject class ConversationCreationActivity : BaseActivity() { @Inject lateinit var viewModelFactory: ViewModelProvider.Factory - private lateinit var conversationCreationViewModel: ConversationCreationViewModel - @OptIn(ExperimentalMaterial3Api::class) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) - conversationCreationViewModel = - ViewModelProvider(this, viewModelFactory)[ConversationCreationViewModel::class.java] - val selectedParticipants: List? = when ( - Build.VERSION.SDK_INT >= Build.VERSION_CODES - .TIRAMISU - ) { - true -> intent.getParcelableArrayListExtra("selectedParticipants") - else -> intent.extras?.getParcelableArrayList("selectedParticipants") - } ?: emptyList() + NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) + val conversationCreationViewModel = ViewModelProvider( + this, + viewModelFactory + )[ConversationCreationViewModel::class.java] setContent { val colorScheme = viewThemeUtils.getColorScheme(this) MaterialTheme( colorScheme = colorScheme ) { - val context = LocalContext.current - Scaffold( - topBar = { - TopAppBar( - title = { Text(text = stringResource(id = R.string.nc_new_conversation)) }, - navigationIcon = { - IconButton(onClick = { - (context as? Activity)?.finish() - }) { - Icon( - Icons.AutoMirrored.Filled.ArrowBack, - contentDescription = stringResource(R.string.back_button) - ) - } - } + ConversationCreationScreen(conversationCreationViewModel) + } + } + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun ConversationCreationScreen(conversationCreationViewModel: ConversationCreationViewModel) { + val context = LocalContext.current + val launcher = rememberLauncherForActivityResult( + contract = ActivityResultContracts.StartActivityForResult(), + + onResult = { result -> + if (result.resultCode == Activity.RESULT_OK) { + val data = result.data + val selectedParticipants = data?.getParcelableArrayListExtra("selectedParticipants") + ?: emptyList() + conversationCreationViewModel.updateSelectedParticipants(selectedParticipants) + } + } + ) + + Scaffold( + topBar = { + TopAppBar( + title = { Text(text = stringResource(id = R.string.nc_new_conversation)) }, + navigationIcon = { + IconButton(onClick = { + (context as? Activity)?.finish() + }) { + Icon( + Icons.AutoMirrored.Filled.ArrowBack, + contentDescription = stringResource(id = R.string.back_button) ) - }, - content = { - Column(Modifier.padding(it)) { - DefaultUserAvatar() - UploadAvatar() - ConversationNameAndDescription(conversationCreationViewModel) - AddParticipants(selectedParticipants, context) - RoomCreationOptions(conversationCreationViewModel) - CreateConversation() - } } - ) + } + ) + }, + content = { paddingValues -> + Column( + modifier = Modifier + .padding(paddingValues) + .verticalScroll(rememberScrollState()) + ) { + DefaultUserAvatar() + UploadAvatar() + ConversationNameAndDescription(conversationCreationViewModel) + AddParticipants(launcher, context, conversationCreationViewModel) + RoomCreationOptions(conversationCreationViewModel) + CreateConversation() } } - } + ) } @Composable @@ -196,7 +218,7 @@ fun ConversationNameAndDescription(conversationCreationViewModel: ConversationCr OutlinedTextField( value = conversationDescription.value, onValueChange = { - conversationCreationViewModel.updateRoomName(it) + conversationCreationViewModel.updateConversationDescription(it) }, label = { Text(text = stringResource(id = R.string.nc_conversation_description)) }, modifier = Modifier @@ -205,59 +227,88 @@ fun ConversationNameAndDescription(conversationCreationViewModel: ConversationCr ) } +@SuppressLint("SuspiciousIndentation") @Composable -fun AddParticipants(selectedParticipants: List?, context: Context) { - Row { - Text( - text = stringResource(id = R.string.nc_participants).uppercase(), - fontSize = 14.sp, - modifier = Modifier.padding(top = 24.dp, start = 16.dp, end = 16.dp, bottom = 16.dp) - ) - if (selectedParticipants?.isNotEmpty() == true) { - Text( - text = stringResource(id = R.string.nc_edit), - fontSize = 12.sp, - modifier = Modifier.padding(top = 24.dp, start = 16.dp, end = 16.dp, bottom = 16.dp) - .clickable { - val intent = Intent(context, ContactsActivityCompose::class.java) - context.startActivity(intent) - }, - textAlign = TextAlign.Right - ) - } - } +fun AddParticipants( + launcher: ManagedActivityResultLauncher, + context: Context, + conversationCreationViewModel: ConversationCreationViewModel +) { + val participants = conversationCreationViewModel.selectedParticipants.collectAsState() - Row( - modifier = Modifier - .padding(start = 16.dp, end = 16.dp) - .clickable { - val intent = Intent(context, ContactsActivityCompose::class.java) - intent.putExtra("isAddParticipants", true) - context.startActivity(intent) - }, - verticalAlignment = Alignment - .CenterVertically + Column( + modifier = Modifier.fillMaxHeight() + .padding(start = 16.dp, end = 16.dp, top = 16.dp) ) { - if (selectedParticipants?.isEmpty() == true) { - Icon( - painter = painterResource(id = R.drawable.ic_account_plus), - contentDescription = null, - modifier = Modifier.size(24.dp) + Row { + Text( + text = stringResource(id = R.string.nc_participants).uppercase(), + fontSize = 14.sp, + modifier = Modifier.padding(start = 16.dp, bottom = 16.dp) ) + Spacer(modifier = Modifier.weight(1f)) + if (participants.value.isNotEmpty()) { + Text( + text = stringResource(id = R.string.nc_edit), + fontSize = 12.sp, + modifier = Modifier + .padding(start = 16.dp, bottom = 16.dp) + .clickable { + val intent = Intent(context, ContactsActivityCompose::class.java) + intent.putParcelableArrayListExtra( + "selected participants", + participants.value as ArrayList + ) + intent.putExtra("isAddParticipantsEdit", true) + launcher.launch(intent) + }, + textAlign = TextAlign.Right + ) + } + } - Text(text = stringResource(id = R.string.nc_add_participants), modifier = Modifier.padding(start = 16.dp)) - } else { - LazyColumn { - items(selectedParticipants!!) { participant -> - participant.label?.let { - Text( - text = it, - modifier = Modifier.padding(all = 16.dp) - ) - } - HorizontalDivider(thickness = 0.1.dp, color = Color.Black) + participants.value.forEach { participant -> + Row(modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) { + val imageUri = participant.id?.let { conversationCreationViewModel.getImageUri(it, true) } + val errorPlaceholderImage: Int = R.drawable.account_circle_96dp + val loadedImage = loadImage(imageUri, context, errorPlaceholderImage) + AsyncImage( + model = loadedImage, + contentDescription = stringResource(id = R.string.user_avatar), + modifier = Modifier.size(width = 32.dp, height = 32.dp) + ) + participant.label?.let { + Text( + text = it, + modifier = Modifier.padding(all = 16.dp), + fontSize = 15.sp + ) } } + HorizontalDivider(thickness = 0.1.dp, color = Color.Black) + } + + Row( + modifier = Modifier + .fillMaxWidth() + .clickable { + val intent = Intent(context, ContactsActivityCompose::class.java) + intent.putExtra("isAddParticipants", true) + launcher.launch(intent) + }, + verticalAlignment = Alignment.CenterVertically + ) { + if (participants.value.isEmpty()) { + Icon( + painter = painterResource(id = R.drawable.ic_account_plus), + contentDescription = null, + modifier = Modifier.size(24.dp) + ) + Text( + text = stringResource(id = R.string.nc_add_participants), + modifier = Modifier.padding(start = 16.dp) + ) + } } } } @@ -366,78 +417,3 @@ fun CreateConversation() { } } } - -// -// @SuppressLint("UnrememberedMutableState") -// @OptIn(ExperimentalMaterial3Api::class) -// @Composable -// fun AppBar(title: String, context: Context, contactsViewModel: ContactsViewModel) { -// val searchQuery by contactsViewModel.searchQuery.collectAsState() -// val searchState = contactsViewModel.searchState.collectAsState() -// val addParticipantsUiState = contactsViewModel.addParticipantsUiState.collectAsState() -// val conversationToken:String? = null -// -// TopAppBar( -// title = { Text(text = title) }, -// navigationIcon = { -// IconButton(onClick = { -// (context as? Activity)?.finish() -// }) { -// Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = stringResource(R.string.back_button)) -// } -// }, -// actions = { -// IconButton(onClick = { -// contactsViewModel.updateSearchState(true) -// }) { -// Icon(Icons.Filled.Search, contentDescription = stringResource(R.string.search_icon)) -// } -// if (contactsViewModel.isAddParticipantsView.value) { -// Text( -// text = stringResource(id = R.string.nc_contacts_done), -// modifier = Modifier.clickable { -// for(contacts in contactsViewModel.selectedParticipantsList){ -// contacts.let { contact -> -// contactsViewModel.addParticipants( -// conversationToken, -// contact.id!!, -// contact.source!! -// ) -// } -// } -// } -// ) -// } -// } -// ) -// val state = addParticipantsUiState.value -// when(state){ -// is AddParticipantsUiState.Error -> { -// val errorMessage = state.message -// Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { -// Text(text = "Error: $errorMessage", color = Color.Red) -// } -// -// } -// is AddParticipantsUiState.None -> { -// -// -// } -// is AddParticipantsUiState.Success -> { -// val conversation = state.participants -// Log.d("ContactsActivityCompose", "$conversation") -// } -// } -// if (searchState.value) { -// Row { -// DisplaySearch( -// text = searchQuery, -// onTextChange = { searchQuery -> -// contactsViewModel.updateSearchQuery(query = searchQuery) -// contactsViewModel.getContactsFromSearchParams() -// }, -// contactsViewModel = contactsViewModel -// ) -// } -// } -// } diff --git a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepository.kt b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepository.kt index 889b89849a2..f419d326a98 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepository.kt @@ -14,4 +14,5 @@ interface ConversationCreationRepository { suspend fun renameConversation(roomToken: String, roomNameNew: String?): GenericOverall suspend fun setConversationDescription(roomToken: String, description: String?): GenericOverall suspend fun addParticipants(conversationToken: String?, userId: String, sourceType: String): AddParticipantOverall + fun getImageUri(avatarId: String, requestBigSize: Boolean): String } diff --git a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepositoryImpl.kt index bfac8a244f2..0f84331a45b 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepositoryImpl.kt @@ -73,4 +73,12 @@ class ConversationCreationRepositoryImpl( } return ncApiCoroutines.addParticipant(credentials, retrofitBucket.url, retrofitBucket.queryMap) } + + override fun getImageUri(avatarId: String, requestBigSize: Boolean): String { + return ApiUtils.getUrlForAvatar( + _currentUser.baseUrl, + avatarId, + requestBigSize + ) + } } diff --git a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt index 25b13daea33..e022f0dfcf0 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt @@ -12,6 +12,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.nextcloud.talk.contacts.AddParticipantsUiState +import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch @@ -20,6 +21,12 @@ import javax.inject.Inject class ConversationCreationViewModel @Inject constructor( private val repository: ConversationCreationRepository ) : ViewModel() { + private val _selectedParticipants = MutableStateFlow>(emptyList()) + val selectedParticipants: StateFlow> = _selectedParticipants + + fun updateSelectedParticipants(participants: List) { + _selectedParticipants.value = participants + } private val _roomName = MutableStateFlow("") val roomName: StateFlow = _roomName @@ -69,4 +76,8 @@ class ConversationCreationViewModel @Inject constructor( } } } + + fun getImageUri(avatarId: String, requestBigSize: Boolean): String { + return repository.getImageUri(avatarId, requestBigSize) + } }