LoginActivity.java
2.87 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
package com.huaheng.wms;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import com.huaheng.wms.https.HttpInterface;
import com.huaheng.wms.https.Subscribers.ProgressSubscriber;
import com.huaheng.wms.https.Subscribers.SubscriberOnNextListener;
import com.huaheng.wms.login.UserBean;
import com.huaheng.wms.login.WareHouseBean;
import com.huaheng.wms.util.WMSUtils;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class LoginActivity extends Activity {
@BindView(R.id.userEdit)
EditText userEdit;
@BindView(R.id.passwordEdit)
EditText passwordEdit;
@BindView(R.id.loginBtn)
Button loginBtn;
private Context mContext;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
mContext = this;
}
@OnClick(R.id.loginBtn)
public void onViewClicked() {
login();
}
private void login() {
String userName = userEdit.getText().toString();
String password = passwordEdit.getText().toString();
if (TextUtils.isEmpty(userName)) {
WMSUtils.showShort(this, this.getString(R.string.enter_username));
WMSUtils.requestFocus(userEdit);
return;
}
if (TextUtils.isEmpty(password)) {
WMSUtils.showShort(this, this.getString(R.string.enter_password));
WMSUtils.requestFocus(passwordEdit);
return;
}
HttpInterface.getInsstance().login(new ProgressSubscriber<UserBean>(this, loginListener), userName, password);
}
SubscriberOnNextListener wareHouseListener = new SubscriberOnNextListener<ArrayList<WareHouseBean>>() {
@Override
public void onNext(ArrayList<WareHouseBean> wareHouseList) {
WMSLog.d("wareHouseListener wareHouseBean:" + wareHouseList.get(0));
Intent intent = new Intent();
intent.setClass(mContext, WareHouseActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("wareHouse", wareHouseList);// 序列化
intent.putExtras(bundle);// 发送数据
startActivity(intent);//
}
};
SubscriberOnNextListener loginListener = new SubscriberOnNextListener<UserBean>() {
@Override
public void onNext(UserBean userBean) {
WMSLog.d("loginListener userBean:" + userBean);
HttpInterface.getInsstance().getWarehouseList(new ProgressSubscriber<List<WareHouseBean>>(mContext, wareHouseListener));
}
};
}