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
 
2
 
3
 import com.kuxuan.moneynote.MyApplication;
3
 import com.kuxuan.moneynote.MyApplication;
4
 import com.kuxuan.moneynote.common.Constant;
4
 import com.kuxuan.moneynote.common.Constant;
5
+import com.kuxuan.moneynote.json.BillJsonList;
5
 import com.kuxuan.moneynote.json.TimeJson;
6
 import com.kuxuan.moneynote.json.TimeJson;
6
 import com.kuxuan.moneynote.utils.LoginStatusUtil;
7
 import com.kuxuan.moneynote.utils.LoginStatusUtil;
7
 import com.kuxuan.moneynote.utils.SPUtil;
8
 import com.kuxuan.moneynote.utils.SPUtil;
9
+import com.kuxuan.moneynote.utils.TextSetUtil;
8
 import com.kuxuan.moneynote.utils.TimeUtlis;
10
 import com.kuxuan.moneynote.utils.TimeUtlis;
9
 import com.kuxuan.sqlite.dao.CategoryDBDao;
11
 import com.kuxuan.sqlite.dao.CategoryDBDao;
10
 import com.kuxuan.sqlite.db.CategoryDB;
12
 import com.kuxuan.sqlite.db.CategoryDB;
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
      * @param year
340
      * @param year
318
      * @param month
341
      * @param month
330
         return (ArrayList<CategoryDB>) list;
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
     public ArrayList<CategoryDB> getYearData(int year, int type, int category_id) {
426
     public ArrayList<CategoryDB> getYearData(int year, int type, int category_id) {
334
         CategoryDBDao categoryDBDao = DbManager.getInstance().getmDaoSession().getCategoryDBDao();
427
         CategoryDBDao categoryDBDao = DbManager.getInstance().getmDaoSession().getCategoryDBDao();
335
         List<CategoryDB> list = null;
428
         List<CategoryDB> list = null;

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

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

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

36
     TextView mPayText;
36
     TextView mPayText;
37
     Calendar cal;
37
     Calendar cal;
38
     int year;
38
     int year;
39
+    private int finalyear;
39
     private static final String TAG = "BillActivity";
40
     private static final String TAG = "BillActivity";
40
     @Override
41
     @Override
41
     public void showProgress() {
42
     public void showProgress() {
63
         TextSetUtil.setTextForMoey("0",mPayText);
64
         TextSetUtil.setTextForMoey("0",mPayText);
64
         cal = Calendar.getInstance();
65
         cal = Calendar.getInstance();
65
         year = cal.get(Calendar.YEAR);
66
         year = cal.get(Calendar.YEAR);
66
-
67
+        finalyear = cal.get(Calendar.YEAR);
67
         final Drawable drawable = ContextCompat.getDrawable(this,R.mipmap.pull_down_selector_normal);
68
         final Drawable drawable = ContextCompat.getDrawable(this,R.mipmap.pull_down_selector_normal);
68
         //设置title
69
         //设置title
69
         getTitleView(1).setTitle(getResources().getString(R.string.bill)).
70
         getTitleView(1).setTitle(getResources().getString(R.string.bill)).
102
                         PickerUtil.onYearPicker(BillActivity.this, new NumberPicker.OnNumberPickListener() {
103
                         PickerUtil.onYearPicker(BillActivity.this, new NumberPicker.OnNumberPickListener() {
103
                             @Override
104
                             @Override
104
                             public void onNumberPicked(int i, Number number) {
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
                                     getTitleView(1).setRight_text(number.intValue()+"");
108
                                     getTitleView(1).setRight_text(number.intValue()+"");
108
                                     year = number.intValue();
109
                                     year = number.intValue();
110
+                                    setOfflineBillData();
109
                                 }else{
111
                                 }else{
110
                                     Toast.makeText(BillActivity.this, "您选择的年不能大于当前年", Toast.LENGTH_SHORT).show();
112
                                     Toast.makeText(BillActivity.this, "您选择的年不能大于当前年", Toast.LENGTH_SHORT).show();
111
                                 }
113
                                 }
113
                         },year);
115
                         },year);
114
                     }
116
                     }
115
                 });
117
                 });
116
-        mPresenter.getBillData(year);
118
+//        mPresenter.getBillData(year);
117
         mPresenter.initRecyclerView(this, mRecyclerView);
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
         abstract void addData(Time time);
48
         abstract void addData(Time time);
49
         abstract void getBillData(int year);
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
 import android.util.Log;
6
 import android.util.Log;
7
 
7
 
8
 import com.kuxuan.moneynote.R;
8
 import com.kuxuan.moneynote.R;
9
+import com.kuxuan.moneynote.db.CategoryDaoOperator;
9
 import com.kuxuan.moneynote.json.BillJson;
10
 import com.kuxuan.moneynote.json.BillJson;
10
 import com.kuxuan.moneynote.json.BillJsonList;
11
 import com.kuxuan.moneynote.json.BillJsonList;
11
 import com.kuxuan.moneynote.json.Time;
12
 import com.kuxuan.moneynote.json.Time;
81
             }
82
             }
82
         },String.valueOf(year));
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
 import com.kuxuan.moneynote.base.BaseFragmentActivity;
11
 import com.kuxuan.moneynote.base.BaseFragmentActivity;
12
 import com.kuxuan.moneynote.base.mvpbase.MVPFragment;
12
 import com.kuxuan.moneynote.base.mvpbase.MVPFragment;
13
 import com.kuxuan.moneynote.common.Constant;
13
 import com.kuxuan.moneynote.common.Constant;
14
+import com.kuxuan.moneynote.db.CategoryDaoOperator;
14
 import com.kuxuan.moneynote.json.BillJson;
15
 import com.kuxuan.moneynote.json.BillJson;
15
 import com.kuxuan.moneynote.json.HeadImg;
16
 import com.kuxuan.moneynote.json.HeadImg;
16
 import com.kuxuan.moneynote.json.MineJson;
17
 import com.kuxuan.moneynote.json.MineJson;
30
 import com.kuxuan.moneynote.utils.SPUtil;
31
 import com.kuxuan.moneynote.utils.SPUtil;
31
 import com.kuxuan.moneynote.utils.TextSetUtil;
32
 import com.kuxuan.moneynote.utils.TextSetUtil;
32
 import com.kuxuan.moneynote.utils.UIHelper;
33
 import com.kuxuan.moneynote.utils.UIHelper;
34
+import com.kuxuan.sqlite.db.CategoryDB;
33
 import com.umeng.socialize.ShareAction;
35
 import com.umeng.socialize.ShareAction;
34
 import com.umeng.socialize.UMShareListener;
36
 import com.umeng.socialize.UMShareListener;
35
 import com.umeng.socialize.bean.SHARE_MEDIA;
37
 import com.umeng.socialize.bean.SHARE_MEDIA;
45
 import org.greenrobot.eventbus.ThreadMode;
47
 import org.greenrobot.eventbus.ThreadMode;
46
 
48
 
47
 import java.lang.ref.WeakReference;
49
 import java.lang.ref.WeakReference;
50
+import java.util.ArrayList;
48
 import java.util.Calendar;
51
 import java.util.Calendar;
49
 
52
 
50
 import butterknife.Bind;
53
 import butterknife.Bind;
198
         TextSetUtil.setTextForMonth(month, monthTv);
201
         TextSetUtil.setTextForMonth(month, monthTv);
199
         if(LoginStatusUtil.isLoginin()){
202
         if(LoginStatusUtil.isLoginin()){
200
             mPresenter.getMineData();
203
             mPresenter.getMineData();
201
-            mPresenter.getMineBill(year);
204
+//            mPresenter.getMineBill(year);
202
         }
205
         }
203
         mShareAction = new ShareAction(getActivity()).setDisplayList(
206
         mShareAction = new ShareAction(getActivity()).setDisplayList(
204
                 SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE).setShareboardclickCallback(new ShareBoardlistener() {
207
                 SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE).setShareboardclickCallback(new ShareBoardlistener() {
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
         if(LoginStatusUtil.isLoginin()){
300
         if(LoginStatusUtil.isLoginin()){
255
             newUser = loginEvent.isNewUser();
301
             newUser = loginEvent.isNewUser();
256
             mPresenter.getMineData();
302
             mPresenter.getMineData();
257
-            mPresenter.getMineBill(year);
303
+//            mPresenter.getMineBill(year);
304
+            setBillData();
258
         }
305
         }
259
 
306
 
260
     }
307
     }
286
     public void onMessageEvent(RefreshEvent loginEvent) {
333
     public void onMessageEvent(RefreshEvent loginEvent) {
287
 
334
 
288
         mPresenter.getMineData();
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
      * @param loginOutEvent
347
      * @param loginOutEvent
298
      */
348
      */
304
             if(mNameText!=null){
354
             if(mNameText!=null){
305
                 mNameText.setText("未登录");
355
                 mNameText.setText("未登录");
306
                 mPortraitImage.setImageResource(R.drawable.im_portrait);
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
             }
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
             if(mNameText!=null){
452
             if(mNameText!=null){
404
                 mNameText.setText("未登录");
453
                 mNameText.setText("未登录");
405
                 mPortraitImage.setImageResource(R.drawable.im_portrait);
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
      */
69
      */
70
     public static void setTextForMoey(String text, TextView textView,int s1,int s2) {
70
     public static void setTextForMoey(String text, TextView textView,int s1,int s2) {
71
         String[] split = null;
71
         String[] split = null;
72
-        String replace = text.replace("-", "");
72
+//        String replace = text.replace("-", "");
73
         try {
73
         try {
74
-            split = replace.split("\\.");
74
+            split = text.split("\\.");
75
             TextParser textParser = new TextParser();
75
             TextParser textParser = new TextParser();
76
             textParser.append(split[0], DisplayUtil.dip2px(s1), Color.BLACK);
76
             textParser.append(split[0], DisplayUtil.dip2px(s1), Color.BLACK);
77
             textParser.append("." + split[1], DisplayUtil.dip2px(s2), Color.parseColor("#262626"));
77
             textParser.append("." + split[1], DisplayUtil.dip2px(s2), Color.parseColor("#262626"));
86
             textParser.parse(textView);
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
        android:ellipsize="end"
19
        android:ellipsize="end"
20
        android:maxLines="1"
20
        android:maxLines="1"
21
        android:layout_height="wrap_content"
21
        android:layout_height="wrap_content"
22
-       android:text="11111.0000"
23
        />
22
        />
24
 
23
 
25
     <LinearLayout
24
     <LinearLayout
46
             android:id="@+id/income_text"
45
             android:id="@+id/income_text"
47
             android:ellipsize="end"
46
             android:ellipsize="end"
48
             android:maxLines="1"
47
             android:maxLines="1"
49
-            android:text="5000.00"
50
             />
48
             />
51
         </LinearLayout>
49
         </LinearLayout>
52
         <View
50
         <View
73
             android:ellipsize="end"
71
             android:ellipsize="end"
74
             android:maxLines="1"
72
             android:maxLines="1"
75
             android:layout_height="wrap_content"
73
             android:layout_height="wrap_content"
76
-            android:text="7710.00"
77
             />
74
             />
78
      </LinearLayout>
75
      </LinearLayout>
79
     </LinearLayout>
76
     </LinearLayout>