Commit 79a1e5d8 authored by Aniket's avatar Aniket

adds error texts to login edit texts

parent 6f80a3c4
...@@ -13,6 +13,10 @@ public interface LoginContract { ...@@ -13,6 +13,10 @@ public interface LoginContract {
void hideLoader(); void hideLoader();
void showErrorInUsernameEditText();
void showErrorInPasswordEditText();
void showError(String message); void showError(String message);
void showLoginServices(List<LoginServiceConfiguration> loginServiceList); void showLoginServices(List<LoginServiceConfiguration> loginServiceList);
......
...@@ -3,7 +3,11 @@ package chat.rocket.android.fragment.server_config ...@@ -3,7 +3,11 @@ package chat.rocket.android.fragment.server_config
import android.os.Bundle import android.os.Bundle
import android.support.constraint.ConstraintLayout import android.support.constraint.ConstraintLayout
import android.support.design.widget.Snackbar import android.support.design.widget.Snackbar
import android.support.design.widget.TextInputLayout
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.view.View import android.view.View
import android.widget.Button import android.widget.Button
import android.widget.TextView import android.widget.TextView
...@@ -26,6 +30,8 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View { ...@@ -26,6 +30,8 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View {
private lateinit var waitingView: View private lateinit var waitingView: View
private lateinit var txtUsername: TextView private lateinit var txtUsername: TextView
private lateinit var txtPasswd: TextView private lateinit var txtPasswd: TextView
private lateinit var textInputUsername: TextInputLayout
private lateinit var textInputPassword: TextInputLayout
override fun getLayout(): Int { override fun getLayout(): Int {
return R.layout.fragment_login return R.layout.fragment_login
...@@ -48,6 +54,38 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View { ...@@ -48,6 +54,38 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View {
val btnUserRegistration = rootView.findViewById<Button>(R.id.btn_user_registration) val btnUserRegistration = rootView.findViewById<Button>(R.id.btn_user_registration)
txtUsername = rootView.findViewById(R.id.editor_username) txtUsername = rootView.findViewById(R.id.editor_username)
txtPasswd = rootView.findViewById(R.id.editor_passwd) txtPasswd = rootView.findViewById(R.id.editor_passwd)
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?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
if(!TextUtils.isEmpty(txtUsername.text.toString()) && textInputUsername.isErrorEnabled)
textInputUsername.setErrorEnabled(false)
}
})
txtPasswd.addTextChangedListener(object :TextWatcher
{
override fun afterTextChanged(p0: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
if(!TextUtils.isEmpty(txtPasswd.text.toString()) && textInputPassword.isErrorEnabled)
textInputPassword.setErrorEnabled(false)
}
})
waitingView = rootView.findViewById(R.id.waiting) waitingView = rootView.findViewById(R.id.waiting)
btnEmail.setOnClickListener { _ -> presenter.login(txtUsername.text.toString(), txtPasswd.text.toString()) } btnEmail.setOnClickListener { _ -> presenter.login(txtUsername.text.toString(), txtPasswd.text.toString()) }
...@@ -63,6 +101,16 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View { ...@@ -63,6 +101,16 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View {
waitingView.visibility = View.VISIBLE waitingView.visibility = View.VISIBLE
} }
override fun showErrorInUsernameEditText(){
textInputUsername.setErrorEnabled(true);
textInputUsername.setError("Enter a Username")
}
override fun showErrorInPasswordEditText(){
textInputPassword.setErrorEnabled(true);
textInputPassword.setError("Enter a Password")
}
override fun hideLoader() { override fun hideLoader() {
waitingView.visibility = View.GONE waitingView.visibility = View.GONE
container.visibility = View.VISIBLE container.visibility = View.VISIBLE
......
...@@ -31,6 +31,8 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi ...@@ -31,6 +31,8 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi
getLoginServices() getLoginServices()
} }
override fun goBack() { override fun goBack() {
val context = RocketChatApplication.getInstance() val context = RocketChatApplication.getInstance()
val hostname = RocketChatCache.getSelectedServerHostname() val hostname = RocketChatCache.getSelectedServerHostname()
...@@ -43,7 +45,19 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi ...@@ -43,7 +45,19 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi
} }
override fun login(username: String, password: String) { override fun login(username: String, password: String) {
if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
//set error to edit texts
if (TextUtils.isEmpty(username)&&TextUtils.isEmpty(password)) {
view.showErrorInUsernameEditText()
view.showErrorInPasswordEditText()
return
}
if (TextUtils.isEmpty(username)) {
view.showErrorInUsernameEditText()
return
}
if (TextUtils.isEmpty(password)){
view.showErrorInPasswordEditText()
return 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