Search in sources :

Example 6 with Measurement

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();
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag) Tag(com.faltenreich.diaguard.shared.data.database.entity.Tag) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag)

Example 7 with Measurement

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<>();
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) MeasurementView(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) ArrayList(java.util.ArrayList) MeasurementView(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView) NestedScrollView(androidx.core.widget.NestedScrollView) ImageView(android.widget.ImageView) View(android.view.View) ChipView(com.faltenreich.diaguard.shared.view.chip.ChipView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 8 with Measurement

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);
    }
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry)

Example 9 with 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;
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) HbA1c(com.faltenreich.diaguard.shared.data.database.entity.HbA1c) Nullable(androidx.annotation.Nullable)

Example 10 with Measurement

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;
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) FileWriter(java.io.FileWriter) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) CSVWriter(com.opencsv.CSVWriter) IOException(java.io.IOException) DateTime(org.joda.time.DateTime) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) Tag(com.faltenreich.diaguard.shared.data.database.entity.Tag) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag) File(java.io.File) Food(com.faltenreich.diaguard.shared.data.database.entity.Food)

Aggregations

Measurement (com.faltenreich.diaguard.shared.data.database.entity.Measurement)24 Entry (com.faltenreich.diaguard.shared.data.database.entity.Entry)15 Category (com.faltenreich.diaguard.shared.data.database.entity.Category)12 ArrayList (java.util.ArrayList)12 EntryTag (com.faltenreich.diaguard.shared.data.database.entity.EntryTag)8 FoodEaten (com.faltenreich.diaguard.shared.data.database.entity.FoodEaten)8 Meal (com.faltenreich.diaguard.shared.data.database.entity.Meal)6 Tag (com.faltenreich.diaguard.shared.data.database.entity.Tag)6 View (android.view.View)4 ImageView (android.widget.ImageView)4 ChipView (com.faltenreich.diaguard.shared.view.chip.ChipView)4 List (java.util.List)4 DateTime (org.joda.time.DateTime)4 AutoCompleteTextView (android.widget.AutoCompleteTextView)3 NestedScrollView (androidx.core.widget.NestedScrollView)3 MeasurementView (com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView)3 BloodSugar (com.faltenreich.diaguard.shared.data.database.entity.BloodSugar)3 CategoryDeprecated (com.faltenreich.diaguard.shared.data.database.entity.deprecated.CategoryDeprecated)3 Food (com.faltenreich.diaguard.shared.data.database.entity.Food)2 EntryAddedEvent (com.faltenreich.diaguard.shared.event.data.EntryAddedEvent)2