From 5f6eda12c269716f18ce3fe60e6ad6dbe02ed4de Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 18 Sep 2024 17:57:54 +0200 Subject: [PATCH 1/5] Only display delete icon when user avatar is selected Signed-off-by: sowjanyakch --- .../ConversationCreationActivity.kt | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) 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 89acf6c85..e70a44b1a 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt @@ -209,7 +209,8 @@ fun ConversationCreationScreen( imagePickerLauncher = imagePickerLauncher, remoteFilePickerLauncher = remoteFilePickerLauncher, cameraLauncher = cameraLauncher, - onDeleteImage = { selectedImageUri = null } + onDeleteImage = { selectedImageUri = null }, + selectedImageUri = selectedImageUri ) ConversationNameAndDescription(conversationCreationViewModel) @@ -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) + ) + } } } } From c78fc9ab6e9ca163a9f4ae101ea97dd7ba19c5a2 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 18 Sep 2024 18:06:32 +0200 Subject: [PATCH 2/5] Make Conversation name text limit to single line Signed-off-by: sowjanyakch --- .../talk/conversationcreation/ConversationCreationActivity.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 e70a44b1a..9708f13be 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt @@ -327,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, From 54b5fd5045c2b632f1585e2d913524aa90f9d166 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 18 Sep 2024 18:34:52 +0200 Subject: [PATCH 3/5] Get selectedImageUri from ViewModel Signed-off-by: sowjanyakch --- .../ConversationCreationActivity.kt | 18 ++++++++---------- .../ConversationCreationViewModel.kt | 13 +++++++++---- 2 files changed, 17 insertions(+), 14 deletions(-) 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 9708f13be..518c2e61e 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.selectedImageUriState.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,18 +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) } } ) @@ -550,11 +550,11 @@ fun ConversationOptions( @Composable fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: ConversationCreationViewModel) { + var password by remember { mutableStateOf("") } AlertDialog( containerColor = colorResource(id = R.color.dialog_background), - onDismissRequest = onDismiss, confirmButton = { Button(onClick = { @@ -585,8 +585,7 @@ fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: Con @Composable fun CreateConversation( conversationCreationViewModel: ConversationCreationViewModel, - context: Context, - selectedImageUri: Uri? + context: Context ) { val selectedParticipants by conversationCreationViewModel.selectedParticipants.collectAsState() Box( @@ -600,8 +599,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 38586a6e3..99fa5ae67 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,10 @@ class ConversationCreationViewModel @Inject constructor( val selectedParticipants: StateFlow> = _selectedParticipants private val roomViewState = MutableStateFlow(RoomUIState.None) + private val selectedImageUri = MutableStateFlow(null) + val selectedImageUriState:StateFlow = selectedImageUri + + private val _currentUser = userManager.currentUser.blockingGet() val currentUser: User = _currentUser @@ -39,6 +43,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 +74,6 @@ class ConversationCreationViewModel @Inject constructor( roomType: String, conversationName: String, participants: Set, - selectedImageUri: Uri?, onRoomCreated: (String) -> Unit ) { val scope = when { @@ -109,9 +116,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 ?: "") From 6b32cb7e0b6e4939575a7cfb790577465f8a7f13 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Thu, 19 Sep 2024 14:57:12 +0200 Subject: [PATCH 4/5] ktlint format Signed-off-by: sowjanyakch --- .../java/com/nextcloud/talk/activities/CallActivity.kt | 4 +++- app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt | 2 +- .../conversationcreation/ConversationCreationActivity.kt | 8 ++------ .../conversationcreation/ConversationCreationViewModel.kt | 5 ++--- 4 files changed, 8 insertions(+), 11 deletions(-) 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 6376ce8fe..4302e2754 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 f71e16464..7d4a4d902 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 518c2e61e..2e5e83323 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt @@ -138,7 +138,7 @@ fun ConversationCreationScreen( context: Context, pickImage: PickImage ) { - val selectedImageUri = conversationCreationViewModel.selectedImageUriState.collectAsState().value + val selectedImageUri = conversationCreationViewModel.selectedImageUriState.collectAsState().value val imagePickerLauncher = rememberLauncherForActivityResult( contract = ActivityResultContracts.StartActivityForResult() @@ -550,7 +550,6 @@ fun ConversationOptions( @Composable fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: ConversationCreationViewModel) { - var password by remember { mutableStateOf("") } AlertDialog( @@ -583,10 +582,7 @@ fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: Con } @Composable -fun CreateConversation( - conversationCreationViewModel: ConversationCreationViewModel, - context: Context -) { +fun CreateConversation(conversationCreationViewModel: ConversationCreationViewModel, context: Context) { val selectedParticipants by conversationCreationViewModel.selectedParticipants.collectAsState() Box( modifier = Modifier 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 99fa5ae67..c30630ffb 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt @@ -33,8 +33,7 @@ class ConversationCreationViewModel @Inject constructor( private val roomViewState = MutableStateFlow(RoomUIState.None) private val selectedImageUri = MutableStateFlow(null) - val selectedImageUriState:StateFlow = selectedImageUri - + val selectedImageUriState: StateFlow = selectedImageUri private val _currentUser = userManager.currentUser.blockingGet() val currentUser: User = _currentUser @@ -43,7 +42,7 @@ class ConversationCreationViewModel @Inject constructor( _selectedParticipants.value = participants } - fun updateSelectedImageUri(uri:Uri?){ + fun updateSelectedImageUri(uri: Uri?) { selectedImageUri.value = uri } From 31966441f435a7c14de5c23ce2367de7a6d9a23d Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 20 Sep 2024 16:07:43 +0200 Subject: [PATCH 5/5] rename variable selectedImageUri Signed-off-by: sowjanyakch --- .../conversationcreation/ConversationCreationActivity.kt | 2 +- .../conversationcreation/ConversationCreationViewModel.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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 2e5e83323..74bf4d615 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt @@ -138,7 +138,7 @@ fun ConversationCreationScreen( context: Context, pickImage: PickImage ) { - val selectedImageUri = conversationCreationViewModel.selectedImageUriState.collectAsState().value + val selectedImageUri = conversationCreationViewModel.selectedImageUri.collectAsState().value val imagePickerLauncher = rememberLauncherForActivityResult( contract = ActivityResultContracts.StartActivityForResult() 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 c30630ffb..0fa663d88 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt @@ -32,8 +32,8 @@ class ConversationCreationViewModel @Inject constructor( val selectedParticipants: StateFlow> = _selectedParticipants private val roomViewState = MutableStateFlow(RoomUIState.None) - private val selectedImageUri = MutableStateFlow(null) - val selectedImageUriState: StateFlow = selectedImageUri + private val _selectedImageUri = MutableStateFlow(null) + val selectedImageUri: StateFlow = _selectedImageUri private val _currentUser = userManager.currentUser.blockingGet() val currentUser: User = _currentUser @@ -43,7 +43,7 @@ class ConversationCreationViewModel @Inject constructor( } fun updateSelectedImageUri(uri: Uri?) { - selectedImageUri.value = uri + _selectedImageUri.value = uri } private val _roomName = MutableStateFlow("")