mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 11:39:42 +01:00
refactoring
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
3de36ebec3
commit
013195465c
@ -76,10 +76,10 @@ class GuestAccessHelper(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
is ConversationInfoViewModel.AllowGuestsUIState.Error -> {
|
is ConversationInfoViewModel.AllowGuestsUIState.Error -> {
|
||||||
val exception = uiState.message
|
val exception = uiState.exception
|
||||||
val message = context.getString(R.string.nc_guest_access_allow_failed)
|
val message = context.getString(R.string.nc_guest_access_allow_failed)
|
||||||
Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show()
|
Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show()
|
||||||
Log.e(TAG, exception)
|
Log.e(TAG, message, exception)
|
||||||
}
|
}
|
||||||
ConversationInfoViewModel.AllowGuestsUIState.None -> {
|
ConversationInfoViewModel.AllowGuestsUIState.None -> {
|
||||||
}
|
}
|
||||||
@ -111,10 +111,10 @@ class GuestAccessHelper(
|
|||||||
// unused atm
|
// unused atm
|
||||||
}
|
}
|
||||||
is ConversationInfoViewModel.PasswordUiState.Error -> {
|
is ConversationInfoViewModel.PasswordUiState.Error -> {
|
||||||
val exception = uiState.message
|
val exception = uiState.exception
|
||||||
val message = context.getString(R.string.nc_guest_access_password_failed)
|
val message = context.getString(R.string.nc_guest_access_password_failed)
|
||||||
Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show()
|
Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show()
|
||||||
Log.e(TAG, exception)
|
Log.e(TAG, message, exception)
|
||||||
}
|
}
|
||||||
is ConversationInfoViewModel.PasswordUiState.None -> {
|
is ConversationInfoViewModel.PasswordUiState.None -> {
|
||||||
// unused atm
|
// unused atm
|
||||||
|
@ -18,11 +18,9 @@ import com.nextcloud.talk.chat.data.network.ChatNetworkDataSource
|
|||||||
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.domain.ConversationModel
|
||||||
import com.nextcloud.talk.models.json.capabilities.SpreedCapability
|
import com.nextcloud.talk.models.json.capabilities.SpreedCapability
|
||||||
import com.nextcloud.talk.models.json.generic.GenericMeta
|
|
||||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||||
import com.nextcloud.talk.models.json.participants.TalkBan
|
import com.nextcloud.talk.models.json.participants.TalkBan
|
||||||
import com.nextcloud.talk.repositories.conversations.ConversationsRepository
|
import com.nextcloud.talk.repositories.conversations.ConversationsRepository
|
||||||
import com.nextcloud.talk.repositories.conversations.ConversationsRepositoryImpl.Companion.STATUS_CODE_OK
|
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
import io.reactivex.Observer
|
import io.reactivex.Observer
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
@ -249,14 +247,10 @@ class ConversationInfoViewModel @Inject constructor(
|
|||||||
fun allowGuests(token: String, allow: Boolean) {
|
fun allowGuests(token: String, allow: Boolean) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
val allowGuestsResult = conversationsRepository.allowGuests(token, allow)
|
conversationsRepository.allowGuests(token, allow)
|
||||||
val statusCode: GenericMeta? = allowGuestsResult.ocs?.meta
|
|
||||||
val result = statusCode?.statusCode == STATUS_CODE_OK
|
|
||||||
if (result) {
|
|
||||||
_allowGuestsViewState.value = AllowGuestsUIState.Success(allow)
|
_allowGuestsViewState.value = AllowGuestsUIState.Success(allow)
|
||||||
}
|
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
_allowGuestsViewState.value = AllowGuestsUIState.Error(exception.message ?: "")
|
_allowGuestsViewState.value = AllowGuestsUIState.Error(exception)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,14 +259,10 @@ class ConversationInfoViewModel @Inject constructor(
|
|||||||
fun setPassword(password: String, token: String) {
|
fun setPassword(password: String, token: String) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
val setPasswordResult = conversationsRepository.setPassword(password, token)
|
conversationsRepository.setPassword(password, token)
|
||||||
val statusCode: GenericMeta? = setPasswordResult.ocs?.meta
|
_passwordViewState.value = PasswordUiState.Success
|
||||||
val result = statusCode?.statusCode == STATUS_CODE_OK
|
|
||||||
if (result) {
|
|
||||||
_passwordViewState.value = PasswordUiState.Success(result)
|
|
||||||
}
|
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
_passwordViewState.value = PasswordUiState.Error(exception.message ?: "")
|
_passwordViewState.value = PasswordUiState.Error(exception)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -315,12 +305,12 @@ class ConversationInfoViewModel @Inject constructor(
|
|||||||
sealed class AllowGuestsUIState {
|
sealed class AllowGuestsUIState {
|
||||||
data object None : AllowGuestsUIState()
|
data object None : AllowGuestsUIState()
|
||||||
data class Success(val allow: Boolean) : AllowGuestsUIState()
|
data class Success(val allow: Boolean) : AllowGuestsUIState()
|
||||||
data class Error(val message: String) : AllowGuestsUIState()
|
data class Error(val exception: Exception) : AllowGuestsUIState()
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class PasswordUiState {
|
sealed class PasswordUiState {
|
||||||
data object None : PasswordUiState()
|
data object None : PasswordUiState()
|
||||||
data class Success(val result: Boolean) : PasswordUiState()
|
data object Success : PasswordUiState()
|
||||||
data class Error(val message: String) : PasswordUiState()
|
data class Error(val exception: Exception) : PasswordUiState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user