Exemplo n.º 1
0
 /** 初始化本类 */
 private void initData() {
   currentBaby = App.getCurrentBaby();
   if (currentBaby == null) {
     ACache aCache = ACache.get(App.getAppContext());
     String json = aCache.getAsString(Baby.CACHE_KEY);
     Log.i("baby currentbaby json", json);
     currentBaby = JSON.parseObject(json, Baby.class);
   }
   if (babyInfos == null) babyInfos = getAllBabyInfoCache();
   months2Weights();
 }
Exemplo n.º 2
0
 /**
  * 存入一个babyinfo,先存网络,如果成功在存本地,本地也成功,则更新本类的babyinfos,更新一下monthtoweights 并更新currentbabyinfo
  *
  * @param babyInfo 要存入的babyinfo
  */
 public void saveOneWeight(final BabyInfo babyInfo) {
   babyInfo.setBaby(App.getCurrentBaby());
   babyInfo.saveInCloud(
       new SaveCallback() {
         @Override
         public void done(AVException e) {
           if (e != null) {
             e.printStackTrace();
             Log.i(TAG, "babyinfo incloud failed");
             return;
           }
           Log.i(TAG, "babyinfo incloud success");
           babyInfo.saveInCache(
               App.getAppContext(),
               new LocalSaveTask.LocalSaveCallback() {
                 @Override
                 public void done() {
                   babyInfos.add(babyInfo);
                   if (babyInfos.isEmpty()) babyInfos.add(babyInfo);
                   else {
                     BabyInfo tempBabyinfo = babyInfos.get(babyInfos.size() - 1);
                     if (tempBabyinfo.getAge().equals(babyInfo.getAge())) {
                       babyInfos.remove(babyInfos.size() - 1);
                       babyInfos.add(babyInfo);
                     } else {
                       babyInfos.add(babyInfo);
                     }
                   }
                   addOneWeight(babyInfo);
                   String currentDate = currentBabyInfo.getAge();
                   String today = babyInfo.getAge();
                   Date current = null, now = null;
                   try {
                     current = Standar.DATE_FORMAT.parse(currentDate);
                   } catch (ParseException e) {
                     e.printStackTrace();
                     return;
                   }
                   try {
                     now = Standar.DATE_FORMAT.parse(today);
                   } catch (ParseException e) {
                     e.printStackTrace();
                     return;
                   }
                   if (current.compareTo(now) <= 0) {
                     currentBabyInfo = babyInfo;
                   }
                 }
               });
         }
       });
 }