Loading dialog during signout process
This commit is contained in:
parent
b2b3ee1fe5
commit
d6bb6efb1d
@ -139,6 +139,7 @@ class SessionOverviewFragment :
|
|||||||
updateToolbar(state.isCurrentSession)
|
updateToolbar(state.isCurrentSession)
|
||||||
updateEntryDetails(state.deviceId)
|
updateEntryDetails(state.deviceId)
|
||||||
updateSessionInfo(state)
|
updateSessionInfo(state)
|
||||||
|
updateLoading(state.isLoading)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateToolbar(isCurrentSession: Boolean) {
|
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 ->
|
private val reAuthActivityResultLauncher = registerStartForActivityResult { activityResult ->
|
||||||
if (activityResult.resultCode == Activity.RESULT_OK) {
|
if (activityResult.resultCode == Activity.RESULT_OK) {
|
||||||
when (activityResult.data?.extras?.getString(ReAuthActivity.RESULT_FLOW_TYPE)) {
|
when (activityResult.data?.extras?.getString(ReAuthActivity.RESULT_FLOW_TYPE)) {
|
||||||
|
@ -139,16 +139,10 @@ class SessionOverviewViewModel @AssistedInject constructor(
|
|||||||
// TODO add unit tests
|
// TODO add unit tests
|
||||||
private fun handleSignoutSession() = withState { state ->
|
private fun handleSignoutSession() = withState { state ->
|
||||||
// TODO for current session: do the same process as sign out button in the general settings
|
// 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 {
|
viewModelScope.launch {
|
||||||
val signoutResult = signoutSessionUseCase.execute(state.deviceId, object : UserInteractiveAuthInterceptor {
|
setLoading(true)
|
||||||
override fun performStage(flowResponse: RegistrationFlowResponse, errCode: String?, promise: Continuation<UIABaseAuth>) {
|
val signoutResult = signout(state.deviceId)
|
||||||
when (val result = interceptSignoutFlowResponseUseCase.execute(flowResponse, errCode, promise)) {
|
setLoading(false)
|
||||||
is SignoutSessionResult.ReAuthNeeded -> onReAuthNeeded(result)
|
|
||||||
is SignoutSessionResult.Completed -> Unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (signoutResult.isSuccess) {
|
if (signoutResult.isSuccess) {
|
||||||
onSignoutSuccess()
|
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) {
|
private fun onReAuthNeeded(reAuthNeeded: SignoutSessionResult.ReAuthNeeded) {
|
||||||
Timber.d("onReAuthNeeded")
|
Timber.d("onReAuthNeeded")
|
||||||
pendingAuthHandler.pendingAuth = DefaultBaseAuth(session = reAuthNeeded.flowResponse.session)
|
pendingAuthHandler.pendingAuth = DefaultBaseAuth(session = reAuthNeeded.flowResponse.session)
|
||||||
@ -168,6 +171,10 @@ class SessionOverviewViewModel @AssistedInject constructor(
|
|||||||
_viewEvents.post(SessionOverviewViewEvent.RequestReAuth(reAuthNeeded.flowResponse, reAuthNeeded.errCode))
|
_viewEvents.post(SessionOverviewViewEvent.RequestReAuth(reAuthNeeded.flowResponse, reAuthNeeded.errCode))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setLoading(isLoading: Boolean) {
|
||||||
|
setState { copy(isLoading = isLoading) }
|
||||||
|
}
|
||||||
|
|
||||||
private fun onSignoutSuccess() {
|
private fun onSignoutSuccess() {
|
||||||
Timber.d("signout success")
|
Timber.d("signout success")
|
||||||
refreshDeviceList()
|
refreshDeviceList()
|
||||||
|
@ -26,6 +26,7 @@ data class SessionOverviewViewState(
|
|||||||
val isCurrentSession: Boolean = false,
|
val isCurrentSession: Boolean = false,
|
||||||
val isCurrentSessionTrusted: Boolean = false,
|
val isCurrentSessionTrusted: Boolean = false,
|
||||||
val deviceInfo: Async<DeviceFullInfo> = Uninitialized,
|
val deviceInfo: Async<DeviceFullInfo> = Uninitialized,
|
||||||
|
val isLoading: Boolean = false,
|
||||||
) : MavericksState {
|
) : MavericksState {
|
||||||
constructor(args: SessionOverviewArgs) : this(
|
constructor(args: SessionOverviewArgs) : this(
|
||||||
deviceId = args.deviceId
|
deviceId = args.deviceId
|
||||||
|
Loading…
Reference in New Issue
Block a user