From c850509fe5cd8f87f08b4bee844a0186da32d60e Mon Sep 17 00:00:00 2001 From: jagadeesh-18-bot Date: Sun, 6 Jul 2025 13:41:49 +0530 Subject: [PATCH] Update askUserForTwoFactorAuth for IME_ACTION_DONE to trigger performLogin --- .../fr/free/nrw/commons/auth/LoginActivity.kt | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.kt b/app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.kt index 840bc7ca3..b0f0d16a9 100644 --- a/app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.kt +++ b/app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.kt @@ -348,12 +348,31 @@ class LoginActivity : AccountAuthenticatorActivity() { @VisibleForTesting fun askUserForTwoFactorAuth() { + if (binding == null) { + Timber.w("Binding is null, reinitializing in askUserForTwoFactorAuth") + binding = ActivityLoginBinding.inflate(layoutInflater) + setContentView(binding!!.root) + } progressDialog!!.dismiss() - with(binding!!) { - twoFactorContainer.visibility = View.VISIBLE - twoFactorContainer.hint = getString(if (lastLoginResult is LoginResult.EmailAuthResult) R.string.email_auth_code else R.string._2fa_code) - loginTwoFactor.visibility = View.VISIBLE - loginTwoFactor.requestFocus() + if (binding != null) { + with(binding!!) { + twoFactorContainer.visibility = View.VISIBLE + twoFactorContainer.hint = getString(if (lastLoginResult is LoginResult.EmailAuthResult) R.string.email_auth_code else R.string._2fa_code) + 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 imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY)