use of com.faltenreich.diaguard.shared.data.database.entity.Measurement in project Diaguard by Faltenreich.
the class EntryEditFragment method setEntry.
private void setEntry(@NonNull Entry entry) {
noteInput.setText(entry.getNote());
// FIXME: Previous order gets ignored on Fragment recreation
List<Measurement> measurements = entry.getMeasurementCache();
if (measurements != null && !measurements.isEmpty()) {
Collections.sort(measurements, CategoryComparatorFactory.getInstance().createComparatorFromMeasurements());
for (Measurement measurement : measurements) {
addMeasurement(measurement, false);
}
} else if (!entry.isPersisted() && !isRecreated) {
for (Category category : viewModel.getPinnedCategories()) {
if (!hasCategory(category)) {
addCategory(category, false);
}
}
}
if (viewModel.getEntryTags() != null) {
for (EntryTag entryTag : viewModel.getEntryTags()) {
Tag tag = entryTag.getTag();
if (tag != null) {
addTag(entryTag.getTag());
}
}
}
invalidateDateTime();
fabMenu.restock();
}
use of com.faltenreich.diaguard.shared.data.database.entity.Measurement in project Diaguard by Faltenreich.
the class EntryEditFragment method getFoodEaten.
private List<FoodEaten> getFoodEaten() {
for (int index = 0; index < measurementContainer.getChildCount(); index++) {
View view = measurementContainer.getChildAt(index);
if (view instanceof MeasurementView) {
MeasurementView<?> measurementView = ((MeasurementView<?>) view);
Measurement measurement = measurementView.getMeasurement();
if (measurement instanceof Meal) {
List<FoodEaten> foodEatenList = new ArrayList<>();
for (FoodEaten foodEaten : ((Meal) measurement).getFoodEatenCache()) {
if (foodEaten.isValid()) {
foodEatenList.add(foodEaten);
}
}
return foodEatenList;
}
}
}
return new ArrayList<>();
}
use of com.faltenreich.diaguard.shared.data.database.entity.Measurement in project Diaguard by Faltenreich.
the class EntryEditViewModel method createEntry.
private void createEntry() {
entry = new Entry();
entry.setDate(dateTime);
if (category != null) {
Measurement measurement = ObjectFactory.createFromClass(category.toClass());
measurement.setEntry(entry);
entry.getMeasurementCache().add(measurement);
}
}
use of com.faltenreich.diaguard.shared.data.database.entity.Measurement in project Diaguard by Faltenreich.
the class HbA1cDashboardValue method forUserGeneratedHbA1c.
@Nullable
private Float forUserGeneratedHbA1c() {
Entry latestHbA1cEntry = getLatestEntryWithHbA1c();
if (latestHbA1cEntry != null) {
latestHbA1cEntry.setMeasurementCache(EntryDao.getInstance().getMeasurements(latestHbA1cEntry));
for (Measurement measurement : latestHbA1cEntry.getMeasurementCache()) {
if (measurement instanceof HbA1c) {
this.entry = latestHbA1cEntry;
HbA1c hbA1c = (HbA1c) measurement;
return PreferenceStore.getInstance().formatDefaultToCustomUnit(Category.HBA1C, hbA1c.getValues()[0]);
}
}
}
return null;
}
use of com.faltenreich.diaguard.shared.data.database.entity.Measurement in project Diaguard by Faltenreich.
the class CsvExport method doInBackground.
@Override
protected File doInBackground(Void... params) {
DateTime dateStart = config.getDateStart();
DateTime dateEnd = config.getDateEnd();
Category[] categories = config.getCategories();
boolean isBackup = config.isBackup();
File file = isBackup ? Export.getBackupFile(config, FileType.CSV) : Export.getExportFile(config);
try {
FileWriter fileWriter = new FileWriter(file);
CSVWriter writer = new CSVWriter(fileWriter, CsvMeta.CSV_DELIMITER);
if (isBackup) {
// Meta information to detect the data scheme in future iterations
String[] meta = new String[] { CsvMeta.CSV_KEY_META, Integer.toString(DatabaseHelper.getVersion()) };
writer.writeNext(meta);
List<Tag> tags = TagDao.getInstance().getAll();
for (Tag tag : tags) {
writer.writeNext(ArrayUtils.add(tag.getValuesForBackup(), 0, tag.getKeyForBackup()));
}
List<Food> foods = FoodDao.getInstance().getAllFromUser();
for (Food food : foods) {
writer.writeNext(ArrayUtils.add(food.getValuesForBackup(), 0, food.getKeyForBackup()));
}
}
List<Entry> entries = dateStart != null && dateEnd != null ? EntryDao.getInstance().getEntriesBetween(dateStart, dateEnd) : EntryDao.getInstance().getAll();
int position = 0;
for (Entry entry : entries) {
publishProgress(String.format(Locale.getDefault(), "%s %d/%d", config.getContext().getString(R.string.entry), position, entries.size()));
writer.writeNext(isBackup ? ArrayUtils.add(entry.getValuesForBackup(), 0, entry.getKeyForBackup()) : entry.getValuesForExport());
List<Measurement> measurements = categories != null ? EntryDao.getInstance().getMeasurements(entry, categories) : EntryDao.getInstance().getMeasurements(entry);
for (Measurement measurement : measurements) {
writer.writeNext(isBackup ? ArrayUtils.add(measurement.getValuesForBackup(), 0, measurement.getKeyForBackup()) : measurement.getValuesForExport());
if (isBackup && measurement instanceof Meal) {
Meal meal = (Meal) measurement;
for (FoodEaten foodEaten : meal.getFoodEaten()) {
if (foodEaten.getMeal() != null && foodEaten.getFood() != null) {
writer.writeNext(ArrayUtils.add(foodEaten.getValuesForBackup(), 0, foodEaten.getKeyForBackup()));
}
}
}
}
if (isBackup) {
List<EntryTag> entryTags = EntryTagDao.getInstance().getAll(entry);
for (EntryTag entryTag : entryTags) {
if (entryTag.getEntry() != null && entryTag.getTag() != null) {
writer.writeNext(ArrayUtils.add(entryTag.getValuesForBackup(), 0, entryTag.getKeyForBackup()));
}
}
}
position++;
}
writer.close();
} catch (IOException exception) {
Log.e(TAG, exception.toString());
}
return file;
}
Aggregations