|
| 1 | +package org.cryptomator.presentation.presenter |
| 2 | + |
| 3 | +import org.cryptomator.domain.Cloud |
| 4 | +import org.cryptomator.domain.di.PerView |
| 5 | +import org.cryptomator.domain.exception.authentication.AuthenticationException |
| 6 | +import org.cryptomator.generator.Callback |
| 7 | +import org.cryptomator.presentation.CryptomatorApp |
| 8 | +import org.cryptomator.presentation.exception.ExceptionHandlers |
| 9 | +import org.cryptomator.presentation.ui.activity.view.AutoUploadRefreshTokenView |
| 10 | +import org.cryptomator.presentation.workflow.ActivityResult |
| 11 | +import org.cryptomator.presentation.workflow.AuthenticationExceptionHandler |
| 12 | +import javax.inject.Inject |
| 13 | + |
| 14 | +@PerView |
| 15 | +class AutoUploadRefreshTokenPresenter @Inject constructor( |
| 16 | + exceptionHandlers: ExceptionHandlers, // |
| 17 | + private val authenticationExceptionHandler: AuthenticationExceptionHandler, // |
| 18 | +) : Presenter<AutoUploadRefreshTokenView>(exceptionHandlers) { |
| 19 | + |
| 20 | + fun refreshCloudToken(authenticationException: AuthenticationException) { |
| 21 | + authenticationExceptionHandler.handleAuthenticationException( // |
| 22 | + this@AutoUploadRefreshTokenPresenter, // |
| 23 | + authenticationException, // |
| 24 | + ActivityResultCallbacks.onAutoUploadCloudAuthenticated(authenticationException.cloud) |
| 25 | + ) |
| 26 | + } |
| 27 | + |
| 28 | + @Callback(dispatchResultOkOnly = false) |
| 29 | + fun onAutoUploadCloudAuthenticated(result: ActivityResult, cloud: Cloud) { |
| 30 | + if (result.isResultOk) { |
| 31 | + val cryptomatorApp = activity().application as CryptomatorApp |
| 32 | + cryptomatorApp.startAutoUpload(cloud) |
| 33 | + } |
| 34 | + finish() |
| 35 | + } |
| 36 | +} |
0 commit comments