2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-05 21:20:45 +00:00

FNX2-15653:checks blanks name in homescreen shortcut name

This commit is contained in:
bawyap 2020-08-20 14:09:48 +05:30 committed by liuche
parent 76f240bad0
commit b57601df1e

View File

@ -5,6 +5,7 @@
package org.mozilla.fenix.shortcut
import android.os.Bundle
import android.text.Editable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -41,7 +42,7 @@ class CreateShortcutFragment : DialogFragment() {
cancel_button.setOnClickListener { dismiss() }
add_button.setOnClickListener {
val text = shortcut_text.text.toString()
val text = shortcut_text.text.toString().trim()
requireActivity().lifecycleScope.launch {
requireComponents.useCases.webAppUseCases.addToHomescreen(text)
}
@ -57,10 +58,13 @@ class CreateShortcutFragment : DialogFragment() {
}
private fun updateAddButtonEnabledState() {
add_button.isEnabled = shortcut_text.text.isNotEmpty()
add_button.alpha = if (shortcut_text.text.isNotEmpty()) ENABLED_ALPHA else DISABLED_ALPHA
val text = shortcut_text.text
add_button.isEnabled = isTextValid(text)
add_button.alpha = if (isTextValid(text)) ENABLED_ALPHA else DISABLED_ALPHA
}
private fun isTextValid(text: Editable) = text.isNotEmpty() && !text.isBlank()
companion object {
private const val ENABLED_ALPHA = 1.0f
private const val DISABLED_ALPHA = 0.4f