MonkeyedTextInputEditText: make more robust

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2020-03-28 18:06:23 -06:00
parent 6a7396bc1d
commit 532c33a13b

View File

@ -19,12 +19,12 @@ class MonkeyedTextInputEditText @JvmOverloads constructor(context: Context, attr
val text = super.getText() val text = super.getText()
if (!text.isNullOrEmpty()) if (!text.isNullOrEmpty())
return text return text
/* We want this expression in TextInputLayout.java to be true: /* We want this expression in TextInputLayout.java to be true if there's a hint set:
* final boolean hasText = editText != null && !TextUtils.isEmpty(editText.getText()); * final boolean hasText = editText != null && !TextUtils.isEmpty(editText.getText());
* But for everyone else it should return the real value, so we check the caller. * But for everyone else it should return the real value, so we check the caller.
*/ */
if (Thread.currentThread().stackTrace[3].className == TextInputLayout::class.qualifiedName) if (!hint.isNullOrEmpty() && Thread.currentThread().stackTrace[3].className == TextInputLayout::class.qualifiedName)
return SpannableStringBuilder(" ") return SpannableStringBuilder(hint)
return text return text
} }
} }