[Android] Fix a visual issue when clearing a text input

Nicolas Pomepuy git at videolan.org
Wed Jul 12 08:30:37 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jul  6 08:54:14 2023 +0200| [c0df70d346f013583fa8cb940ddb944baa633ffd] | committer: Duncan McNamara

Fix a visual issue when clearing a text input

If the text input is not focused during or after its text is cleared
we force a request layout to make sure its state is updated

> https://code.videolan.org/videolan/vlc-android/commit/c0df70d346f013583fa8cb940ddb944baa633ffd
---

 .../src/org/videolan/vlc/gui/PinCodeActivity.kt         | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt
index d627e46789..beee551fac 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt
@@ -39,6 +39,7 @@ import androidx.databinding.DataBindingUtil
 import androidx.lifecycle.AndroidViewModel
 import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.ViewModelProvider
+import com.google.android.material.textfield.TextInputEditText
 import org.videolan.resources.AndroidDevices
 import org.videolan.resources.util.applyOverscanMargin
 import org.videolan.tools.KEY_SAFE_MODE_PIN
@@ -105,7 +106,7 @@ class PinCodeActivity : BaseActivity() {
                 //Manage backspace button
                 if (keyCode == KeyEvent.KEYCODE_DEL && event.action == KeyEvent.ACTION_DOWN) {
                     if (editText.text?.isNotEmpty() == true) return at setOnKeyListener false
-                    getLastSetET()?.text?.clear()
+                    getLastSetET()?.clearText()
                     updateFocus()
                     return at setOnKeyListener true
                 }
@@ -162,7 +163,7 @@ class PinCodeActivity : BaseActivity() {
             it.setOnClickListener { keyboardButton ->
                 when (keyboardButton.tag) {
                     "-1" -> {
-                        getLastSetET()?.text?.clear()
+                        getLastSetET()?.clearText()
                     }
 
                     else -> getCurrentInput()?.setText(keyboardButton.tag as String)
@@ -261,9 +262,10 @@ class PinCodeActivity : BaseActivity() {
             }
 
             KeyEvent.KEYCODE_DEL -> {
-                getLastSetET()?.text?.clear()
+                getLastSetET()?.clearText()
                 true
             }
+
             KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_NUMPAD_ENTER -> {
                 next()
                 true
@@ -284,12 +286,12 @@ class PinCodeActivity : BaseActivity() {
                 setResult(RESULT_OK)
                 finish()
             } else {
-                pinTexts.forEach { it.text?.clear() }
+                pinTexts.forEach { it.clearText() }
                 return
             }
         }
         model.nextStep(getPinCode())
-        pinTexts.forEach { it.text?.clear() }
+        pinTexts.forEach { it.clearText() }
     }
 
     override fun onOptionsItemSelected(item: MenuItem): Boolean {
@@ -395,3 +397,8 @@ enum class PinCodeReason {
     FIRST_CREATION, MODIFY, CHECK
 }
 
+fun TextInputEditText.clearText() {
+    text?.clear()
+    requestLayout()
+}
+



More information about the Android mailing list