3 Commits cb39a58f3a ... 343650b1bf

Author SHA1 Message Date
  e 343650b1bf 提交数据库 6 years ago
  e d408befb3e Merge branch 'MoneyNote3.0' of http://git.quyaqu.com/xieshengqi/MoneyMoreMoreNote into MoneyNote3.0 6 years ago
  e 9b81e05bc0 提交数据库 6 years ago

+ 94 - 1
app/src/main/java/com/kuxuan/moneynote/db/CategoryDaoOperator.java

@@ -2,9 +2,11 @@ package com.kuxuan.moneynote.db;
2 2
 
3 3
 import com.kuxuan.moneynote.MyApplication;
4 4
 import com.kuxuan.moneynote.common.Constant;
5
+import com.kuxuan.moneynote.json.BillJsonList;
5 6
 import com.kuxuan.moneynote.json.TimeJson;
6 7
 import com.kuxuan.moneynote.utils.LoginStatusUtil;
7 8
 import com.kuxuan.moneynote.utils.SPUtil;
9
+import com.kuxuan.moneynote.utils.TextSetUtil;
8 10
 import com.kuxuan.moneynote.utils.TimeUtlis;
9 11
 import com.kuxuan.sqlite.dao.CategoryDBDao;
10 12
 import com.kuxuan.sqlite.db.CategoryDB;
@@ -312,7 +314,28 @@ public class CategoryDaoOperator {
312 314
 
313 315
 
314 316
     /**
315
-     * 获取一个月的数据
317
+     * 获取某年某月支出或者收入的数据
318
+     * @param year
319
+     * @param month
320
+     * @param type
321
+     * @return
322
+     */
323
+    public ArrayList<CategoryDB> getMonthData(int year,int month,int type){
324
+
325
+        CategoryDBDao categoryDBDao = DbManager.getInstance().getmDaoSession().getCategoryDBDao();
326
+        ArrayList<CategoryDB> list = null;
327
+
328
+        try {
329
+            list = (ArrayList<CategoryDB>) categoryDBDao.queryBuilder().where(CategoryDBDao.Properties.Year.eq(year),CategoryDBDao.Properties.Month.eq(month),CategoryDBDao.Properties.Type.eq(type),CategoryDBDao.Properties.User_id.eq(LoginStatusUtil.getLoginUserId())).list();
330
+        } catch (Exception e) {
331
+        }
332
+
333
+        return list;
334
+    }
335
+
336
+
337
+    /**
338
+     * 获取某个类别的一个月的数据
316 339
      *
317 340
      * @param year
318 341
      * @param month
@@ -330,6 +353,76 @@ public class CategoryDaoOperator {
330 353
         return (ArrayList<CategoryDB>) list;
331 354
     }
332 355
 
356
+    public BillJsonList getMonthData(int year,int month){
357
+
358
+        BillJsonList billJsonList = null;
359
+
360
+        CategoryDaoOperator categoryDaoOperator  = CategoryDaoOperator.newInstance();
361
+
362
+        //收入 type ==1
363
+        ArrayList<CategoryDB> categoryDBArrayList_Income = categoryDaoOperator.getMonthData(year,month,1);
364
+
365
+        double income = 0;
366
+
367
+        for (int i =0 ;i < categoryDBArrayList_Income.size();i++){
368
+
369
+            income = income + categoryDBArrayList_Income.get(i).getAccount();
370
+
371
+        }
372
+
373
+        ArrayList<CategoryDB> categoryDBArrayList_expenditure = categoryDaoOperator.getMonthData(year,month,2);
374
+
375
+        double expenditure = 0;
376
+
377
+        for (int i =0 ;i < categoryDBArrayList_expenditure.size();i++){
378
+
379
+            expenditure = expenditure + categoryDBArrayList_expenditure.get(i).getAccount();
380
+
381
+        }
382
+
383
+        double surplus = 0;
384
+
385
+        surplus = income - expenditure;
386
+
387
+
388
+        String incomeStr = TextSetUtil.formatFloatNumber(income);
389
+        String expenditureStr = TextSetUtil.formatFloatNumber(expenditure);
390
+        String surplusStr = TextSetUtil.formatFloatNumber(surplus);
391
+
392
+
393
+        return new BillJsonList(incomeStr,expenditureStr,surplusStr,month+"");
394
+    }
395
+
396
+
397
+    /**
398
+     * 获取某年的支出或者收入的数据
399
+     * @param year
400
+     * @param type
401
+     * @return
402
+     */
403
+    public ArrayList<CategoryDB> getYearData(int year,int type){
404
+
405
+        CategoryDBDao categoryDBDao = DbManager.getInstance().getmDaoSession().getCategoryDBDao();
406
+
407
+        ArrayList<CategoryDB> list = null;
408
+
409
+        try{
410
+          list = (ArrayList<CategoryDB>) categoryDBDao.queryBuilder().where(CategoryDBDao.Properties.Year.eq(year),CategoryDBDao.Properties.Type.eq(type),CategoryDBDao.Properties.User_id.eq(LoginStatusUtil.getLoginUserId())).list();
411
+        }catch (Exception e){
412
+
413
+        }
414
+
415
+        return list;
416
+    }
417
+
418
+
419
+    /**
420
+     * 获取某个类别的一年月的数据
421
+     * @param year
422
+     * @param type
423
+     * @param category_id
424
+     * @return
425
+     */
333 426
     public ArrayList<CategoryDB> getYearData(int year, int type, int category_id) {
334 427
         CategoryDBDao categoryDBDao = DbManager.getInstance().getmDaoSession().getCategoryDBDao();
335 428
         List<CategoryDB> list = null;

+ 3 - 0
app/src/main/java/com/kuxuan/moneynote/json/BillJsonList.java

@@ -21,6 +21,9 @@ public class BillJsonList {
21 21
         this.month = month;
22 22
     }
23 23
 
24
+    public BillJsonList(){}
25
+
26
+
24 27
     public String getIncome() {
25 28
         return income;
26 29
     }

+ 12 - 4
app/src/main/java/com/kuxuan/moneynote/ui/activitys/bill/BillActivity.java

@@ -36,6 +36,7 @@ public class BillActivity extends MVPFragmentActivity<BillPresenter, BillModel>
36 36
     TextView mPayText;
37 37
     Calendar cal;
38 38
     int year;
39
+    private int finalyear;
39 40
     private static final String TAG = "BillActivity";
40 41
     @Override
41 42
     public void showProgress() {
@@ -63,7 +64,7 @@ public class BillActivity extends MVPFragmentActivity<BillPresenter, BillModel>
63 64
         TextSetUtil.setTextForMoey("0",mPayText);
64 65
         cal = Calendar.getInstance();
65 66
         year = cal.get(Calendar.YEAR);
66
-
67
+        finalyear = cal.get(Calendar.YEAR);
67 68
         final Drawable drawable = ContextCompat.getDrawable(this,R.mipmap.pull_down_selector_normal);
68 69
         //设置title
69 70
         getTitleView(1).setTitle(getResources().getString(R.string.bill)).
@@ -102,10 +103,11 @@ public class BillActivity extends MVPFragmentActivity<BillPresenter, BillModel>
102 103
                         PickerUtil.onYearPicker(BillActivity.this, new NumberPicker.OnNumberPickListener() {
103 104
                             @Override
104 105
                             public void onNumberPicked(int i, Number number) {
105
-                                if (number.intValue()<=year) {
106
-                                    mPresenter.getBillData(number.intValue());
106
+                                if (number.intValue()<=finalyear) {
107
+//                                    mPresenter.getBillData(number.intValue());
107 108
                                     getTitleView(1).setRight_text(number.intValue()+"");
108 109
                                     year = number.intValue();
110
+                                    setOfflineBillData();
109 111
                                 }else{
110 112
                                     Toast.makeText(BillActivity.this, "您选择的年不能大于当前年", Toast.LENGTH_SHORT).show();
111 113
                                 }
@@ -113,9 +115,15 @@ public class BillActivity extends MVPFragmentActivity<BillPresenter, BillModel>
113 115
                         },year);
114 116
                     }
115 117
                 });
116
-        mPresenter.getBillData(year);
118
+//        mPresenter.getBillData(year);
117 119
         mPresenter.initRecyclerView(this, mRecyclerView);
120
+        setOfflineBillData();
121
+
122
+    }
123
+
124
+    private void setOfflineBillData() {
118 125
 
126
+        mPresenter.getOfflineData(year);
119 127
 
120 128
     }
121 129
 

+ 2 - 0
app/src/main/java/com/kuxuan/moneynote/ui/activitys/bill/BillContract.java

@@ -48,6 +48,8 @@ public interface BillContract {
48 48
         abstract void addData(Time time);
49 49
         abstract void getBillData(int year);
50 50
 
51
+        abstract void getOfflineData(int year);
52
+
51 53
     }
52 54
 
53 55
 }

+ 28 - 0
app/src/main/java/com/kuxuan/moneynote/ui/activitys/bill/BillPresenter.java

@@ -6,6 +6,7 @@ import android.support.v7.widget.RecyclerView;
6 6
 import android.util.Log;
7 7
 
8 8
 import com.kuxuan.moneynote.R;
9
+import com.kuxuan.moneynote.db.CategoryDaoOperator;
9 10
 import com.kuxuan.moneynote.json.BillJson;
10 11
 import com.kuxuan.moneynote.json.BillJsonList;
11 12
 import com.kuxuan.moneynote.json.Time;
@@ -81,4 +82,31 @@ public class BillPresenter extends BillContract.BillPresent {
81 82
             }
82 83
         },String.valueOf(year));
83 84
     }
85
+
86
+    @Override
87
+    void getOfflineData(int year) {
88
+
89
+        Calendar cal = Calendar.getInstance();
90
+        int Current_year = cal.get(Calendar.YEAR);
91
+        int Current_month = cal.get(Calendar.MONTH)+1;
92
+
93
+        int monthCount = 12;
94
+
95
+        if(year == Current_year){
96
+            monthCount = Current_month;
97
+        }
98
+
99
+        CategoryDaoOperator categoryDaoOperator  = CategoryDaoOperator.newInstance();
100
+
101
+        List<BillJsonList> billJsonLists=new ArrayList<>();
102
+
103
+        for (int i=1;i<=monthCount;i++){
104
+
105
+            BillJsonList billJsonList = categoryDaoOperator.getMonthData(year,i);
106
+            billJsonLists.add(billJsonList);
107
+
108
+        }
109
+        mAdapter.setNewData(billJsonLists);
110
+
111
+    }
84 112
 }

+ 66 - 17
app/src/main/java/com/kuxuan/moneynote/ui/fragments/mine/MineFragment.java

@@ -11,6 +11,7 @@ import com.kuxuan.moneynote.R;
11 11
 import com.kuxuan.moneynote.base.BaseFragmentActivity;
12 12
 import com.kuxuan.moneynote.base.mvpbase.MVPFragment;
13 13
 import com.kuxuan.moneynote.common.Constant;
14
+import com.kuxuan.moneynote.db.CategoryDaoOperator;
14 15
 import com.kuxuan.moneynote.json.BillJson;
15 16
 import com.kuxuan.moneynote.json.HeadImg;
16 17
 import com.kuxuan.moneynote.json.MineJson;
@@ -30,6 +31,7 @@ import com.kuxuan.moneynote.utils.LoginStatusUtil;
30 31
 import com.kuxuan.moneynote.utils.SPUtil;
31 32
 import com.kuxuan.moneynote.utils.TextSetUtil;
32 33
 import com.kuxuan.moneynote.utils.UIHelper;
34
+import com.kuxuan.sqlite.db.CategoryDB;
33 35
 import com.umeng.socialize.ShareAction;
34 36
 import com.umeng.socialize.UMShareListener;
35 37
 import com.umeng.socialize.bean.SHARE_MEDIA;
@@ -45,6 +47,7 @@ import org.greenrobot.eventbus.Subscribe;
45 47
 import org.greenrobot.eventbus.ThreadMode;
46 48
 
47 49
 import java.lang.ref.WeakReference;
50
+import java.util.ArrayList;
48 51
 import java.util.Calendar;
49 52
 
50 53
 import butterknife.Bind;
@@ -198,7 +201,7 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
198 201
         TextSetUtil.setTextForMonth(month, monthTv);
199 202
         if(LoginStatusUtil.isLoginin()){
200 203
             mPresenter.getMineData();
201
-            mPresenter.getMineBill(year);
204
+//            mPresenter.getMineBill(year);
202 205
         }
203 206
         mShareAction = new ShareAction(getActivity()).setDisplayList(
204 207
                 SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE).setShareboardclickCallback(new ShareBoardlistener() {
@@ -214,9 +217,52 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
214 217
             }
215 218
         });
216 219
 
217
-        TextSetUtil.setTextForMoey("0.00", incomeText, 16, 12);
218
-        TextSetUtil.setTextForMoey("0.00", payText, 16, 12);
219
-        TextSetUtil.setTextForMoey("0.00", balanceText, 16, 12);
220
+//        TextSetUtil.setTextForMoey("0.00", incomeText, 16, 12);
221
+//        TextSetUtil.setTextForMoey("0.00", payText, 16, 12);
222
+//        TextSetUtil.setTextForMoey("0.00", balanceText, 16, 12);
223
+
224
+        setBillData();
225
+
226
+
227
+    }
228
+
229
+    private void setBillData() {
230
+
231
+       CategoryDaoOperator categoryDaoOperator  = CategoryDaoOperator.newInstance();
232
+
233
+       //收入 type ==1
234
+        ArrayList<CategoryDB> categoryDBArrayList_Income = categoryDaoOperator.getMonthData(Integer.parseInt(year),Integer.parseInt(month),1);
235
+
236
+        double income = 0;
237
+
238
+        for (int i =0 ;i < categoryDBArrayList_Income.size();i++){
239
+
240
+            income = income + categoryDBArrayList_Income.get(i).getAccount();
241
+
242
+        }
243
+
244
+
245
+        ArrayList<CategoryDB> categoryDBArrayList_expenditure = categoryDaoOperator.getMonthData(Integer.parseInt(year),Integer.parseInt(month),2);
246
+
247
+        double expenditure = 0;
248
+
249
+        for (int i =0 ;i < categoryDBArrayList_expenditure.size();i++){
250
+
251
+            expenditure = expenditure + categoryDBArrayList_expenditure.get(i).getAccount();
252
+
253
+        }
254
+
255
+        double surplus = 0;
256
+
257
+        surplus = income - expenditure;
258
+
259
+        String incomeStr = TextSetUtil.formatFloatNumber(income);
260
+        String expenditureStr = TextSetUtil.formatFloatNumber(expenditure);
261
+        String surplusStr = TextSetUtil.formatFloatNumber(surplus);
262
+
263
+        TextSetUtil.setTextForMoey(incomeStr, incomeText, 16, 12);
264
+        TextSetUtil.setTextForMoey(expenditureStr, payText, 16, 12);
265
+        TextSetUtil.setTextForMoey(surplusStr, balanceText, 16, 12);
220 266
 
221 267
     }
222 268
 
@@ -254,7 +300,8 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
254 300
         if(LoginStatusUtil.isLoginin()){
255 301
             newUser = loginEvent.isNewUser();
256 302
             mPresenter.getMineData();
257
-            mPresenter.getMineBill(year);
303
+//            mPresenter.getMineBill(year);
304
+            setBillData();
258 305
         }
259 306
 
260 307
     }
@@ -286,13 +333,16 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
286 333
     public void onMessageEvent(RefreshEvent loginEvent) {
287 334
 
288 335
         mPresenter.getMineData();
289
-        mPresenter.getMineBill(year);
336
+//        mPresenter.getMineBill(year);
337
+
338
+        setBillData();
339
+
290 340
     }
291 341
 
292 342
 
293 343
 
294 344
     /**
295
-     * add账单之后刷新数据
345
+     * 退出
296 346
      *
297 347
      * @param loginOutEvent
298 348
      */
@@ -304,9 +354,9 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
304 354
             if(mNameText!=null){
305 355
                 mNameText.setText("未登录");
306 356
                 mPortraitImage.setImageResource(R.drawable.im_portrait);
307
-                TextSetUtil.setTextForMoey("0.00", incomeText, 16, 12);
308
-                TextSetUtil.setTextForMoey("0.00 ", payText, 16, 12);
309
-                TextSetUtil.setTextForMoey("0.00", balanceText, 16, 12);
357
+//                TextSetUtil.setTextForMoey("0.00", incomeText, 16, 12);
358
+//                TextSetUtil.setTextForMoey("0.00 ", payText, 16, 12);
359
+//                TextSetUtil.setTextForMoey("0.00", balanceText, 16, 12);
310 360
             }
311 361
 
312 362
         }
@@ -389,10 +439,9 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
389 439
             }
390 440
         }
391 441
 
392
-
393
-        TextSetUtil.setTextForMoey("0.00", incomeText, 16, 12);
394
-        TextSetUtil.setTextForMoey("0.00 ", payText, 16, 12);
395
-        TextSetUtil.setTextForMoey("0.00", balanceText, 16, 12);
442
+//        TextSetUtil.setTextForMoey("0.00", incomeText, 16, 12);
443
+//        TextSetUtil.setTextForMoey("0.00 ", payText, 16, 12);
444
+//        TextSetUtil.setTextForMoey("0.00", balanceText, 16, 12);
396 445
 
397 446
 
398 447
     }
@@ -403,9 +452,9 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
403 452
             if(mNameText!=null){
404 453
                 mNameText.setText("未登录");
405 454
                 mPortraitImage.setImageResource(R.drawable.im_portrait);
406
-                TextSetUtil.setTextForMoey("0.00", incomeText, 16, 12);
407
-                TextSetUtil.setTextForMoey("0.00 ", payText, 16, 12);
408
-                TextSetUtil.setTextForMoey("0.00", balanceText, 16, 12);
455
+//                TextSetUtil.setTextForMoey("0.00", incomeText, 16, 12);
456
+//                TextSetUtil.setTextForMoey("0.00 ", payText, 16, 12);
457
+//                TextSetUtil.setTextForMoey("0.00", balanceText, 16, 12);
409 458
             }
410 459
 
411 460
         }

+ 19 - 2
app/src/main/java/com/kuxuan/moneynote/utils/TextSetUtil.java

@@ -69,9 +69,9 @@ public class TextSetUtil {
69 69
      */
70 70
     public static void setTextForMoey(String text, TextView textView,int s1,int s2) {
71 71
         String[] split = null;
72
-        String replace = text.replace("-", "");
72
+//        String replace = text.replace("-", "");
73 73
         try {
74
-            split = replace.split("\\.");
74
+            split = text.split("\\.");
75 75
             TextParser textParser = new TextParser();
76 76
             textParser.append(split[0], DisplayUtil.dip2px(s1), Color.BLACK);
77 77
             textParser.append("." + split[1], DisplayUtil.dip2px(s2), Color.parseColor("#262626"));
@@ -86,4 +86,21 @@ public class TextSetUtil {
86 86
             textParser.parse(textView);
87 87
         }
88 88
     }
89
+
90
+
91
+    /**
92
+     * 当浮点型数据位数超过10位之后,数据变成科学计数法显示。用此方法可以使其正常显示。
93
+     * @param value
94
+     * @return Sting
95
+     */
96
+    public static String formatFloatNumber(double value) {
97
+        if(value != 0.00){
98
+            java.text.DecimalFormat df = new java.text.DecimalFormat("########.00");
99
+            return df.format(value);
100
+        }else{
101
+            return "0.00";
102
+        }
103
+
104
+    }
105
+
89 106
 }

+ 0 - 3
app/src/main/res/layout/activity_bill.xml

@@ -19,7 +19,6 @@
19 19
        android:ellipsize="end"
20 20
        android:maxLines="1"
21 21
        android:layout_height="wrap_content"
22
-       android:text="11111.0000"
23 22
        />
24 23
 
25 24
     <LinearLayout
@@ -46,7 +45,6 @@
46 45
             android:id="@+id/income_text"
47 46
             android:ellipsize="end"
48 47
             android:maxLines="1"
49
-            android:text="5000.00"
50 48
             />
51 49
         </LinearLayout>
52 50
         <View
@@ -73,7 +71,6 @@
73 71
             android:ellipsize="end"
74 72
             android:maxLines="1"
75 73
             android:layout_height="wrap_content"
76
-            android:text="7710.00"
77 74
             />
78 75
      </LinearLayout>
79 76
     </LinearLayout>