Update text change listener

This commit is contained in:
Hafiz 2022-07-17 09:02:25 -04:00
parent 3aff147a77
commit 13071e6be5
2 changed files with 5 additions and 39 deletions

View file

@ -1,34 +0,0 @@
package com.habitrpg.common.habitica.extensions
import android.text.Editable
import android.text.TextWatcher
class OnChangeTextWatcher(private var function: (CharSequence?, Int, Int, Int) -> Unit) : TextWatcher {
override fun afterTextChanged(s: Editable?) { /* no-on */ }
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { /* no-on */ }
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
function(s, start, before, count)
}
}
class BeforeChangeTextWatcher(private var function: (CharSequence?, Int, Int, Int) -> Unit) : TextWatcher {
override fun afterTextChanged(s: Editable?) { /* no-on */ }
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
function(s, start, count, after)
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { /* no-on */ }
}
class AfterChangeTextWatcher(private var function: (Editable?) -> Unit) : TextWatcher {
override fun afterTextChanged(s: Editable?) {
function(s)
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { /* no-on */ }
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { /* no-on */ }
}

View file

@ -8,10 +8,10 @@ import android.text.method.PasswordTransformationMethod
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.core.view.isVisible
import androidx.core.widget.doOnTextChanged
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.databinding.ActivityLoginBinding
import com.habitrpg.common.habitica.extensions.OnChangeTextWatcher
import com.habitrpg.wearos.habitica.ui.viewmodels.LoginViewModel
import dagger.hilt.android.AndroidEntryPoint
@ -82,12 +82,12 @@ class LoginActivity: BaseActivity<ActivityLoginBinding, LoginViewModel>() {
binding.registerButton.setOnClickListener { openRegisterOnPhone() }
binding.passwordEditText.transformationMethod = PasswordTransformationMethod()
binding.usernameEditText.addTextChangedListener(OnChangeTextWatcher { _, _, _, _ ->
binding.usernameEditText.doOnTextChanged { text, start, before, count ->
setLoginButtonIsEnabled()
})
binding.passwordEditText.addTextChangedListener(OnChangeTextWatcher { _, _, _, _ ->
}
binding.passwordEditText.doOnTextChanged { text, start, before, count ->
setLoginButtonIsEnabled()
})
}
currentState = State.INITIAL
}