Bläddra i källkod

Work on warnings

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
sowjanyakch 6 månader sedan
förälder
incheckning
52378327f9

+ 9 - 3
app/src/main/java/com/nextcloud/talk/contacts/ContactsActivityCompose.kt

@@ -106,7 +106,8 @@ class ContactsActivityCompose : BaseActivity() {
             val uiState = contactsViewModel.contactsViewState.collectAsState()
             val selectedParticipants = remember {
                 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
-                    intent.getParcelableArrayListExtra("selectedParticipants", AutocompleteUser::class.java) ?: emptyList()
+                    intent.getParcelableArrayListExtra("selectedParticipants", AutocompleteUser::class.java)
+                        ?: emptyList()
                 } else {
                     @Suppress("DEPRECATION")
                     intent.getParcelableArrayListExtra("selectedParticipants") ?: emptyList()
@@ -224,7 +225,10 @@ fun ContactItemRow(
 @SuppressLint("UnrememberedMutableState")
 @OptIn(ExperimentalMaterial3Api::class)
 @Composable
-fun AppBar(title: String, context: Context, contactsViewModel: ContactsViewModel) {
+fun AppBar(
+    title: String,
+    context: Context,
+    contactsViewModel: ContactsViewModel) {
     val searchQuery by contactsViewModel.searchQuery.collectAsState()
     val searchState = contactsViewModel.searchState.collectAsState()
     val isAddParticipants = contactsViewModel.isAddParticipantsView.collectAsState()
@@ -279,7 +283,9 @@ fun AppBar(title: String, context: Context, contactsViewModel: ContactsViewModel
 }
 
 @Composable
-fun ConversationCreationOptions(context: Context, contactsViewModel: ContactsViewModel) {
+fun ConversationCreationOptions(
+    context: Context,
+    contactsViewModel: ContactsViewModel) {
     val isAddParticipants by contactsViewModel.isAddParticipantsView.collectAsState()
     if (!isAddParticipants) {
         Column {

+ 3 - 9
app/src/main/java/com/nextcloud/talk/contacts/ContactsViewModel.kt

@@ -30,8 +30,8 @@ class ContactsViewModel @Inject constructor(
     val shareTypeList: List<String> = shareTypes
     private val _searchState = MutableStateFlow(false)
     val searchState: StateFlow<Boolean> = _searchState
-    private val _selectedParticipants = MutableStateFlow<List<AutocompleteUser>>(emptyList())
-    val selectedParticipantsList: StateFlow<List<AutocompleteUser>> = _selectedParticipants
+    private val selectedParticipants = MutableStateFlow<List<AutocompleteUser>>(emptyList())
+    val selectedParticipantsList: StateFlow<List<AutocompleteUser>> = selectedParticipants
     private val _isAddParticipantsView = MutableStateFlow(false)
     val isAddParticipantsView: StateFlow<Boolean> = _isAddParticipantsView
 
@@ -44,7 +44,7 @@ class ContactsViewModel @Inject constructor(
     }
 
     fun updateSelectedParticipants(participants: List<AutocompleteUser>) {
-        _selectedParticipants.value = participants
+        selectedParticipants.value = participants
     }
     fun updateSearchState(searchState: Boolean) {
         _searchState.value = searchState
@@ -107,9 +107,3 @@ sealed class RoomUiState {
     data class Success(val conversation: Conversation?) : RoomUiState()
     data class Error(val message: String) : RoomUiState()
 }
-
-sealed class AddParticipantsUiState() {
-    data object None : AddParticipantsUiState()
-    data class Success(val participants: List<Conversation>?) : AddParticipantsUiState()
-    data class Error(val message: String) : AddParticipantsUiState()
-}

+ 18 - 7
app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt

@@ -102,8 +102,9 @@ class ConversationCreationActivity : BaseActivity() {
 
 @OptIn(ExperimentalMaterial3Api::class)
 @Composable
-fun ConversationCreationScreen(conversationCreationViewModel: ConversationCreationViewModel, context: Context) {
-    val context = LocalContext.current
+fun ConversationCreationScreen(
+    conversationCreationViewModel: ConversationCreationViewModel,
+    context: Context) {
     val launcher = rememberLauncherForActivityResult(
         contract = ActivityResultContracts.StartActivityForResult(),
 
@@ -159,7 +160,7 @@ fun DefaultUserAvatar() {
     ) {
         AsyncImage(
             model = R.drawable.ic_circular_group,
-            contentDescription = "User Avatar",
+            contentDescription = stringResource(id = R.string.user_avatar),
             modifier = Modifier
                 .size(width = 84.dp, height = 84.dp)
                 .padding(top = 8.dp)
@@ -214,7 +215,9 @@ fun UploadAvatar() {
 }
 
 @Composable
-fun ConversationNameAndDescription(conversationCreationViewModel: ConversationCreationViewModel) {
+fun ConversationNameAndDescription(
+    conversationCreationViewModel: ConversationCreationViewModel
+) {
     val conversationRoomName = conversationCreationViewModel.roomName.collectAsState()
     val conversationDescription = conversationCreationViewModel.conversationDescription.collectAsState()
     OutlinedTextField(
@@ -327,7 +330,9 @@ fun AddParticipants(
 }
 
 @Composable
-fun RoomCreationOptions(conversationCreationViewModel: ConversationCreationViewModel) {
+fun RoomCreationOptions(
+    conversationCreationViewModel: ConversationCreationViewModel
+) {
     val isGuestsAllowed = conversationCreationViewModel.isGuestsAllowed.value
     val isConversationAvailableForRegisteredUsers = conversationCreationViewModel
         .isConversationAvailableForRegisteredUsers.value
@@ -446,7 +451,10 @@ fun ConversationOptions(
 }
 
 @Composable
-fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: ConversationCreationViewModel) {
+fun ShowPasswordDialog(
+    onDismiss: () -> Unit,
+    conversationCreationViewModel: ConversationCreationViewModel
+) {
     var password by remember { mutableStateOf("") }
 
     AlertDialog(
@@ -478,7 +486,10 @@ 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

+ 15 - 61
app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt

@@ -25,8 +25,7 @@ class ConversationCreationViewModel @Inject constructor(
 ) : ViewModel() {
     private val _selectedParticipants = MutableStateFlow<List<AutocompleteUser>>(emptyList())
     val selectedParticipants: StateFlow<List<AutocompleteUser>> = _selectedParticipants
-    private val _roomViewState = MutableStateFlow<RoomUIState>(RoomUIState.None)
-    val roomViewState: StateFlow<RoomUIState> = _roomViewState
+    private val roomViewState = MutableStateFlow<RoomUIState>(RoomUIState.None)
 
     fun updateSelectedParticipants(participants: List<AutocompleteUser>) {
         _selectedParticipants.value = participants
@@ -42,7 +41,7 @@ class ConversationCreationViewModel @Inject constructor(
     var isConversationAvailableForRegisteredUsers = mutableStateOf(false)
     var openForGuestAppUsers = mutableStateOf(false)
     private val addParticipantsViewState = MutableStateFlow<AddParticipantsUiState>(AddParticipantsUiState.None)
-    private val _allowGuestsResult = MutableStateFlow<AllowGuestsUiState>(AllowGuestsUiState.None)
+    private val allowGuestsResult = MutableStateFlow<AllowGuestsUiState>(AllowGuestsUiState.None)
     fun updateRoomName(roomName: String) {
         _roomName.value = roomName
     }
@@ -55,51 +54,6 @@ class ConversationCreationViewModel @Inject constructor(
         _conversationDescription.value = conversationDescription
     }
 
-    fun renameConversation(roomToken: String) {
-        viewModelScope.launch {
-            try {
-                repository.renameConversation(roomToken, roomName.value)
-            } catch (e: Exception) {
-                Log.d("ConversationCreationViewModel", "${e.message}")
-            }
-        }
-    }
-
-    fun setConversationDescription(roomToken: String) {
-        viewModelScope.launch {
-            try {
-                repository.setConversationDescription(roomToken, conversationDescription.value)
-            } catch (e: Exception) {
-                Log.d("ConversationCreationViewModel", "${e.message}")
-            }
-        }
-    }
-
-    fun addParticipants(conversationToken: String?, userId: String, sourceType: String) {
-        viewModelScope.launch {
-            try {
-                val participantsOverall = repository.addParticipants(conversationToken, userId, sourceType)
-                val participants: List<Conversation>? = participantsOverall.ocs?.data
-                addParticipantsViewState.value = AddParticipantsUiState.Success(participants)
-            } catch (exception: Exception) {
-                addParticipantsViewState.value = AddParticipantsUiState.Error(exception.message ?: "")
-            }
-        }
-    }
-
-    fun allowGuests(token: String, allow: Boolean) {
-        viewModelScope.launch {
-            try {
-                val response = repository.allowGuests(token, allow)
-                val statusCode: Int = response.ocs?.meta?.statusCode!!
-                val result = (statusCode == STATUS_CODE_OK)
-                _allowGuestsResult.value = AllowGuestsUiState.Success(result)
-            } catch (exception: Exception) {
-                _allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "")
-            }
-        }
-    }
-
     fun createRoomAndAddParticipants(
         roomType: String,
         conversationName: String,
@@ -112,7 +66,7 @@ class ConversationCreationViewModel @Inject constructor(
             else -> 0
         }
         viewModelScope.launch {
-            _roomViewState.value = RoomUIState.None
+            roomViewState.value = RoomUIState.None
             try {
                 val roomResult = repository.createRoom(roomType, conversationName)
                 val conversation = roomResult.ocs?.data
@@ -121,15 +75,15 @@ class ConversationCreationViewModel @Inject constructor(
                     val token = conversation.token
                     if (token != null) {
                         try {
-                            val conversationDescription = repository.setConversationDescription(
+                            repository.setConversationDescription(
                                 token,
                                 _conversationDescription.value
                             )
-                            val allowGuestsResult = repository.allowGuests(token, isGuestsAllowed.value)
-                            val statusCode: GenericMeta? = allowGuestsResult.ocs?.meta
+                            val allowGuestResultOverall = repository.allowGuests(token, isGuestsAllowed.value)
+                            val statusCode: GenericMeta? = allowGuestResultOverall.ocs?.meta
                             val result = (statusCode?.statusCode == STATUS_CODE_OK)
                             if (result) {
-                                _allowGuestsResult.value = AllowGuestsUiState.Success(result)
+                                allowGuestsResult.value = AllowGuestsUiState.Success(result)
                                 for (participant in participants) {
                                     if (participant.id != null) {
                                         val participantOverall = repository.addParticipants(
@@ -142,19 +96,19 @@ class ConversationCreationViewModel @Inject constructor(
                                     }
                                 }
                             }
-                            val passwordResult = repository.setPassword(token, _password.value)
+                            repository.setPassword(token, _password.value)
                             repository.openConversation(token, scope)
                             onRoomCreated(token)
                         } catch (exception: Exception) {
-                            _allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "")
+                            allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "")
                         }
                     }
-                    _roomViewState.value = RoomUIState.Success(conversation)
+                    roomViewState.value = RoomUIState.Success(conversation)
                 } else {
-                    _roomViewState.value = RoomUIState.Error("Conversation is null")
+                    roomViewState.value = RoomUIState.Error("Conversation is null")
                 }
             } catch (e: Exception) {
-                _roomViewState.value = RoomUIState.Error(e.message ?: "Unknown error")
+                roomViewState.value = RoomUIState.Error(e.message ?: "Unknown error")
                 Log.e("ConversationCreationViewModel", "Error - ${e.message}")
             }
         }
@@ -173,9 +127,9 @@ class ConversationCreationViewModel @Inject constructor(
                 )
 
                 val conversation: Conversation? = room.ocs?.data
-                _roomViewState.value = RoomUIState.Success(conversation)
+                roomViewState.value = RoomUIState.Success(conversation)
             } catch (exception: Exception) {
-                _roomViewState.value = RoomUIState.Error(exception.message ?: "")
+                roomViewState.value = RoomUIState.Error(exception.message ?: "")
             }
         }
     }
@@ -192,7 +146,7 @@ sealed class RoomUIState {
     data class Error(val message: String) : RoomUIState()
 }
 
-sealed class AddParticipantsUiState() {
+sealed class AddParticipantsUiState {
     data object None : AddParticipantsUiState()
     data class Success(val participants: List<Conversation>?) : AddParticipantsUiState()
     data class Error(val message: String) : AddParticipantsUiState()