Signout: propose the user to retry in case of error
This commit is contained in:
parent
ced72aff4f
commit
20f53e9a58
|
@ -73,6 +73,38 @@ class MainActivity : VectorBaseActivity() {
|
||||||
|
|
||||||
// Handle some wanted cleanup
|
// Handle some wanted cleanup
|
||||||
if (clearCache || clearCredentials) {
|
if (clearCache || clearCredentials) {
|
||||||
|
doCleanUp(clearCache, clearCredentials)
|
||||||
|
} else {
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun doCleanUp(clearCache: Boolean, clearCredentials: Boolean) {
|
||||||
|
when {
|
||||||
|
clearCredentials -> sessionHolder.getActiveSession().signOut(object : MatrixCallback<Unit> {
|
||||||
|
override fun onSuccess(data: Unit) {
|
||||||
|
Timber.w("SIGN_OUT: success, start app")
|
||||||
|
sessionHolder.clearActiveSession()
|
||||||
|
doLocalCleanupAndStart()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(failure: Throwable) {
|
||||||
|
displayError(failure, clearCache, clearCredentials)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
clearCache -> sessionHolder.getActiveSession().clearCache(object : MatrixCallback<Unit> {
|
||||||
|
override fun onSuccess(data: Unit) {
|
||||||
|
doLocalCleanupAndStart()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(failure: Throwable) {
|
||||||
|
displayError(failure, clearCache, clearCredentials)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun doLocalCleanupAndStart() {
|
||||||
GlobalScope.launch(Dispatchers.Main) {
|
GlobalScope.launch(Dispatchers.Main) {
|
||||||
// On UI Thread
|
// On UI Thread
|
||||||
Glide.get(this@MainActivity).clearMemory()
|
Glide.get(this@MainActivity).clearMemory()
|
||||||
|
@ -84,38 +116,16 @@ class MainActivity : VectorBaseActivity() {
|
||||||
deleteAllFiles(this@MainActivity.cacheDir)
|
deleteAllFiles(this@MainActivity.cacheDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
when {
|
|
||||||
clearCredentials -> sessionHolder.getActiveSession().signOut(object : MatrixCallback<Unit> {
|
|
||||||
override fun onSuccess(data: Unit) {
|
|
||||||
Timber.w("SIGN_OUT: success, start app")
|
|
||||||
sessionHolder.clearActiveSession()
|
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(failure: Throwable) {
|
private fun displayError(failure: Throwable, clearCache: Boolean, clearCredentials: Boolean) {
|
||||||
displayErrorAndStart(failure)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
clearCache -> sessionHolder.getActiveSession().clearCache(object : MatrixCallback<Unit> {
|
|
||||||
override fun onSuccess(data: Unit) {
|
|
||||||
start()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(failure: Throwable) {
|
|
||||||
displayErrorAndStart(failure)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
else -> start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun displayErrorAndStart(failure: Throwable) {
|
|
||||||
AlertDialog.Builder(this)
|
AlertDialog.Builder(this)
|
||||||
.setTitle(R.string.dialog_title_error)
|
.setTitle(R.string.dialog_title_error)
|
||||||
.setMessage(errorFormatter.toHumanReadable(failure))
|
.setMessage(errorFormatter.toHumanReadable(failure))
|
||||||
.setPositiveButton(R.string.ok) { _, _ -> start() }
|
.setPositiveButton(R.string.global_retry) { _, _ -> doCleanUp(clearCache, clearCredentials) }
|
||||||
|
.setNegativeButton(R.string.cancel) { _, _ -> start() }
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue