forked from github/wulkanowy-mirror
Set error tint to password toggle icon when error occured (#2163)
This commit is contained in:
parent
253e55f70e
commit
c67d2d767d
@ -15,12 +15,7 @@ import io.github.wulkanowy.databinding.FragmentLoginFormBinding
|
||||
import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.modules.login.LoginActivity
|
||||
import io.github.wulkanowy.ui.modules.login.LoginData
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.hideSoftInput
|
||||
import io.github.wulkanowy.utils.openEmailClient
|
||||
import io.github.wulkanowy.utils.openInternetBrowser
|
||||
import io.github.wulkanowy.utils.setOnEditorDoneSignIn
|
||||
import io.github.wulkanowy.utils.showSoftInput
|
||||
import io.github.wulkanowy.utils.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
@ -149,12 +144,14 @@ class LoginFormFragment : BaseFragment<FragmentLoginFormBinding>(R.layout.fragme
|
||||
override fun setErrorPassRequired(focus: Boolean) {
|
||||
with(binding.loginFormPassLayout) {
|
||||
error = getString(R.string.error_field_required)
|
||||
setEndIconTintList(requireContext().getAttrColorStateList(R.attr.colorError))
|
||||
}
|
||||
}
|
||||
|
||||
override fun setErrorPassInvalid(focus: Boolean) {
|
||||
with(binding.loginFormPassLayout) {
|
||||
error = getString(R.string.login_invalid_password)
|
||||
setEndIconTintList(requireContext().getAttrColorStateList(R.attr.colorError))
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,6 +159,7 @@ class LoginFormFragment : BaseFragment<FragmentLoginFormBinding>(R.layout.fragme
|
||||
with(binding) {
|
||||
loginFormUsernameLayout.error = " "
|
||||
loginFormPassLayout.error = " "
|
||||
loginFormPassLayout.setEndIconTintList(requireContext().getAttrColorStateList(R.attr.colorError))
|
||||
loginFormHostLayout.error = " "
|
||||
loginFormErrorBox.text = message ?: getString(R.string.login_incorrect_password_default)
|
||||
loginFormErrorBox.isVisible = true
|
||||
@ -181,6 +179,7 @@ class LoginFormFragment : BaseFragment<FragmentLoginFormBinding>(R.layout.fragme
|
||||
|
||||
override fun clearPassError() {
|
||||
binding.loginFormPassLayout.error = null
|
||||
binding.loginFormPassLayout.setEndIconTintList(null)
|
||||
binding.loginFormErrorBox.isVisible = false
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import android.content.res.ColorStateList
|
||||
import android.graphics.*
|
||||
import android.text.TextPaint
|
||||
import android.util.DisplayMetrics.DENSITY_DEFAULT
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.*
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.ColorUtils
|
||||
@ -14,7 +13,6 @@ import androidx.core.graphics.applyCanvas
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawable
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import androidx.core.widget.ImageViewCompat
|
||||
|
||||
|
||||
@ColorInt
|
||||
@ -89,6 +87,6 @@ fun Context.createNameInitialsDrawable(
|
||||
.apply { isCircular = true }
|
||||
}
|
||||
|
||||
fun ImageView.setTint(@ColorInt color: Int) {
|
||||
ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(color))
|
||||
fun Context.getAttrColorStateList(@AttrRes color: Int): ColorStateList {
|
||||
return ColorStateList.valueOf(getThemeAttrColor(color))
|
||||
}
|
||||
|
@ -180,12 +180,12 @@
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_marginRight="24dp"
|
||||
android:hint="@string/login_password_hint"
|
||||
app:endIconMode="password_toggle"
|
||||
app:errorEnabled="true"
|
||||
app:errorIconDrawable="@null"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/loginFormUsernameLayout"
|
||||
app:passwordToggleEnabled="true">
|
||||
app:layout_constraintTop_toBottomOf="@+id/loginFormUsernameLayout">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/loginFormPass"
|
||||
|
Loading…
x
Reference in New Issue
Block a user