diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.kt b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.kt index 6376ce8fe3..4302e27549 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.kt @@ -1633,7 +1633,9 @@ class CallActivity : CallBaseActivity() { private fun callOrJoinRoomViaWebSocket() { if (hasExternalSignalingServer) { webSocketClient!!.joinRoomWithRoomTokenAndSession( - roomToken!!, callSession, externalSignalingServer!!.federation + roomToken!!, + callSession, + externalSignalingServer!!.federation ) } else { performCall() diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index f71e164646..7d4a4d9027 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -3240,7 +3240,7 @@ class ChatActivity : val lon = data["longitude"]!! metaData = "{\"type\":\"geo-location\",\"id\":\"geo:$lat,$lon\",\"latitude\":\"$lat\"," + - "\"longitude\":\"$lon\",\"name\":\"$name\"}" + "\"longitude\":\"$lon\",\"name\":\"$name\"}" } when (type) { 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 89acf6c856..74bf4d6150 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt @@ -138,14 +138,14 @@ fun ConversationCreationScreen( context: Context, pickImage: PickImage ) { - var selectedImageUri by remember { mutableStateOf(null) } + val selectedImageUri = conversationCreationViewModel.selectedImageUri.collectAsState().value val imagePickerLauncher = rememberLauncherForActivityResult( contract = ActivityResultContracts.StartActivityForResult() ) { result -> if (result.resultCode == Activity.RESULT_OK) { pickImage.onImagePickerResult(result.data) { uri -> - selectedImageUri = uri + conversationCreationViewModel.updateSelectedImageUri(uri) } } } @@ -205,17 +205,18 @@ fun ConversationCreationScreen( DefaultUserAvatar(selectedImageUri) UploadAvatar( pickImage = pickImage, - onImageSelected = { uri -> selectedImageUri = uri }, + onImageSelected = { uri -> conversationCreationViewModel.updateSelectedImageUri(uri) }, imagePickerLauncher = imagePickerLauncher, remoteFilePickerLauncher = remoteFilePickerLauncher, cameraLauncher = cameraLauncher, - onDeleteImage = { selectedImageUri = null } + onDeleteImage = { conversationCreationViewModel.updateSelectedImageUri(null) }, + selectedImageUri = selectedImageUri ) ConversationNameAndDescription(conversationCreationViewModel) AddParticipants(launcher, context, conversationCreationViewModel) RoomCreationOptions(conversationCreationViewModel) - CreateConversation(conversationCreationViewModel, context, selectedImageUri) + CreateConversation(conversationCreationViewModel, context) } } ) @@ -258,7 +259,8 @@ fun UploadAvatar( imagePickerLauncher: ManagedActivityResultLauncher, remoteFilePickerLauncher: ManagedActivityResultLauncher, cameraLauncher: ManagedActivityResultLauncher, - onDeleteImage: () -> Unit + onDeleteImage: () -> Unit, + selectedImageUri: Uri? ) { Row( modifier = Modifier @@ -299,14 +301,16 @@ fun UploadAvatar( ) } - IconButton(onClick = { - onDeleteImage() - }) { - Icon( - painter = painterResource(id = R.drawable.ic_delete_grey600_24dp), - contentDescription = null, - modifier = Modifier.size(24.dp) - ) + if (selectedImageUri != null) { + IconButton(onClick = { + onDeleteImage() + }) { + Icon( + painter = painterResource(id = R.drawable.ic_delete_grey600_24dp), + contentDescription = null, + modifier = Modifier.size(24.dp) + ) + } } } } @@ -323,7 +327,8 @@ fun ConversationNameAndDescription(conversationCreationViewModel: ConversationCr label = { Text(text = stringResource(id = R.string.nc_call_name)) }, modifier = Modifier .padding(start = 16.dp, end = 16.dp) - .fillMaxWidth() + .fillMaxWidth(), + singleLine = true ) OutlinedTextField( value = conversationDescription.value, @@ -549,7 +554,6 @@ fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: Con AlertDialog( containerColor = colorResource(id = R.color.dialog_background), - onDismissRequest = onDismiss, confirmButton = { Button(onClick = { @@ -578,11 +582,7 @@ fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: Con } @Composable -fun CreateConversation( - conversationCreationViewModel: ConversationCreationViewModel, - context: Context, - selectedImageUri: Uri? -) { +fun CreateConversation(conversationCreationViewModel: ConversationCreationViewModel, context: Context) { val selectedParticipants by conversationCreationViewModel.selectedParticipants.collectAsState() Box( modifier = Modifier @@ -595,8 +595,7 @@ fun CreateConversation( conversationCreationViewModel.createRoomAndAddParticipants( roomType = CompanionClass.ROOM_TYPE_GROUP, conversationName = conversationCreationViewModel.roomName.value, - participants = selectedParticipants.toSet(), - selectedImageUri = selectedImageUri + participants = selectedParticipants.toSet() ) { roomToken -> val bundle = Bundle() bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken) 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 38586a6e38..0fa663d889 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt @@ -32,6 +32,9 @@ class ConversationCreationViewModel @Inject constructor( val selectedParticipants: StateFlow> = _selectedParticipants private val roomViewState = MutableStateFlow(RoomUIState.None) + private val _selectedImageUri = MutableStateFlow(null) + val selectedImageUri: StateFlow = _selectedImageUri + private val _currentUser = userManager.currentUser.blockingGet() val currentUser: User = _currentUser @@ -39,6 +42,10 @@ class ConversationCreationViewModel @Inject constructor( _selectedParticipants.value = participants } + fun updateSelectedImageUri(uri: Uri?) { + _selectedImageUri.value = uri + } + private val _roomName = MutableStateFlow("") val roomName: StateFlow = _roomName private val _password = MutableStateFlow("") @@ -66,7 +73,6 @@ class ConversationCreationViewModel @Inject constructor( roomType: String, conversationName: String, participants: Set, - selectedImageUri: Uri?, onRoomCreated: (String) -> Unit ) { val scope = when { @@ -109,9 +115,7 @@ class ConversationCreationViewModel @Inject constructor( repository.setPassword(token, _password.value) } repository.openConversation(token, scope) - if (selectedImageUri != null) { - repository.uploadConversationAvatar(selectedImageUri.toFile(), token) - } + selectedImageUri.value?.let { repository.uploadConversationAvatar(it.toFile(), token) } onRoomCreated(token) } catch (exception: Exception) { allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "")