-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refresh stale authentication token during auto upload
Fixes #495
- Loading branch information
Showing
8 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...n/src/main/java/org/cryptomator/presentation/presenter/AutoUploadRefreshTokenPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.cryptomator.presentation.presenter | ||
|
||
import org.cryptomator.domain.Cloud | ||
import org.cryptomator.domain.di.PerView | ||
import org.cryptomator.domain.exception.authentication.AuthenticationException | ||
import org.cryptomator.generator.Callback | ||
import org.cryptomator.presentation.CryptomatorApp | ||
import org.cryptomator.presentation.exception.ExceptionHandlers | ||
import org.cryptomator.presentation.ui.activity.view.AutoUploadRefreshTokenView | ||
import org.cryptomator.presentation.workflow.ActivityResult | ||
import org.cryptomator.presentation.workflow.AuthenticationExceptionHandler | ||
import javax.inject.Inject | ||
|
||
@PerView | ||
class AutoUploadRefreshTokenPresenter @Inject constructor( | ||
exceptionHandlers: ExceptionHandlers, // | ||
private val authenticationExceptionHandler: AuthenticationExceptionHandler, // | ||
) : Presenter<AutoUploadRefreshTokenView>(exceptionHandlers) { | ||
|
||
fun refreshCloudToken(authenticationException: AuthenticationException) { | ||
authenticationExceptionHandler.handleAuthenticationException( // | ||
this@AutoUploadRefreshTokenPresenter, // | ||
authenticationException, // | ||
ActivityResultCallbacks.onAutoUploadCloudAuthenticated(authenticationException.cloud) | ||
) | ||
} | ||
|
||
@Callback(dispatchResultOkOnly = false) | ||
fun onAutoUploadCloudAuthenticated(result: ActivityResult, cloud: Cloud) { | ||
if (result.isResultOk) { | ||
val cryptomatorApp = activity().application as CryptomatorApp | ||
cryptomatorApp.startAutoUpload(cloud) | ||
} | ||
finish() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../src/main/java/org/cryptomator/presentation/ui/activity/AutoUploadRefreshTokenActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.cryptomator.presentation.ui.activity | ||
|
||
import android.os.Bundle | ||
import org.cryptomator.domain.exception.authentication.AuthenticationException | ||
import org.cryptomator.generator.Activity | ||
import org.cryptomator.presentation.R | ||
import org.cryptomator.presentation.presenter.AutoUploadRefreshTokenPresenter | ||
import org.cryptomator.presentation.ui.activity.view.AutoUploadRefreshTokenView | ||
import javax.inject.Inject | ||
import timber.log.Timber | ||
|
||
@Activity(layout = R.layout.activity_empty) | ||
class AutoUploadRefreshTokenActivity : BaseActivity(), AutoUploadRefreshTokenView { | ||
|
||
@Inject | ||
lateinit var presenter: AutoUploadRefreshTokenPresenter | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val cloud = intent.getSerializableExtra(AUTHENTICATION_EXCEPTION_ARG) as? AuthenticationException | ||
cloud?.let { | ||
presenter.refreshCloudToken(it) | ||
} ?: run { | ||
Timber.tag("AutoUploadRefreshTokenActivity").e("WrongCredentialsException not provided") | ||
finish() | ||
} | ||
} | ||
|
||
companion object { | ||
const val AUTHENTICATION_EXCEPTION_ARG = "authenticationException" | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...src/main/java/org/cryptomator/presentation/ui/activity/view/AutoUploadRefreshTokenView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.cryptomator.presentation.ui.activity.view | ||
|
||
interface AutoUploadRefreshTokenView : View { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters