1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-09-20 06:49:08 -05:00

Set error tint to password toggle icon when error occured (#2163)

This commit is contained in:
Mikołaj Pich 2023-04-06 01:28:47 +02:00 committed by GitHub
parent 253e55f70e
commit c67d2d767d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 12 deletions

View File

@ -15,12 +15,7 @@ import io.github.wulkanowy.databinding.FragmentLoginFormBinding
import io.github.wulkanowy.ui.base.BaseFragment import io.github.wulkanowy.ui.base.BaseFragment
import io.github.wulkanowy.ui.modules.login.LoginActivity import io.github.wulkanowy.ui.modules.login.LoginActivity
import io.github.wulkanowy.ui.modules.login.LoginData import io.github.wulkanowy.ui.modules.login.LoginData
import io.github.wulkanowy.utils.AppInfo import io.github.wulkanowy.utils.*
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 javax.inject.Inject import javax.inject.Inject
@AndroidEntryPoint @AndroidEntryPoint
@ -149,12 +144,14 @@ class LoginFormFragment : BaseFragment<FragmentLoginFormBinding>(R.layout.fragme
override fun setErrorPassRequired(focus: Boolean) { override fun setErrorPassRequired(focus: Boolean) {
with(binding.loginFormPassLayout) { with(binding.loginFormPassLayout) {
error = getString(R.string.error_field_required) error = getString(R.string.error_field_required)
setEndIconTintList(requireContext().getAttrColorStateList(R.attr.colorError))
} }
} }
override fun setErrorPassInvalid(focus: Boolean) { override fun setErrorPassInvalid(focus: Boolean) {
with(binding.loginFormPassLayout) { with(binding.loginFormPassLayout) {
error = getString(R.string.login_invalid_password) 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) { with(binding) {
loginFormUsernameLayout.error = " " loginFormUsernameLayout.error = " "
loginFormPassLayout.error = " " loginFormPassLayout.error = " "
loginFormPassLayout.setEndIconTintList(requireContext().getAttrColorStateList(R.attr.colorError))
loginFormHostLayout.error = " " loginFormHostLayout.error = " "
loginFormErrorBox.text = message ?: getString(R.string.login_incorrect_password_default) loginFormErrorBox.text = message ?: getString(R.string.login_incorrect_password_default)
loginFormErrorBox.isVisible = true loginFormErrorBox.isVisible = true
@ -181,6 +179,7 @@ class LoginFormFragment : BaseFragment<FragmentLoginFormBinding>(R.layout.fragme
override fun clearPassError() { override fun clearPassError() {
binding.loginFormPassLayout.error = null binding.loginFormPassLayout.error = null
binding.loginFormPassLayout.setEndIconTintList(null)
binding.loginFormErrorBox.isVisible = false binding.loginFormErrorBox.isVisible = false
} }

View File

@ -6,7 +6,6 @@ import android.content.res.ColorStateList
import android.graphics.* import android.graphics.*
import android.text.TextPaint import android.text.TextPaint
import android.util.DisplayMetrics.DENSITY_DEFAULT import android.util.DisplayMetrics.DENSITY_DEFAULT
import android.widget.ImageView
import androidx.annotation.* import androidx.annotation.*
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils 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.RoundedBitmapDrawable
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory
import androidx.core.graphics.drawable.toBitmap import androidx.core.graphics.drawable.toBitmap
import androidx.core.widget.ImageViewCompat
@ColorInt @ColorInt
@ -89,6 +87,6 @@ fun Context.createNameInitialsDrawable(
.apply { isCircular = true } .apply { isCircular = true }
} }
fun ImageView.setTint(@ColorInt color: Int) { fun Context.getAttrColorStateList(@AttrRes color: Int): ColorStateList {
ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(color)) return ColorStateList.valueOf(getThemeAttrColor(color))
} }

View File

@ -180,12 +180,12 @@
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
android:layout_marginRight="24dp" android:layout_marginRight="24dp"
android:hint="@string/login_password_hint" android:hint="@string/login_password_hint"
app:endIconMode="password_toggle"
app:errorEnabled="true" app:errorEnabled="true"
app:errorIconDrawable="@null" app:errorIconDrawable="@null"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginFormUsernameLayout" app:layout_constraintTop_toBottomOf="@+id/loginFormUsernameLayout">
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/loginFormPass" android:id="@+id/loginFormPass"