-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoginActivity.java
More file actions
108 lines (89 loc) · 2.98 KB
/
LoginActivity.java
File metadata and controls
108 lines (89 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.jcminarro.authexample.login;
import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.jcminarro.authexample.R;
import com.jcminarro.authexample.internal.di.component.DaggerLoginComponent;
import com.jcminarro.authexample.internal.di.component.LoginComponent;
import com.jcminarro.authexample.internal.di.injectablebase.BaseInjectionActivity;
import com.jcminarro.authexample.internal.di.module.ActivityModule;
import com.jcminarro.authexample.internal.presenter.Presenter;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.OnClick;
public class LoginActivity extends BaseInjectionActivity<LoginComponent> implements LoginPresenter.View {
@BindView(R.id.username) AutoCompleteTextView username;
@BindView(R.id.password) EditText password;
@BindView(R.id.login_progress) View loading;
@BindView(R.id.login_form) View loginForm;
@Inject
@Presenter LoginPresenter presenter;
public static Intent getLaunchIntent(Context context) {
return new Intent(context, LoginActivity.class);
}
@Override
protected void onConfigureViews() {
super.onConfigureViews();
password.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) {
onLogin();
return true;
}
return false;
}
});
}
@Override
protected void initDI() {
activityComponent = DaggerLoginComponent
.builder()
.appComponent(getAppComponent())
.activityModule(new ActivityModule(this))
.build();
activityComponent.inject(this);
}
private void onLogin() {
presenter.loginFP(username.getText().toString(),
password.getText().toString());
}
@Override
protected int getLayout() {
return R.layout.activity_login;
}
@OnClick(R.id.signIn)
public void onLoginClick() {
onLogin();
}
@Override
public void close() {
onBackPressed();
}
@Override
public void showError() {
Toast.makeText(this, R.string.error_invalid_credential, Toast.LENGTH_LONG).show();
}
@Override
public void showLogin() {
loginForm.setVisibility(View.VISIBLE);
}
@Override
public void hideLogin() {
loginForm.setVisibility(View.GONE);
}
@Override
public void showLoading() {
loading.setVisibility(View.VISIBLE);
}
@Override
public void hideLoading() {
loading.setVisibility(View.GONE);
}
}