Commit 124340a7 authored by Aniket's avatar Aniket

implements rxbinders in edit text textwatchers

parent 79a1e5d8
......@@ -5,9 +5,7 @@ import android.support.constraint.ConstraintLayout
import android.support.design.widget.Snackbar
import android.support.design.widget.TextInputLayout
import android.support.v4.app.Fragment
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.view.View
import android.widget.Button
import android.widget.TextView
......@@ -18,8 +16,10 @@ import chat.rocket.android.log.RCLog
import chat.rocket.core.models.LoginServiceConfiguration
import chat.rocket.persistence.realm.repositories.RealmLoginServiceConfigurationRepository
import chat.rocket.persistence.realm.repositories.RealmPublicSettingRepository
import com.jakewharton.rxbinding2.widget.RxTextView
import java.util.*
/**
* Login screen.
*/
......@@ -57,43 +57,29 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View {
textInputUsername = rootView.findViewById(R.id.text_input_username)
textInputPassword = rootView.findViewById(R.id.text_input_passwd)
//setting text change listeners to username and password edit texts
txtUsername.addTextChangedListener(object :TextWatcher
{
override fun afterTextChanged(p0: Editable?) {
}
setUpRxBinders()
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
waitingView = rootView.findViewById(R.id.waiting)
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
if(!TextUtils.isEmpty(txtUsername.text.toString()) && textInputUsername.isErrorEnabled)
textInputUsername.setErrorEnabled(false)
}
})
btnEmail.setOnClickListener { _ -> presenter.login(txtUsername.text.toString(), txtPasswd.text.toString()) }
txtPasswd.addTextChangedListener(object :TextWatcher
{
override fun afterTextChanged(p0: Editable?) {
btnUserRegistration.setOnClickListener { _ ->
UserRegistrationDialogFragment.create(hostname, txtUsername.text.toString(), txtPasswd.text.toString())
.show(fragmentManager!!, "UserRegistrationDialogFragment")
}
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
fun setUpRxBinders() {
RxTextView.textChanges(txtUsername).subscribe { text ->
if (!TextUtils.isEmpty(text) && textInputUsername.isErrorEnabled)
textInputUsername.setErrorEnabled(false)
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
if(!TextUtils.isEmpty(txtPasswd.text.toString()) && textInputPassword.isErrorEnabled)
RxTextView.textChanges(txtPasswd).subscribe { text ->
if (!TextUtils.isEmpty(text) && textInputPassword.isErrorEnabled)
textInputPassword.setErrorEnabled(false)
}
})
waitingView = rootView.findViewById(R.id.waiting)
btnEmail.setOnClickListener { _ -> presenter.login(txtUsername.text.toString(), txtPasswd.text.toString()) }
btnUserRegistration.setOnClickListener { _ ->
UserRegistrationDialogFragment.create(hostname, txtUsername.text.toString(), txtPasswd.text.toString())
.show(fragmentManager!!, "UserRegistrationDialogFragment")
}
}
override fun showLoader() {
......@@ -101,12 +87,12 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View {
waitingView.visibility = View.VISIBLE
}
override fun showErrorInUsernameEditText(){
override fun showErrorInUsernameEditText() {
textInputUsername.setErrorEnabled(true);
textInputUsername.setError("Enter a Username")
}
override fun showErrorInPasswordEditText(){
override fun showErrorInPasswordEditText() {
textInputPassword.setErrorEnabled(true);
textInputPassword.setError("Enter a Password")
}
......
......@@ -32,7 +32,6 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi
}
override fun goBack() {
val context = RocketChatApplication.getInstance()
val hostname = RocketChatCache.getSelectedServerHostname()
......@@ -47,7 +46,7 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi
override fun login(username: String, password: String) {
//set error to edit texts
if (TextUtils.isEmpty(username)&&TextUtils.isEmpty(password)) {
if (TextUtils.isEmpty(username) && TextUtils.isEmpty(password)) {
view.showErrorInUsernameEditText()
view.showErrorInPasswordEditText()
return
......@@ -56,7 +55,7 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi
view.showErrorInUsernameEditText()
return
}
if (TextUtils.isEmpty(password)){
if (TextUtils.isEmpty(password)) {
view.showErrorInPasswordEditText()
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment