Skip to content

Commit

Permalink
disable "Add account" button while adding an account
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Nov 25, 2021
1 parent 00e3cb6 commit 5c9f0b0
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class MicrosoftAccountsActivity : AppCompatActivity() {
findViewById(R.id.accounts_dropdown)
}

private val addAccountButton: Button by lazy {
findViewById(R.id.add_account)
}

private val executorService: ExecutorService by lazy {
Executors.newSingleThreadExecutor()
}
Expand All @@ -48,17 +52,9 @@ class MicrosoftAccountsActivity : AppCompatActivity() {
}
setAdapter(accountsAdapter)
}
findViewById<TextView>(R.id.add_account).apply {
setOnClickListener {
this@MicrosoftAccountsActivity.onAddAccount()
}
}
signOutButton.setOnClickListener {
onSignOut()
}
signOutAllButton.setOnClickListener {
onSignOutAllAccounts()
}
addAccountButton.setOnClickListener { onAddAccount() }
signOutButton.setOnClickListener { onSignOut() }
signOutAllButton.setOnClickListener { onSignOutAllAccounts() }

withTokenBroker { tokenBroker ->
val allAccounts = tokenBroker.allAccounts()
Expand All @@ -73,13 +69,19 @@ class MicrosoftAccountsActivity : AppCompatActivity() {
}

private fun addAccount(accountType: AccountType) {
addAccountButton.isEnabled = false

withTokenBroker { tokenBroker ->
tokenBroker.acquireToken(
this,
Config.scopesFor(accountType),
null,
accountType
) { result: AuthResult?, error: AuthError? ->
runOnUiThread {
addAccountButton.isEnabled = true
}

when {
error != null -> showErrorMessage(
error.message ?: resources.getString(R.string.error_sign_in)
Expand Down

0 comments on commit 5c9f0b0

Please sign in to comment.