Xieshengqi 6 年 前
コミット
ebe150f018

+ 9 - 0
app/src/main/java/com/kuxuan/moneynote/api/ApiService.java

@@ -407,6 +407,15 @@ public interface ApiService {
407 407
     @POST("upData")
408 408
     Observable<BaseJson<Object>> upData(@Body UpDataBody dataBody);
409 409
 
410
+
411
+    /**
412
+     * 设置预算
413
+     * @param month_budget
414
+     * @return
415
+     */
416
+    @POST("setMonthBudget")
417
+    Observable<BaseJson<Object>> setBudgetData(@Query("month_budget")String month_budget);
418
+
410 419
 }
411 420
 
412 421
 

+ 10 - 0
app/src/main/java/com/kuxuan/moneynote/json/MineJson.java

@@ -17,6 +17,16 @@ public class MineJson {
17 17
     private String nickname;
18 18
     private String headimgurl;
19 19
     private String android_share_url;
20
+    private String month_budget;
21
+
22
+
23
+    public String getMonth_budget() {
24
+        return month_budget;
25
+    }
26
+
27
+    public void setMonth_budget(String month_budget) {
28
+        this.month_budget = month_budget;
29
+    }
20 30
 
21 31
     public String getAndroid_share_url() {
22 32
         return android_share_url;

+ 54 - 4
app/src/main/java/com/kuxuan/moneynote/ui/activitys/budget/BudgetActivity.java

@@ -7,17 +7,28 @@ import android.widget.ImageView;
7 7
 import android.widget.RelativeLayout;
8 8
 import android.widget.TextView;
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.LoginStatusUtil;
21
+import com.kuxuan.moneynote.utils.NetWorkUtil;
14 22
 import com.kuxuan.moneynote.utils.SPUtil;
23
+import com.kuxuan.moneynote.utils.ToastUtil;
15 24
 
16 25
 import org.greenrobot.eventbus.EventBus;
17 26
 import org.greenrobot.eventbus.Subscribe;
18 27
 import org.greenrobot.eventbus.ThreadMode;
19 28
 
20 29
 import butterknife.Bind;
30
+import io.reactivex.android.schedulers.AndroidSchedulers;
31
+import io.reactivex.schedulers.Schedulers;
21 32
 
22 33
 /**
23 34
  * 预算设置
@@ -54,14 +65,18 @@ public class BudgetActivity extends BaseActivity {
54 65
         imageView.setOnClickListener(new View.OnClickListener() {
55 66
             @Override
56 67
             public void onClick(View view) {
68
+                if(!NetWorkUtil.isNetworkAvailable(BudgetActivity.this)){
69
+                    ToastUtil.show(BudgetActivity.this,getResources().getString(R.string.nonetwork));
70
+                   return;
71
+                }
57 72
                 boolean isOpne = (boolean) SPUtil.get(BudgetActivity.this, Constant.System.SWITCH, false);
58 73
                 if (isOpne) {
59
-                    SPUtil.putAndApply(BudgetActivity.this, Constant.System.SWITCH, false);
74
+                    setData("0", isOpne);
60 75
                 } else {
61
-                    SPUtil.putAndApply(BudgetActivity.this, Constant.System.SWITCH, true);
76
+                    int d = (int) SPUtil.get(BudgetActivity.this, Constant.System.BUGET_NUM, Constant.System.NORMAL_NUM);
77
+                    setData(d + "", isOpne);
62 78
                 }
63
-                EventBus.getDefault().post(new BugetEvent());
64
-                finish();
79
+
65 80
             }
66 81
         });
67 82
         activityBugetGotosettingLayout.setOnClickListener(new View.OnClickListener() {
@@ -105,4 +120,39 @@ public class BudgetActivity extends BaseActivity {
105 120
         setData();
106 121
     }
107 122
 
123
+
124
+    private void setData(final String data, final boolean isOpen) {
125
+        RetrofitClient.getApiService().setBudgetData(data).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new MyObsever<BaseJson<Object>>() {
126
+            @Override
127
+            public void onError(ExceptionHandle.ResponeThrowable e) {
128
+            }
129
+
130
+            @Override
131
+            public void onSuccess(BaseJson<Object> objectBaseJson) {
132
+                if (objectBaseJson != null) {
133
+                    if (objectBaseJson.getCode() == 0) {
134
+                        int i = Integer.parseInt(data);
135
+                        SPUtil.putAndApply(MyApplication.getInstance(), Constant.System.BUGET_NUM, i);
136
+                        MineJson userInfo = LoginStatusUtil.getUserInfo();
137
+                        if(userInfo!=null){
138
+                            userInfo.setMonth_budget(data);
139
+                            LoginStatusUtil.setUserInfo(userInfo);
140
+                        }
141
+                        if (isOpen) {
142
+                            SPUtil.putAndApply(BudgetActivity.this, Constant.System.SWITCH, false);
143
+
144
+
145
+                        } else {
146
+                            SPUtil.putAndApply(BudgetActivity.this, Constant.System.SWITCH, true);
147
+                        }
148
+                        EventBus.getDefault().post(new BugetEvent());
149
+                        finish();
150
+                    } else {
151
+                    }
152
+                } else {
153
+
154
+                }
155
+            }
156
+        });
157
+    }
108 158
 }

+ 58 - 8
app/src/main/java/com/kuxuan/moneynote/ui/activitys/budget/BudgetSettingActivity.java

@@ -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
 }

+ 1 - 1
app/src/main/java/com/kuxuan/moneynote/ui/activitys/category/CategoryPresent.java

@@ -84,7 +84,7 @@ public class CategoryPresent extends CategoryContract.CategoryPresent {
84 84
 
85 85
             @Override
86 86
             public void onFail(String msg) {
87
-
87
+view.hideProgress();
88 88
             }
89 89
         }, type);
90 90
     }

+ 5 - 4
app/src/main/java/com/kuxuan/moneynote/ui/fragments/details/DetialFragment.java

@@ -304,12 +304,13 @@ public class DetialFragment extends MVPFragment<DetialPresent, DetialModel> impl
304 304
         currentOutMoney = Double.parseDouble(outMoey);
305 305
         TextSetUtil.setTextForMoey(JavaFormatUtils.formatFloatNumber(currentInmoney), fragmentDetialMoneyin);
306 306
         TextSetUtil.setTextForMoey(JavaFormatUtils.formatFloatNumber(currentOutMoney), fragmentDetialMoneyout);
307
-        changeTypeData(currentInmoney, currentOutMoney);
307
+        boolean isOpen = (boolean) SPUtil.get(getActivity(), Constant.System.SWITCH, false);
308
+            changeTypeData(currentInmoney, currentOutMoney);
308 309
     }
309 310
 
310 311
     private void changeTypeData(Double inMoney, Double outMoney) {
311 312
         boolean isOpen = (boolean) SPUtil.get(getActivity(), Constant.System.SWITCH, false);
312
-        Integer date = (Integer) SPUtil.get(getActivity(), Constant.System.BUGET_NUM, Constant.System.NORMAL_NUM);
313
+        Integer date = (Integer) SPUtil.get(getActivity(), Constant.System.BUGET_NUM, 0);
313 314
         if (isOpen) {
314 315
             type_text.setText("预算结余");
315 316
             TextSetUtil.setTextForBigSize(JavaFormatUtils.formatFloatNumber(date - outMoney), allMoney_text);
@@ -476,8 +477,8 @@ public class DetialFragment extends MVPFragment<DetialPresent, DetialModel> impl
476 477
                     //选中的时候存储颜色
477 478
 //                    SPUtil.putAndApply(getContext(), Constant.Skin.COLOR_SELECT, "#FF4081" );
478 479
                     String color1 = item.getColor();
479
-                    color1 =  color1.substring(2,8);
480
-                    Log.e("字符数",color1.length()+"");
480
+                    color1 = color1.substring(2, 8);
481
+                    Log.e("字符数", color1.length() + "");
481 482
                     SPUtil.putAndApply(MyApplication.getInstance(), Constant.Skin.COLOR_SELECT, color1);
482 483
 
483 484
                     EventBus.getDefault().post(new SkinEvent(mskinBean.getCode()));

+ 31 - 13
app/src/main/java/com/kuxuan/moneynote/ui/fragments/mine/MineFragment.java

@@ -25,6 +25,7 @@ import com.kuxuan.moneynote.ui.activitys.bill.BillActivity;
25 25
 import com.kuxuan.moneynote.ui.activitys.bindphone.BindThirdActivity;
26 26
 import com.kuxuan.moneynote.ui.activitys.budget.BudgetActivity;
27 27
 import com.kuxuan.moneynote.ui.activitys.category.CategoryActivity;
28
+import com.kuxuan.moneynote.ui.activitys.eventbus.BugetEvent;
28 29
 import com.kuxuan.moneynote.ui.activitys.eventbus.LoginEvent;
29 30
 import com.kuxuan.moneynote.ui.activitys.eventbus.LoginOutEvent;
30 31
 import com.kuxuan.moneynote.ui.activitys.eventbus.NetworkEvent;
@@ -215,13 +216,12 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
215 216
     public void initView() {
216 217
         EventBus.getDefault().register(this);
217 218
 
218
-         int position = (int) SPUtil.get(getContext(),Constant.Skin.CHECKED,-1);
219
-         if(position>-1){
220
-             String fileheader = MyApplication.getInstance().getApplicationContext().getFilesDir().getPath()+"/"+"skin";
221
-             File file = new File(fileheader + Constant.Skin.MINE+position+".png");
222
-             GlideUtil.setImageWithNoCache(getContext(),file,iv_mineskin);
223
-         }
224
-
219
+        int position = (int) SPUtil.get(getContext(), Constant.Skin.CHECKED, -1);
220
+        if (position > -1) {
221
+            String fileheader = MyApplication.getInstance().getApplicationContext().getFilesDir().getPath() + "/" + "skin";
222
+            File file = new File(fileheader + Constant.Skin.MINE + position + ".png");
223
+            GlideUtil.setImageWithNoCache(getContext(), file, iv_mineskin);
224
+        }
225 225
 
226 226
 
227 227
         cal = Calendar.getInstance();
@@ -229,7 +229,7 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
229 229
         mShareListener = new CustomShareListener(getActivity());
230 230
         month = cal.get(Calendar.MONTH) + 1 + "";
231 231
         year = cal.get(Calendar.YEAR) + "";
232
-        TextSetUtil.setTextForMonth(month+"月", monthTv, Color.BLACK);
232
+        TextSetUtil.setTextForMonth(month + "月", monthTv, Color.BLACK);
233 233
         if (LoginStatusUtil.isLoginin()) {
234 234
             MineJson userInfo = LoginStatusUtil.getUserInfo();
235 235
             if (userInfo == null) {
@@ -440,12 +440,13 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
440 440
 
441 441
     @Bind(R.id.iv_mineskin)
442 442
     ImageView iv_mineskin;
443
+
443 444
     @Subscribe(threadMode = ThreadMode.MAIN)
444
-    public void onMessageEvent5(SkinEvent skinBean){
445
+    public void onMessageEvent5(SkinEvent skinBean) {
445 446
 
446
-        String fileheader = MyApplication.getInstance().getApplicationContext().getFilesDir().getPath()+"/"+"skin";
447
-        File file = new File(fileheader + Constant.Skin.MINE+skinBean.getCode()+".png");
448
-        GlideUtil.setImageWithNoCache(getContext(),file,iv_mineskin);
447
+        String fileheader = MyApplication.getInstance().getApplicationContext().getFilesDir().getPath() + "/" + "skin";
448
+        File file = new File(fileheader + Constant.Skin.MINE + skinBean.getCode() + ".png");
449
+        GlideUtil.setImageWithNoCache(getContext(), file, iv_mineskin);
449 450
 
450 451
     }
451 452
 
@@ -491,7 +492,6 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
491 492
         }
492 493
 
493 494
         if (mineModel.getAvatar() == null && mineModel.getHeadimgurl() == null) {
494
-            return;
495 495
         } else {
496 496
             if (mineModel.getAvatar() == null) {
497 497
                 Glide.with(this).load(mineModel.getHeadimgurl())
@@ -529,6 +529,24 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
529 529
         }
530 530
         aaaa = mineModel.getAndroid_share_url();
531 531
 
532
+
533
+        //预算设置
534
+        String month_budget = mineModel.getMonth_budget();
535
+        int budget = 0;
536
+        try {
537
+            budget = (int) Double.parseDouble(month_budget);
538
+
539
+        } catch (Exception e) {
540
+
541
+        }
542
+        if (budget == 0) {
543
+            SPUtil.putAndApply(MyApplication.getInstance(), Constant.System.SWITCH, false);
544
+            SPUtil.putAndApply(MyApplication.getInstance(), Constant.System.BUGET_NUM, Constant.System.NORMAL_NUM);
545
+        } else {
546
+            SPUtil.putAndApply(MyApplication.getInstance(), Constant.System.SWITCH, true);
547
+            SPUtil.putAndApply(MyApplication.getInstance(), Constant.System.BUGET_NUM, budget);
548
+        }
549
+        EventBus.getDefault().post(new BugetEvent());
532 550
     }
533 551
 
534 552
     @Override

+ 4 - 2
app/src/main/java/com/kuxuan/moneynote/utils/LoginStatusUtil.java

@@ -46,8 +46,10 @@ public class LoginStatusUtil {
46 46
         SPUtil.putAndApply(MyApplication.getInstance(), Constant.Time.TOKEN_FAIL, 0L);
47 47
         SPUtil.putAndApply(MyApplication.getInstance(), Constant.UserInfo.USER_ID, -1);
48 48
         SPUtil.putAndApply(MyApplication.getInstance(), Constant.UserInfo.USER_INFO, "");
49
-        //初始下载数据位
50
-        SPUtil.putAndApply(MyApplication.getInstance(), Constant.DbInfo.DB_DOWNLOAD_INDEX, 0);
49
+//预算初始化
50
+        SPUtil.putAndApply(MyApplication.getInstance(), Constant.System.SWITCH, false);
51
+        SPUtil.putAndApply(MyApplication.getInstance(), Constant.System.BUGET_NUM, Constant.System.NORMAL_NUM);
52
+
51 53
     }
52 54
 
53 55