mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Loading dialog during signout process
This commit is contained in:
parent
b2b3ee1fe5
commit
d6bb6efb1d
@ -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)) {
|
||||
|
@ -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<UIABaseAuth>) {
|
||||
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<UIABaseAuth>) {
|
||||
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()
|
||||
|
@ -26,6 +26,7 @@ data class SessionOverviewViewState(
|
||||
val isCurrentSession: Boolean = false,
|
||||
val isCurrentSessionTrusted: Boolean = false,
|
||||
val deviceInfo: Async<DeviceFullInfo> = Uninitialized,
|
||||
val isLoading: Boolean = false,
|
||||
) : MavericksState {
|
||||
constructor(args: SessionOverviewArgs) : this(
|
||||
deviceId = args.deviceId
|
||||
|
Loading…
Reference in New Issue
Block a user