예제 #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();
 }
예제 #2
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();
 }
예제 #3
0
  private void drawExcle() {
    Context context = App.getAppContext();
    LinearLayout.LayoutParams temperatureParams =
        new LinearLayout.LayoutParams(mWidth, LinearLayout.LayoutParams.MATCH_PARENT);
    LinearLayout.LayoutParams amountParams =
        new LinearLayout.LayoutParams(mWidth, LinearLayout.LayoutParams.MATCH_PARENT);
    LinearLayout temperatureContainer =
        (LinearLayout) layout.findViewById(R.id.temperature_excle_container);
    LinearLayout amountContainer = (LinearLayout) layout.findViewById(R.id.amount_excle_container);

    refreshExcleData(temperatureData, amountData);

    temperatureExcle = new com.inhand.milk.fragment.milk_amount_curve.Excle(mContext);
    temperatureContainer.addView(temperatureExcle, temperatureParams);
    temperatureExcle.setRange(temperatureMax, temperatureMin);
    temperatureExcle.addLine(temperatureData);
    temperatureExcle.setTextColor(
        context
            .getResources()
            .getColor(R.color.milk_amount_curve_temperature_excle_title_text_color));
    temperatureExcle.setFirstBgColor(
        context
            .getResources()
            .getColor(R.color.milk_amount_curve_temperature_excle_first_bg_color));
    temperatureExcle.setSecondBgColor(
        context
            .getResources()
            .getColor(R.color.milk_amount_curve_temperature_excle_seconde_bg_color));
    temperatureExcle.setLineColor(
        context.getResources().getColor(R.color.milk_amount_curve_temperature_excle_line_color));
    setTemperatureExcle(temperatureExcle);

    amountExcle = new com.inhand.milk.fragment.milk_amount_curve.Excle(mContext);
    amountContainer.addView(amountExcle, amountParams);

    amountExcle.setRange(amountMax, amountMin);
    amountExcle.addLine(amountData);
    amountExcle.setTextColor(
        context.getResources().getColor(R.color.milk_amount_curve_amount_excle_title_text_color));
    amountExcle.setFirstBgColor(
        context.getResources().getColor(R.color.milk_amount_curve_amount_excle_first_bg_color));
    amountExcle.setSecondBgColor(
        context.getResources().getColor(R.color.milk_amount_curve_amount_excle_seconde_bg_color));
    amountExcle.setLineColor(
        context.getResources().getColor(R.color.milk_amount_curve_amount_excle_line_color));
    setAmountExcle(amountExcle);
  }
예제 #4
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;
  }