|
@@ -7,17 +7,29 @@ import android.view.View;
|
7
|
7
|
import android.widget.Button;
|
8
|
8
|
import android.widget.EditText;
|
9
|
9
|
|
|
10
|
+import com.kuxuan.moneynote.MyApplication;
|
10
|
11
|
import com.kuxuan.moneynote.R;
|
|
12
|
+import com.kuxuan.moneynote.api.ExceptionHandle;
|
|
13
|
+import com.kuxuan.moneynote.api.MyObsever;
|
|
14
|
+import com.kuxuan.moneynote.api.RetrofitClient;
|
11
|
15
|
import com.kuxuan.moneynote.base.BaseActivity;
|
12
|
16
|
import com.kuxuan.moneynote.common.Constant;
|
|
17
|
+import com.kuxuan.moneynote.json.BaseJson;
|
|
18
|
+import com.kuxuan.moneynote.json.MineJson;
|
13
|
19
|
import com.kuxuan.moneynote.ui.activitys.eventbus.BugetEvent;
|
|
20
|
+import com.kuxuan.moneynote.utils.DrawableUtil;
|
14
|
21
|
import com.kuxuan.moneynote.utils.JavaFormatUtils;
|
|
22
|
+import com.kuxuan.moneynote.utils.LoginStatusUtil;
|
|
23
|
+import com.kuxuan.moneynote.utils.NetWorkUtil;
|
15
|
24
|
import com.kuxuan.moneynote.utils.SPUtil;
|
|
25
|
+import com.kuxuan.moneynote.utils.ToastUtil;
|
16
|
26
|
|
17
|
27
|
import org.greenrobot.eventbus.EventBus;
|
18
|
28
|
|
19
|
29
|
import butterknife.Bind;
|
20
|
30
|
import butterknife.OnClick;
|
|
31
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
32
|
+import io.reactivex.schedulers.Schedulers;
|
21
|
33
|
|
22
|
34
|
/**
|
23
|
35
|
* Created by xieshengqi on 2018/4/24.
|
|
@@ -47,6 +59,7 @@ public class BudgetSettingActivity extends BaseActivity {
|
47
|
59
|
int num = (int) SPUtil.get(this, Constant.System.BUGET_NUM, Constant.System.NORMAL_NUM);
|
48
|
60
|
numedit.setHint(JavaFormatUtils.formatFloatNumber(num));
|
49
|
61
|
initEdit();
|
|
62
|
+
|
50
|
63
|
}
|
51
|
64
|
|
52
|
65
|
private void initEdit() {
|
|
@@ -64,12 +77,12 @@ public class BudgetSettingActivity extends BaseActivity {
|
64
|
77
|
@Override
|
65
|
78
|
public void afterTextChanged(Editable editable) {
|
66
|
79
|
if (editable.length() != 0 && numedit.getText().length() != 0) {
|
67
|
|
- completeBtn.setBackground(getResources().getDrawable(R.drawable.bg_orange_btn));
|
68
|
|
- completeBtn.setTextColor(getResources().getColor(R.color.black));
|
|
80
|
+ completeBtn.setBackground(DrawableUtil.getShape(BudgetSettingActivity.this));
|
|
81
|
+ completeBtn.setTextColor(getResources().getColor(R.color.white));
|
69
|
82
|
completeBtn.setEnabled(true);
|
70
|
83
|
} else {
|
71
|
84
|
completeBtn.setBackground(getResources().getDrawable(R.drawable.bg_gray_btn));
|
72
|
|
- completeBtn.setTextColor(getResources().getColor(R.color.gray_text));
|
|
85
|
+ completeBtn.setTextColor(getResources().getColor(R.color.white));
|
73
|
86
|
completeBtn.setEnabled(false);
|
74
|
87
|
}
|
75
|
88
|
}
|
|
@@ -78,11 +91,48 @@ public class BudgetSettingActivity extends BaseActivity {
|
78
|
91
|
|
79
|
92
|
@OnClick(R.id.activity_bugetsetting_complete_btn)
|
80
|
93
|
public void onViewClicked() {
|
81
|
|
-
|
82
|
94
|
String string = numedit.getText().toString();
|
83
|
|
- int i = Integer.parseInt(string);
|
84
|
|
- SPUtil.putAndApply(this, Constant.System.BUGET_NUM, i);
|
85
|
|
- EventBus.getDefault().post(new BugetEvent());
|
86
|
|
- finish();
|
|
95
|
+ int da = Integer.parseInt(string);
|
|
96
|
+ if (da == 0) {
|
|
97
|
+ ToastUtil.show(this, "预算金额必须大于0");
|
|
98
|
+ return;
|
|
99
|
+ }
|
|
100
|
+ if (!NetWorkUtil.isNetworkAvailable(this)) {
|
|
101
|
+ ToastUtil.show(this, getResources().getString(R.string.nonetwork));
|
|
102
|
+ return;
|
|
103
|
+ }
|
|
104
|
+ setData(string);
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+ private void setData(final String data) {
|
|
109
|
+ RetrofitClient.getApiService().setBudgetData(data).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new MyObsever<BaseJson<Object>>() {
|
|
110
|
+ @Override
|
|
111
|
+ public void onError(ExceptionHandle.ResponeThrowable e) {
|
|
112
|
+ ToastUtil.show(BudgetSettingActivity.this, "设置失败");
|
|
113
|
+ }
|
|
114
|
+
|
|
115
|
+ @Override
|
|
116
|
+ public void onSuccess(BaseJson<Object> objectBaseJson) {
|
|
117
|
+ if (objectBaseJson != null) {
|
|
118
|
+ if (objectBaseJson.getCode() == 0) {
|
|
119
|
+ int i = Integer.parseInt(data);
|
|
120
|
+ MineJson userInfo = LoginStatusUtil.getUserInfo();
|
|
121
|
+ if (userInfo != null) {
|
|
122
|
+ userInfo.setMonth_budget(data);
|
|
123
|
+ LoginStatusUtil.setUserInfo(userInfo);
|
|
124
|
+ }
|
|
125
|
+ if (i != 0)
|
|
126
|
+ SPUtil.putAndApply(MyApplication.getInstance(), Constant.System.BUGET_NUM, i);
|
|
127
|
+ EventBus.getDefault().post(new BugetEvent());
|
|
128
|
+ finish();
|
|
129
|
+ } else {
|
|
130
|
+ ToastUtil.show(BudgetSettingActivity.this, objectBaseJson.getMessage().get(0));
|
|
131
|
+ }
|
|
132
|
+ } else {
|
|
133
|
+ ToastUtil.show(BudgetSettingActivity.this, "设置失败");
|
|
134
|
+ }
|
|
135
|
+ }
|
|
136
|
+ });
|
87
|
137
|
}
|
88
|
138
|
}
|