Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/src/main/java/com/bansify/browser/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ class MainActivity : ComponentActivity() {
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
if (BansifyOAuth.isCallback(intent.data)) {
intent.data?.let { viewModel.handleBansifyAuthCallback(it) }
return
}
handleIncomingIntent(intent)
}

private fun handleIncomingIntent(intent: Intent?) {
// The OAuth redirect can arrive on a cold start too (the system may have killed us
// while the consent page was open), so it is checked here rather than only in
// onNewIntent. Opening it as a tab would silently drop the code.
if (BansifyOAuth.isCallback(intent?.data)) {
intent?.data?.let { viewModel.handleBansifyAuthCallback(it) }
return
}
if (intent?.action == Intent.ACTION_VIEW) {
val url = intent.dataString
if (!url.isNullOrBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1568,8 +1568,17 @@ class BrowserViewModel(application: Application) : AndroidViewModel(application)
}
result
.onSuccess { showSnackbar(getString(R.string.snackbar_signed_in_account)) }
.onFailure {
showSnackbar(getString(R.string.snackbar_bansify_signin_failed))
.onFailure { error ->
// The generic string told the user nothing and told us nothing. Surface
// what actually failed, trimmed to something a snackbar can show.
val detail = error.message?.trim().orEmpty()
showSnackbar(
if (detail.isBlank()) {
getString(R.string.snackbar_bansify_signin_failed)
} else {
detail.take(140)
}
)
}
}
}
Expand Down
Loading