mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-29 09:58:54 +03:00
Merge pull request #4250 from nextcloud/conversation_creation_modification
Conversation creation modification
This commit is contained in:
commit
3b09da75a7
4 changed files with 34 additions and 29 deletions
|
@ -1633,7 +1633,9 @@ class CallActivity : CallBaseActivity() {
|
|||
private fun callOrJoinRoomViaWebSocket() {
|
||||
if (hasExternalSignalingServer) {
|
||||
webSocketClient!!.joinRoomWithRoomTokenAndSession(
|
||||
roomToken!!, callSession, externalSignalingServer!!.federation
|
||||
roomToken!!,
|
||||
callSession,
|
||||
externalSignalingServer!!.federation
|
||||
)
|
||||
} else {
|
||||
performCall()
|
||||
|
|
|
@ -138,14 +138,14 @@ fun ConversationCreationScreen(
|
|||
context: Context,
|
||||
pickImage: PickImage
|
||||
) {
|
||||
var selectedImageUri by remember { mutableStateOf<Uri?>(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<Intent, ActivityResult>,
|
||||
remoteFilePickerLauncher: ManagedActivityResultLauncher<Intent, ActivityResult>,
|
||||
cameraLauncher: ManagedActivityResultLauncher<Intent, ActivityResult>,
|
||||
onDeleteImage: () -> Unit
|
||||
onDeleteImage: () -> Unit,
|
||||
selectedImageUri: Uri?
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
|
@ -299,6 +301,7 @@ fun UploadAvatar(
|
|||
)
|
||||
}
|
||||
|
||||
if (selectedImageUri != null) {
|
||||
IconButton(onClick = {
|
||||
onDeleteImage()
|
||||
}) {
|
||||
|
@ -310,6 +313,7 @@ fun UploadAvatar(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ConversationNameAndDescription(conversationCreationViewModel: ConversationCreationViewModel) {
|
||||
|
@ -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)
|
||||
|
|
|
@ -32,6 +32,9 @@ class ConversationCreationViewModel @Inject constructor(
|
|||
val selectedParticipants: StateFlow<List<AutocompleteUser>> = _selectedParticipants
|
||||
private val roomViewState = MutableStateFlow<RoomUIState>(RoomUIState.None)
|
||||
|
||||
private val _selectedImageUri = MutableStateFlow<Uri?>(null)
|
||||
val selectedImageUri: StateFlow<Uri?> = _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<String> = _roomName
|
||||
private val _password = MutableStateFlow("")
|
||||
|
@ -66,7 +73,6 @@ class ConversationCreationViewModel @Inject constructor(
|
|||
roomType: String,
|
||||
conversationName: String,
|
||||
participants: Set<AutocompleteUser>,
|
||||
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 ?: "")
|
||||
|
|
Loading…
Reference in a new issue