mirror of
https://github.com/nextcloud/talk-android
synced 2025-02-08 15:42:58 +00:00
upload conversation avatar
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
fa014aab3a
commit
f8bc4f2e96
@ -105,7 +105,7 @@ interface NcApiCoroutines {
|
|||||||
suspend fun uploadConversationAvatar(
|
suspend fun uploadConversationAvatar(
|
||||||
@Header("Authorization") authorization: String,
|
@Header("Authorization") authorization: String,
|
||||||
@Url url: String,
|
@Url url: String,
|
||||||
@Part("attachment") attachment: MultipartBody.Part
|
@Part attachment: MultipartBody.Part
|
||||||
): RoomOverall
|
): RoomOverall
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
|
@ -212,7 +212,7 @@ fun ConversationCreationScreen(
|
|||||||
ConversationNameAndDescription(conversationCreationViewModel)
|
ConversationNameAndDescription(conversationCreationViewModel)
|
||||||
AddParticipants(launcher, context, conversationCreationViewModel)
|
AddParticipants(launcher, context, conversationCreationViewModel)
|
||||||
RoomCreationOptions(conversationCreationViewModel)
|
RoomCreationOptions(conversationCreationViewModel)
|
||||||
CreateConversation(conversationCreationViewModel, context)
|
CreateConversation(conversationCreationViewModel, context,selectedImageUri)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -275,7 +275,7 @@ fun UploadAvatar(
|
|||||||
pickImage.selectLocal(imagePickerLauncher)
|
pickImage.selectLocal(imagePickerLauncher)
|
||||||
}) {
|
}) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.ic_folder_multiple_image),
|
painter = painterResource(id = R.drawable.upload),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(24.dp)
|
modifier = Modifier.size(24.dp)
|
||||||
)
|
)
|
||||||
@ -286,7 +286,7 @@ fun UploadAvatar(
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.baseline_tag_faces_24),
|
painter = painterResource(id = R.drawable.ic_mimetype_folder),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(24.dp)
|
modifier = Modifier.size(24.dp)
|
||||||
)
|
)
|
||||||
@ -571,7 +571,7 @@ fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: Con
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CreateConversation(conversationCreationViewModel: ConversationCreationViewModel, context: Context) {
|
fun CreateConversation(conversationCreationViewModel: ConversationCreationViewModel, context: Context,selectedImageUri: Uri?) {
|
||||||
val selectedParticipants by conversationCreationViewModel.selectedParticipants.collectAsState()
|
val selectedParticipants by conversationCreationViewModel.selectedParticipants.collectAsState()
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -584,7 +584,8 @@ fun CreateConversation(conversationCreationViewModel: ConversationCreationViewMo
|
|||||||
conversationCreationViewModel.createRoomAndAddParticipants(
|
conversationCreationViewModel.createRoomAndAddParticipants(
|
||||||
roomType = CompanionClass.ROOM_TYPE_GROUP,
|
roomType = CompanionClass.ROOM_TYPE_GROUP,
|
||||||
conversationName = conversationCreationViewModel.roomName.value,
|
conversationName = conversationCreationViewModel.roomName.value,
|
||||||
participants = selectedParticipants.toSet()
|
participants = selectedParticipants.toSet(),
|
||||||
|
selectedImageUri = selectedImageUri
|
||||||
) { roomToken ->
|
) { roomToken ->
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken)
|
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken)
|
||||||
|
@ -7,12 +7,13 @@
|
|||||||
|
|
||||||
package com.nextcloud.talk.conversationcreation
|
package com.nextcloud.talk.conversationcreation
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.core.net.toFile
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.nextcloud.talk.data.user.model.User
|
import com.nextcloud.talk.data.user.model.User
|
||||||
import com.nextcloud.talk.models.domain.ConversationModel
|
|
||||||
import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser
|
import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser
|
||||||
import com.nextcloud.talk.models.json.conversations.Conversation
|
import com.nextcloud.talk.models.json.conversations.Conversation
|
||||||
import com.nextcloud.talk.models.json.generic.GenericMeta
|
import com.nextcloud.talk.models.json.generic.GenericMeta
|
||||||
@ -21,7 +22,6 @@ import com.nextcloud.talk.users.UserManager
|
|||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.io.File
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ConversationCreationViewModel @Inject constructor(
|
class ConversationCreationViewModel @Inject constructor(
|
||||||
@ -32,12 +32,6 @@ class ConversationCreationViewModel @Inject constructor(
|
|||||||
val selectedParticipants: StateFlow<List<AutocompleteUser>> = _selectedParticipants
|
val selectedParticipants: StateFlow<List<AutocompleteUser>> = _selectedParticipants
|
||||||
private val roomViewState = MutableStateFlow<RoomUIState>(RoomUIState.None)
|
private val roomViewState = MutableStateFlow<RoomUIState>(RoomUIState.None)
|
||||||
|
|
||||||
private val _uploadState = MutableStateFlow<UploadAvatarState>(UploadAvatarState.Loading)
|
|
||||||
val uploadState: StateFlow<UploadAvatarState> = _uploadState
|
|
||||||
|
|
||||||
private val _deleteState = MutableStateFlow<DeleteAvatarState>(DeleteAvatarState.Loading)
|
|
||||||
val deleteState: StateFlow<DeleteAvatarState> = _deleteState
|
|
||||||
|
|
||||||
private val _currentUser = userManager.currentUser.blockingGet()
|
private val _currentUser = userManager.currentUser.blockingGet()
|
||||||
val currentUser: User = _currentUser
|
val currentUser: User = _currentUser
|
||||||
|
|
||||||
@ -72,6 +66,7 @@ class ConversationCreationViewModel @Inject constructor(
|
|||||||
roomType: String,
|
roomType: String,
|
||||||
conversationName: String,
|
conversationName: String,
|
||||||
participants: Set<AutocompleteUser>,
|
participants: Set<AutocompleteUser>,
|
||||||
|
selectedImageUri: Uri?,
|
||||||
onRoomCreated: (String) -> Unit
|
onRoomCreated: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
val scope = when {
|
val scope = when {
|
||||||
@ -114,6 +109,9 @@ class ConversationCreationViewModel @Inject constructor(
|
|||||||
repository.setPassword(token, _password.value)
|
repository.setPassword(token, _password.value)
|
||||||
}
|
}
|
||||||
repository.openConversation(token, scope)
|
repository.openConversation(token, scope)
|
||||||
|
if(selectedImageUri!= null){
|
||||||
|
repository.uploadConversationAvatar(selectedImageUri.toFile(), token)
|
||||||
|
}
|
||||||
onRoomCreated(token)
|
onRoomCreated(token)
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "")
|
allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "")
|
||||||
@ -130,28 +128,6 @@ class ConversationCreationViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uploadConversationAvatar(file: File, roomToken: String) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
try {
|
|
||||||
val response = repository.uploadConversationAvatar(file, roomToken)
|
|
||||||
_uploadState.value = UploadAvatarState.Success(response)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
_uploadState.value = UploadAvatarState.Error(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deleteConversationAvatar(roomToken: String) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
try {
|
|
||||||
val result = repository.deleteConversationAvatar(roomToken)
|
|
||||||
_deleteState.value = DeleteAvatarState.Success(result)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
_deleteState.value = DeleteAvatarState.Error(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getImageUri(avatarId: String, requestBigSize: Boolean): String {
|
fun getImageUri(avatarId: String, requestBigSize: Boolean): String {
|
||||||
return repository.getImageUri(avatarId, requestBigSize)
|
return repository.getImageUri(avatarId, requestBigSize)
|
||||||
}
|
}
|
||||||
@ -191,14 +167,3 @@ sealed class AddParticipantsUiState {
|
|||||||
data class Error(val message: String) : AddParticipantsUiState()
|
data class Error(val message: String) : AddParticipantsUiState()
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class UploadAvatarState {
|
|
||||||
object Loading : UploadAvatarState()
|
|
||||||
data class Success(val roomOverall: ConversationModel) : UploadAvatarState()
|
|
||||||
data class Error(val exception: Exception) : UploadAvatarState()
|
|
||||||
}
|
|
||||||
|
|
||||||
sealed class DeleteAvatarState {
|
|
||||||
object Loading : DeleteAvatarState()
|
|
||||||
data class Success(val roomOverall: ConversationModel) : DeleteAvatarState()
|
|
||||||
data class Error(val exception: Exception) : DeleteAvatarState()
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user