mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
extract methods (avoid too long method "initObservers")
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
f34968c886
commit
a1c7e37fd9
@ -238,22 +238,70 @@ class ConversationInfoActivity :
|
|||||||
initObservers()
|
initObservers()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("Detekt.LongMethod")
|
|
||||||
private fun initObservers() {
|
private fun initObservers() {
|
||||||
initViewStateObserver()
|
initViewStateObserver()
|
||||||
|
initCapabilitiesObersver()
|
||||||
|
initRoomOberserver()
|
||||||
|
initBanActorObserver()
|
||||||
|
initConversationReadOnlyObserver()
|
||||||
|
initClearChatHistoryObserver()
|
||||||
|
}
|
||||||
|
|
||||||
viewModel.getCapabilitiesViewState.observe(this) { state ->
|
private fun initClearChatHistoryObserver() {
|
||||||
|
viewModel.clearChatHistoryViewState.observe(this) { uiState ->
|
||||||
|
when (uiState) {
|
||||||
|
is ConversationInfoViewModel.ClearChatHistoryViewState.None -> {
|
||||||
|
}
|
||||||
|
|
||||||
|
is ConversationInfoViewModel.ClearChatHistoryViewState.Success -> {
|
||||||
|
Snackbar.make(
|
||||||
|
binding.root,
|
||||||
|
context.getString(R.string.nc_clear_history_success),
|
||||||
|
Snackbar.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
is ConversationInfoViewModel.ClearChatHistoryViewState.Error -> {
|
||||||
|
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
|
||||||
|
Log.e(TAG, "failed to clear chat history", uiState.exception)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initConversationReadOnlyObserver() {
|
||||||
|
viewModel.getConversationReadOnlyState.observe(this) { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
is ConversationInfoViewModel.GetCapabilitiesSuccessState -> {
|
is ConversationInfoViewModel.SetConversationReadOnlyViewState.Success -> {
|
||||||
spreedCapabilities = state.spreedCapabilities
|
}
|
||||||
|
|
||||||
handleConversation()
|
is ConversationInfoViewModel.SetConversationReadOnlyViewState.Error -> {
|
||||||
|
Snackbar.make(binding.root, R.string.conversation_read_only_failed, Snackbar.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
is ConversationInfoViewModel.SetConversationReadOnlyViewState.None -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initBanActorObserver() {
|
||||||
|
viewModel.getBanActorState.observe(this) { state ->
|
||||||
|
when (state) {
|
||||||
|
is ConversationInfoViewModel.BanActorSuccessState -> {
|
||||||
|
getListOfParticipants() // Refresh the list of participants
|
||||||
|
}
|
||||||
|
|
||||||
|
ConversationInfoViewModel.BanActorErrorState -> {
|
||||||
|
Snackbar.make(binding.root, "Error banning actor", Snackbar.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initRoomOberserver() {
|
||||||
viewModel.createRoomViewState.observe(this) { state ->
|
viewModel.createRoomViewState.observe(this) { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
is ConversationInfoViewModel.CreateRoomUIState.Success -> {
|
is ConversationInfoViewModel.CreateRoomUIState.Success -> {
|
||||||
@ -272,54 +320,20 @@ class ConversationInfoActivity :
|
|||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.getBanActorState.observe(this) { state ->
|
|
||||||
when (state) {
|
|
||||||
is ConversationInfoViewModel.BanActorSuccessState -> {
|
|
||||||
getListOfParticipants() // Refresh the list of participants
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConversationInfoViewModel.BanActorErrorState -> {
|
private fun initCapabilitiesObersver() {
|
||||||
Snackbar.make(binding.root, "Error banning actor", Snackbar.LENGTH_SHORT).show()
|
viewModel.getCapabilitiesViewState.observe(this) { state ->
|
||||||
|
when (state) {
|
||||||
|
is ConversationInfoViewModel.GetCapabilitiesSuccessState -> {
|
||||||
|
spreedCapabilities = state.spreedCapabilities
|
||||||
|
|
||||||
|
handleConversation()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.getConversationReadOnlyState.observe(this) { state ->
|
|
||||||
when (state) {
|
|
||||||
is ConversationInfoViewModel.SetConversationReadOnlyViewState.Success -> {
|
|
||||||
}
|
|
||||||
|
|
||||||
is ConversationInfoViewModel.SetConversationReadOnlyViewState.Error -> {
|
|
||||||
Snackbar.make(binding.root, R.string.conversation_read_only_failed, Snackbar.LENGTH_LONG).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
is ConversationInfoViewModel.SetConversationReadOnlyViewState.None -> {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
viewModel.clearChatHistoryViewState.observe(this) { uiState ->
|
|
||||||
when (uiState) {
|
|
||||||
is ConversationInfoViewModel.ClearChatHistoryViewState.None -> {
|
|
||||||
}
|
|
||||||
|
|
||||||
is ConversationInfoViewModel.ClearChatHistoryViewState.Success -> {
|
|
||||||
Snackbar.make(
|
|
||||||
binding.root,
|
|
||||||
context.getString(R.string.nc_clear_history_success),
|
|
||||||
Snackbar.LENGTH_LONG
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
is ConversationInfoViewModel.ClearChatHistoryViewState.Error -> {
|
|
||||||
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
|
|
||||||
Log.e(TAG, "failed to clear chat history", uiState.exception)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initViewStateObserver() {
|
private fun initViewStateObserver() {
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* Nextcloud Talk - Android Client
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2025 Marcel Hibbe <dev@mhibbe.de>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
package com.nextcloud.talk.conversationinfo.viewmodel
|
package com.nextcloud.talk.conversationinfo.viewmodel
|
||||||
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
Loading…
Reference in New Issue
Block a user