mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Update askUserForTwoFactorAuth for IME_ACTION_DONE to trigger performLogin
This commit is contained in:
parent
89436b0a75
commit
af13a5eb69
1 changed files with 68 additions and 32 deletions
|
|
@ -79,9 +79,16 @@ class LoginActivity : AccountAuthenticatorActivity() {
|
||||||
delegate.installViewFactory()
|
delegate.installViewFactory()
|
||||||
delegate.onCreate(savedInstanceState)
|
delegate.onCreate(savedInstanceState)
|
||||||
|
|
||||||
binding = ActivityLoginBinding.inflate(layoutInflater)
|
|
||||||
|
// Reinitialize binding if null or during recreation
|
||||||
|
if (binding == null) {
|
||||||
|
binding = ActivityLoginBinding.inflate(layoutInflater)
|
||||||
|
setContentView(binding!!.root)
|
||||||
|
}
|
||||||
|
|
||||||
|
// binding = ActivityLoginBinding.inflate(layoutInflater)
|
||||||
with(binding!!) {
|
with(binding!!) {
|
||||||
setContentView(root)
|
// setContentView(root)
|
||||||
|
|
||||||
loginUsername.addTextChangedListener(textWatcher)
|
loginUsername.addTextChangedListener(textWatcher)
|
||||||
loginPassword.addTextChangedListener(textWatcher)
|
loginPassword.addTextChangedListener(textWatcher)
|
||||||
|
|
@ -182,35 +189,41 @@ class LoginActivity : AccountAuthenticatorActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
// if progressDialog is visible during the configuration change then store state as true else false so that
|
super.onSaveInstanceState(outState)
|
||||||
// we maintain visibility of progressDialog after configuration change
|
|
||||||
if (progressDialog != null && progressDialog!!.isShowing) {
|
if (progressDialog != null && progressDialog!!.isShowing) {
|
||||||
outState.putBoolean(SAVE_PROGRESS_DIALOG, true)
|
outState.putBoolean(SAVE_PROGRESS_DIALOG, true)
|
||||||
} else {
|
} else {
|
||||||
outState.putBoolean(SAVE_PROGRESS_DIALOG, false)
|
outState.putBoolean(SAVE_PROGRESS_DIALOG, false)
|
||||||
}
|
}
|
||||||
outState.putString(
|
binding?.let { binding ->
|
||||||
SAVE_ERROR_MESSAGE,
|
outState.putString(SAVE_ERROR_MESSAGE, binding.errorMessage.text.toString())
|
||||||
binding!!.errorMessage.text.toString()
|
outState.putString(SAVE_USERNAME, binding.loginUsername.text.toString())
|
||||||
) //Save the errorMessage
|
outState.putString(SAVE_PASSWORD, binding.loginPassword.text.toString())
|
||||||
outState.putString(
|
}
|
||||||
SAVE_USERNAME,
|
// Save lastLoginResult as a string (workaround if not Parcelable)
|
||||||
binding!!.loginUsername.text.toString()
|
lastLoginResult?.let { result ->
|
||||||
) // Save the username
|
// Assuming LoginResult has a toString() or can be serialized
|
||||||
outState.putString(
|
outState.putString("last_login_result", result.toString())
|
||||||
SAVE_PASSWORD,
|
}
|
||||||
binding!!.loginPassword.text.toString()
|
|
||||||
) // Save the password
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onRestoreInstanceState(savedInstanceState)
|
super.onRestoreInstanceState(savedInstanceState)
|
||||||
binding!!.loginUsername.setText(savedInstanceState.getString(SAVE_USERNAME))
|
binding?.let {
|
||||||
binding!!.loginPassword.setText(savedInstanceState.getString(SAVE_PASSWORD))
|
it.loginUsername.setText(savedInstanceState.getString(SAVE_USERNAME))
|
||||||
|
it.loginPassword.setText(savedInstanceState.getString(SAVE_PASSWORD))
|
||||||
|
}
|
||||||
if (savedInstanceState.getBoolean(SAVE_PROGRESS_DIALOG)) {
|
if (savedInstanceState.getBoolean(SAVE_PROGRESS_DIALOG)) {
|
||||||
performLogin()
|
performLogin()
|
||||||
}
|
}
|
||||||
val errorMessage = savedInstanceState.getString(SAVE_ERROR_MESSAGE)
|
val errorMessage = savedInstanceState.getString(SAVE_ERROR_MESSAGE)
|
||||||
|
// Restore lastLoginResult from string (workaround)
|
||||||
|
val lastLoginResultString = savedInstanceState.getString("last_login_result")
|
||||||
|
if (!lastLoginResultString.isNullOrEmpty()) {
|
||||||
|
// Note: This is a placeholder; toString() doesn't reconstruct the object
|
||||||
|
// You may need to handle this based on your logic (e.g., recreate a default LoginResult)
|
||||||
|
lastLoginResult = null // or recreate based on string if possible
|
||||||
|
}
|
||||||
if (sessionManager.isUserLoggedIn) {
|
if (sessionManager.isUserLoggedIn) {
|
||||||
showMessage(R.string.login_success, R.color.primaryDarkColor)
|
showMessage(R.string.login_success, R.color.primaryDarkColor)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -283,17 +296,21 @@ class LoginActivity : AccountAuthenticatorActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun twoFactorPrompt(loginResult: LoginResult, caught: Throwable, token: String?) = runOnUiThread {
|
override fun twoFactorPrompt(loginResult: LoginResult, caught: Throwable, token: String?) = runOnUiThread {
|
||||||
Timber.d("Requesting 2FA prompt")
|
if (!isFinishing && !isDestroyed) {
|
||||||
progressDialog!!.dismiss()
|
Timber.d("Requesting 2FA prompt")
|
||||||
lastLoginResult = loginResult
|
progressDialog!!.dismiss()
|
||||||
askUserForTwoFactorAuth()
|
lastLoginResult = loginResult
|
||||||
|
askUserForTwoFactorAuth()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun emailAuthPrompt(loginResult: LoginResult, caught: Throwable, token: String?) {
|
override fun emailAuthPrompt(loginResult: LoginResult, caught: Throwable, token: String?) = runOnUiThread{
|
||||||
Timber.d("Requesting email auth prompt")
|
if (!isFinishing && !isDestroyed) {
|
||||||
progressDialog!!.dismiss()
|
Timber.d("Requesting email auth prompt")
|
||||||
lastLoginResult = loginResult
|
progressDialog!!.dismiss()
|
||||||
askUserForTwoFactorAuth()
|
lastLoginResult = loginResult
|
||||||
|
askUserForTwoFactorAuth()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun passwordResetPrompt(token: String?) = runOnUiThread {
|
override fun passwordResetPrompt(token: String?) = runOnUiThread {
|
||||||
|
|
@ -348,12 +365,31 @@ class LoginActivity : AccountAuthenticatorActivity() {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
fun askUserForTwoFactorAuth() {
|
fun askUserForTwoFactorAuth() {
|
||||||
|
if (binding == null) {
|
||||||
|
Timber.w("Binding is null, reinitializing in askUserForTwoFactorAuth")
|
||||||
|
binding = ActivityLoginBinding.inflate(layoutInflater)
|
||||||
|
setContentView(binding!!.root)
|
||||||
|
}
|
||||||
progressDialog!!.dismiss()
|
progressDialog!!.dismiss()
|
||||||
with(binding!!) {
|
if (binding != null) {
|
||||||
twoFactorContainer.visibility = View.VISIBLE
|
with(binding!!) {
|
||||||
twoFactorContainer.hint = getString(if (lastLoginResult is LoginResult.EmailAuthResult) R.string.email_auth_code else R.string._2fa_code)
|
twoFactorContainer.visibility = View.VISIBLE
|
||||||
loginTwoFactor.visibility = View.VISIBLE
|
twoFactorContainer.hint = getString(if (lastLoginResult is LoginResult.EmailAuthResult) R.string.email_auth_code else R.string._2fa_code)
|
||||||
loginTwoFactor.requestFocus()
|
loginTwoFactor.visibility = View.VISIBLE
|
||||||
|
loginTwoFactor.requestFocus()
|
||||||
|
|
||||||
|
loginTwoFactor.setOnEditorActionListener { _, actionId, event ->
|
||||||
|
if (actionId == EditorInfo.IME_ACTION_DONE ||
|
||||||
|
(event != null && event.keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_DOWN)) {
|
||||||
|
performLogin()
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Timber.e("Binding is null in askUserForTwoFactorAuth after reinitialization attempt")
|
||||||
}
|
}
|
||||||
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY)
|
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue