From ff822d55c51cc8138dd6fb11be6483c169860cd0 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Wed, 18 Sep 2024 14:19:22 +0200 Subject: [PATCH] fix: setTextListeners() function deleted because editetxt is not focusable --- .../android/extensions/ActivityExt.kt | 12 ++++++ .../security/passcode/PassCodeActivity.kt | 38 ------------------- 2 files changed, 12 insertions(+), 38 deletions(-) diff --git a/owncloudApp/src/main/java/com/owncloud/android/extensions/ActivityExt.kt b/owncloudApp/src/main/java/com/owncloud/android/extensions/ActivityExt.kt index fd83b8ebff6..e92e75ccf12 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/extensions/ActivityExt.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/extensions/ActivityExt.kt @@ -34,6 +34,7 @@ import android.net.Uri import android.text.method.LinkMovementMethod import android.util.TypedValue import android.view.ContextThemeWrapper +import android.view.inputmethod.InputMethodManager import android.webkit.MimeTypeMap import android.widget.Button import android.widget.LinearLayout @@ -273,6 +274,17 @@ private fun makeIntent(file: File?, context: Context): Intent { return sendIntent } +fun Activity.hideSoftKeyboard() { + val focusedView = currentFocus + focusedView?.let { + val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + inputMethodManager.hideSoftInputFromWindow( + focusedView.windowToken, + 0 + ) + } +} + fun Activity.checkPasscodeEnforced(securityEnforced: SecurityEnforced) { val sharedPreferencesProvider = OCSharedPreferencesProvider(this) val mdmProvider by inject() diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/security/passcode/PassCodeActivity.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/security/passcode/PassCodeActivity.kt index c434daee4f0..5dcda2ba161 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/security/passcode/PassCodeActivity.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/security/passcode/PassCodeActivity.kt @@ -35,7 +35,6 @@ import android.text.Editable import android.view.KeyEvent import android.view.MenuItem import android.view.View -import android.view.View.OnFocusChangeListener import android.view.WindowManager import android.widget.EditText import android.widget.LinearLayout @@ -162,8 +161,6 @@ class PassCodeActivity : AppCompatActivity(), NumberKeyboardListener, EnableBiom throw IllegalArgumentException(R.string.illegal_argument_exception_message.toString() + " ") } } - - setTextListeners() } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -187,41 +184,6 @@ class PassCodeActivity : AppCompatActivity(), NumberKeyboardListener, EnableBiom passCodeEditTexts.first()?.requestFocus() } - /** - * Binds the appropriate listeners to the input boxes receiving each digit of the pass code. - */ - private fun setTextListeners() { - val numberOfPasscodeDigits = (passCodeViewModel.getPassCode()?.length ?: passCodeViewModel.getNumberOfPassCodeDigits()) - for (i in 0 until numberOfPasscodeDigits) { - - passCodeEditTexts[i]?.setOnKeyListener { v, keyCode, event -> - if (keyCode == KeyEvent.KEYCODE_TAB && event.action == KeyEvent.ACTION_DOWN) { - val focusDirection = if (passCodeEditTexts.indexOf(v) == 0) { - View.FOCUS_DOWN - } else { - View.FOCUS_RIGHT - } - v.focusSearch(focusDirection)?.requestFocus() - true - } else { - false - } - } - - passCodeEditTexts[i]?.onFocusChangeListener = OnFocusChangeListener { _: View, _: Boolean -> - // Return the focus to the first EditText without number - for (j in 0 until i) { - if (passCodeEditTexts[j]?.text.toString() == "") { // TODO WIP validation - // could be done in a global way, with a single OnFocusChangeListener for all the - // input fields - passCodeEditTexts[j]?.requestFocus() - break - } - } - } - } - } - override fun onNumberClicked(number: Int) { passCodeViewModel.onNumberClicked(number) }