From d6bb6efb1d23dd056b110eff962f5c2a29b1b2af Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Fri, 23 Sep 2022 16:35:28 +0200 Subject: [PATCH] Loading dialog during signout process --- .../v2/overview/SessionOverviewFragment.kt | 9 +++++++ .../v2/overview/SessionOverviewViewModel.kt | 25 ++++++++++++------- .../v2/overview/SessionOverviewViewState.kt | 1 + 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt index 3bcd65111f..eed7c1fead 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt @@ -139,6 +139,7 @@ class SessionOverviewFragment : updateToolbar(state.isCurrentSession) updateEntryDetails(state.deviceId) updateSessionInfo(state) + updateLoading(state.isLoading) } private fun updateToolbar(isCurrentSession: Boolean) { @@ -172,6 +173,14 @@ class SessionOverviewFragment : } } + private fun updateLoading(isLoading: Boolean) { + if (isLoading) { + showLoading(null) + } else { + dismissLoadingDialog() + } + } + private val reAuthActivityResultLauncher = registerStartForActivityResult { activityResult -> if (activityResult.resultCode == Activity.RESULT_OK) { when (activityResult.data?.extras?.getString(ReAuthActivity.RESULT_FLOW_TYPE)) { diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt index 7e08e1ccf5..9a6043e194 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt @@ -139,16 +139,10 @@ class SessionOverviewViewModel @AssistedInject constructor( // TODO add unit tests private fun handleSignoutSession() = withState { state -> // TODO for current session: do the same process as sign out button in the general settings - // TODO add a loading viewState or ViewEvent viewModelScope.launch { - val signoutResult = signoutSessionUseCase.execute(state.deviceId, object : UserInteractiveAuthInterceptor { - override fun performStage(flowResponse: RegistrationFlowResponse, errCode: String?, promise: Continuation) { - when (val result = interceptSignoutFlowResponseUseCase.execute(flowResponse, errCode, promise)) { - is SignoutSessionResult.ReAuthNeeded -> onReAuthNeeded(result) - is SignoutSessionResult.Completed -> Unit - } - } - }) + setLoading(true) + val signoutResult = signout(state.deviceId) + setLoading(false) if (signoutResult.isSuccess) { onSignoutSuccess() @@ -161,6 +155,15 @@ class SessionOverviewViewModel @AssistedInject constructor( } } + private suspend fun signout(deviceId: String) = signoutSessionUseCase.execute(deviceId, object : UserInteractiveAuthInterceptor { + override fun performStage(flowResponse: RegistrationFlowResponse, errCode: String?, promise: Continuation) { + when (val result = interceptSignoutFlowResponseUseCase.execute(flowResponse, errCode, promise)) { + is SignoutSessionResult.ReAuthNeeded -> onReAuthNeeded(result) + is SignoutSessionResult.Completed -> Unit + } + } + }) + private fun onReAuthNeeded(reAuthNeeded: SignoutSessionResult.ReAuthNeeded) { Timber.d("onReAuthNeeded") pendingAuthHandler.pendingAuth = DefaultBaseAuth(session = reAuthNeeded.flowResponse.session) @@ -168,6 +171,10 @@ class SessionOverviewViewModel @AssistedInject constructor( _viewEvents.post(SessionOverviewViewEvent.RequestReAuth(reAuthNeeded.flowResponse, reAuthNeeded.errCode)) } + private fun setLoading(isLoading: Boolean) { + setState { copy(isLoading = isLoading) } + } + private fun onSignoutSuccess() { Timber.d("signout success") refreshDeviceList() diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewState.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewState.kt index 1cb455dd5c..8a0b41c55d 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewState.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewState.kt @@ -26,6 +26,7 @@ data class SessionOverviewViewState( val isCurrentSession: Boolean = false, val isCurrentSessionTrusted: Boolean = false, val deviceInfo: Async = Uninitialized, + val isLoading: Boolean = false, ) : MavericksState { constructor(args: SessionOverviewArgs) : this( deviceId = args.deviceId