예제 #1
0
  public void editWeight(double weight) {
    this.weight = WeightDiaryEntry.convertWeightFromSelectedUnits(weight);
    setDirty();

    // Let's also create or update a diary entry for weight
    DiaryEntries entries = DataHelper.getDailyDiaryEntries(new Date(), null);
    WeightDiaryEntry e = entries.getWeightEntry(new Date());
    if (e == null) {
      e = new WeightDiaryEntry(weight, new Date());
    } else {
      e.setWeight(weight);
    }
    DataHelper.saveDiaryEntry(e, null);
  }
예제 #2
0
  public double getWeight() {
    RuntimeExceptionDao<WeightDiaryEntry, Integer> diaryDao =
        DataHelper.getDatabaseHelper().getDiaryDao(WeightDiaryEntry.class);

    List<WeightDiaryEntry> entries;
    try {
      entries =
          diaryDao
              .queryBuilder()
              .orderBy(DiaryEntry.DATESTAMP_FIELD_NAME, true)
              .where()
              .eq(DiaryEntry.DELETED_FIELD_NAME, false)
              .query();

      if (entries != null && entries.size() > 0) {
        WeightDiaryEntry weightEntry = (WeightDiaryEntry) entries.get(entries.size() - 1);
        this.weight = weightEntry.getWeight();
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }

    return this.weight;
  }
예제 #3
0
 public String getWeightForSelectedUnits() {
   double weight = WeightDiaryEntry.getWeightForSelectedUnits(getWeight());
   DecimalFormat decimalFormat = new DecimalFormat("#.##");
   return decimalFormat.format(weight);
 }
예제 #4
0
 public String getWeightWithUnits() {
   return WeightDiaryEntry.getWeightWithUnits(getWeight());
 }