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); }
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; }
public String getWeightForSelectedUnits() { double weight = WeightDiaryEntry.getWeightForSelectedUnits(getWeight()); DecimalFormat decimalFormat = new DecimalFormat("#.##"); return decimalFormat.format(weight); }
public String getWeightWithUnits() { return WeightDiaryEntry.getWeightWithUnits(getWeight()); }