コード例 #1
0
 /** 同步的与云端同步,并更新weighthelper里面数据 */
 public void sync() {
   BabyInfoDao babyInfoDao = new BabyInfoDao();
   List<BabyInfo> babyInfosCloud = babyInfoDao.findByBabyFromCloud(currentBaby);
   if (babyInfosCloud == null || babyInfosCloud.isEmpty()) return;
   if (equals(currentBabyInfo, babyInfosCloud.get(0))) {
     return;
   }
   for (BabyInfo babyInfo : babyInfosCloud) {
     babyInfo.saveInCache(App.getAppContext());
   }
   initData();
 }
コード例 #2
0
  /**
   * 从本地同步获取所有的babyinfo缓存,并更新currentbabyinfo
   *
   * @return 返回一个babyinfo的list;
   */
  private List<BabyInfo> getAllBabyInfoCache() {
    BabyInfoDao babyInfoDao = new BabyInfoDao();
    if (currentBaby == null) Log.i("baby current", "null");
    Date birth = currentBaby.getCreatedAt();
    if (birth == null) Log.i("baby birth", "null");

    /*
    String birthday = currentBaby.getBirthday();
    Date birth = null;
    try {
        birth = Standar.DATE_FORMAT.parse(birthday);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    */
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(birth);
    int birthYear = calendar.get(Calendar.YEAR);
    int birthMonth = calendar.get(Calendar.MONTH) + 1;
    Date date = new Date();
    calendar.setTime(date);
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH) + 1;
    List<BabyInfo> result = new ArrayList<>();
    for (int i = birthYear; i <= year; i++) {
      for (int j = birthMonth; j <= month; j++) {
        String time;
        if (j >= 10) time = String.valueOf(i) + "-" + String.valueOf(j);
        else time = String.valueOf(i) + "-0" + String.valueOf(j);
        Log.d("baby gettime", time);
        List<BabyInfo> tempBabyInfos = babyInfoDao.findByDateFromCache(App.getAppContext(), time);
        if (tempBabyInfos == null) continue;
        result.addAll(tempBabyInfos);
        int count = tempBabyInfos.size();
        if (count <= 0) continue;
        currentBabyInfo = tempBabyInfos.get(count - 1);
        Log.d("baby currentbabyinfo", "not null");
      }
    }

    return result;
  }