Skip to content

Commit

Permalink
Work on warnings
Browse files Browse the repository at this point in the history
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
  • Loading branch information
sowjanyakch committed Sep 3, 2024
1 parent d5d4eef commit ea4a2dc
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(),

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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}")
}
}
Expand All @@ -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 ?: "")
}
}
}
Expand All @@ -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()
Expand Down

0 comments on commit ea4a2dc

Please sign in to comment.