Unverified Commit cb779001 authored by Aniket Singh's avatar Aniket Singh Committed by GitHub

Merge branch 'develop' into patch-5

parents 05c4fcb0 bc498fc2
......@@ -12,31 +12,31 @@ import chat.rocket.android.activity.MainActivity;
*/
public class LaunchUtil {
/**
* launch MainActivity with proper flags.
*/
public static void showMainActivity(Context context) {
Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
/**
* launch MainActivity with proper flags.
*/
public static void showMainActivity(Context context) {
Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
/**
* launch AddServerActivity with proper flags.
*/
public static void showAddServerActivity(Context context) {
Intent intent = new Intent(context, AddServerActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
/**
* launch AddServerActivity with proper flags.
*/
public static void showAddServerActivity(Context context) {
Intent intent = new Intent(context, AddServerActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
/**
* launch ServerConfigActivity with proper flags.
*/
public static void showLoginActivity(Context context, String hostname) {
Intent intent = new Intent(context, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(LoginActivity.KEY_HOSTNAME, hostname);
context.startActivity(intent);
}
/**
* launch ServerConfigActivity with proper flags.
*/
public static void showLoginActivity(Context context, String hostname) {
Intent intent = new Intent(context, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(LoginActivity.KEY_HOSTNAME, hostname);
context.startActivity(intent);
}
}
......@@ -16,6 +16,10 @@ public interface LoginContract {
void hideLoader();
void showErrorInUsernameEditText();
void showErrorInPasswordEditText();
void showError(String message);
void showLoginServices(List<LoginServiceConfiguration> loginServiceList);
......
......@@ -4,7 +4,9 @@ import android.content.Context
import android.os.Bundle
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.TextUtils
import android.view.View
import android.widget.Button
import android.widget.TextView
......@@ -15,8 +17,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.
*/
......@@ -27,6 +31,8 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View {
private lateinit var waitingView: View
private lateinit var txtUsername: TextView
private lateinit var txtPasswd: TextView
private lateinit var textInputUsername: TextInputLayout
private lateinit var textInputPassword: TextInputLayout
override fun getLayout(): Int {
return R.layout.fragment_login
......@@ -49,6 +55,11 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View {
val btnUserRegistration = rootView.findViewById<Button>(R.id.btn_user_registration)
txtUsername = rootView.findViewById(R.id.editor_username)
txtPasswd = rootView.findViewById(R.id.editor_passwd)
textInputUsername = rootView.findViewById(R.id.text_input_username)
textInputPassword = rootView.findViewById(R.id.text_input_passwd)
setUpRxBinders()
waitingView = rootView.findViewById(R.id.waiting)
btnEmail.setOnClickListener { _ -> presenter.login(txtUsername.text.toString(), txtPasswd.text.toString()) }
......@@ -59,11 +70,34 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View {
}
}
fun setUpRxBinders() {
RxTextView.textChanges(txtUsername).subscribe { text ->
if (!TextUtils.isEmpty(text) && textInputUsername.isErrorEnabled)
textInputUsername.setErrorEnabled(false)
}
RxTextView.textChanges(txtPasswd).subscribe { text ->
if (!TextUtils.isEmpty(text) && textInputPassword.isErrorEnabled)
textInputPassword.setErrorEnabled(false)
}
}
override fun showLoader() {
container.visibility = View.GONE
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() {
waitingView.visibility = View.GONE
container.visibility = View.VISIBLE
......
......@@ -32,6 +32,7 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi
getLoginServices()
}
override fun goBack(ctx : Context?) {
val context = RocketChatApplication.getInstance()
val hostname = RocketChatCache.getSelectedServerHostname()
......@@ -44,7 +45,19 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi
}
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
}
......
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