Search in sources :

Example 6 with Category

use of com.faltenreich.diaguard.shared.data.database.entity.Category in project Diaguard by Faltenreich.

the class MeasurementView method init.

private void init() {
    binding = ListItemMeasurementBinding.inflate(LayoutInflater.from(getContext()), this);
    View inputView;
    Category category = measurement.getCategory();
    switch(category) {
        case INSULIN:
            inputView = new InsulinInputView(getContext(), (Insulin) measurement);
            break;
        case MEAL:
            inputView = new MealInputView(getContext(), (Meal) measurement);
            break;
        case PRESSURE:
            inputView = new PressureInputView(getContext(), (Pressure) measurement);
            break;
        default:
            inputView = new GenericInputView<>(getContext(), category.toClass(), measurement);
    }
    // noinspection unchecked
    this.inputView = (MeasurementInputView<?, T>) inputView;
}
Also used : PressureInputView(com.faltenreich.diaguard.feature.entry.edit.input.PressureInputView) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) InsulinInputView(com.faltenreich.diaguard.feature.entry.edit.input.InsulinInputView) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) GenericInputView(com.faltenreich.diaguard.feature.entry.edit.input.GenericInputView) PressureInputView(com.faltenreich.diaguard.feature.entry.edit.input.PressureInputView) ImageView(android.widget.ImageView) InsulinInputView(com.faltenreich.diaguard.feature.entry.edit.input.InsulinInputView) View(android.view.View) CardView(androidx.cardview.widget.CardView) MeasurementInputView(com.faltenreich.diaguard.feature.entry.edit.input.MeasurementInputView) MealInputView(com.faltenreich.diaguard.feature.entry.edit.input.MealInputView) TextView(android.widget.TextView) Insulin(com.faltenreich.diaguard.shared.data.database.entity.Insulin) Pressure(com.faltenreich.diaguard.shared.data.database.entity.Pressure) MealInputView(com.faltenreich.diaguard.feature.entry.edit.input.MealInputView)

Example 7 with Category

use of com.faltenreich.diaguard.shared.data.database.entity.Category in project Diaguard by Faltenreich.

the class ExportFragment method export.

private void export() {
    progressComponent.show(getContext());
    progressComponent.setMessage(getString(R.string.export_progress));
    DateTime dateStart = this.dateStart != null ? this.dateStart.withTimeAtStartOfDay() : null;
    DateTime dateEnd = this.dateEnd != null ? this.dateEnd.withTimeAtStartOfDay() : null;
    Category[] categories = categoryListAdapter.getSelectedCategories();
    PdfExportConfig config = new PdfExportConfig(getContext(), this, dateStart, dateEnd, categories, getStyle(), getBinding().headerCheckbox.isChecked(), getBinding().footerCheckbox.isChecked(), getBinding().noteCheckbox.isChecked(), getBinding().tagsCheckbox.isChecked(), getBinding().emptyDaysCheckbox.isChecked(), categoryListAdapter.exportFood(), categoryListAdapter.splitInsulin(), categoryListAdapter.highlightLimits());
    config.persistInSharedPreferences();
    FileType type = getFormat();
    switch(type) {
        case PDF:
            Export.exportPdf(config);
            break;
        case CSV:
            Export.exportCsv(getContext(), this, dateStart, dateEnd, categories);
            break;
    }
}
Also used : PdfExportConfig(com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfExportConfig) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) FileType(com.faltenreich.diaguard.feature.export.job.FileType) DateTime(org.joda.time.DateTime)

Example 8 with Category

use of com.faltenreich.diaguard.shared.data.database.entity.Category in project Diaguard by Faltenreich.

the class ExportFragment method initCategories.

private void initCategories() {
    List<ExportCategoryListItem> items = new ArrayList<>();
    Category[] activeCategories = PreferenceStore.getInstance().getActiveCategories();
    List<Category> selectedCategories = Arrays.asList(PreferenceStore.getInstance().getExportCategories());
    for (Category category : activeCategories) {
        boolean isCategorySelected = selectedCategories.contains(category);
        boolean isExtraSelected;
        switch(category) {
            case BLOODSUGAR:
                isExtraSelected = PreferenceStore.getInstance().limitsAreHighlighted();
                break;
            case INSULIN:
                isExtraSelected = PreferenceStore.getInstance().exportInsulinSplit();
                break;
            case MEAL:
                isExtraSelected = PreferenceStore.getInstance().exportFood();
                break;
            default:
                isExtraSelected = false;
        }
        items.add(new ExportCategoryListItem(category, isCategorySelected, isExtraSelected));
    }
    categoryListAdapter.addItems(items);
    categoryListAdapter.notifyDataSetChanged();
}
Also used : Category(com.faltenreich.diaguard.shared.data.database.entity.Category) ArrayList(java.util.ArrayList)

Example 9 with Category

use of com.faltenreich.diaguard.shared.data.database.entity.Category 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)

Example 10 with Category

use of com.faltenreich.diaguard.shared.data.database.entity.Category in project Diaguard by Faltenreich.

the class CsvImport method importFromVersion2_2.

@SuppressWarnings("ParameterCanBeLocal")
private void importFromVersion2_2(CSVReader reader, String[] nextLine) throws Exception {
    Entry entry = null;
    while ((nextLine = reader.readNext()) != null) {
        String key = nextLine[0];
        if (key.equalsIgnoreCase(Entry.BACKUP_KEY)) {
            entry = new Entry();
            entry.setDate(DateTimeFormat.forPattern(Export.BACKUP_DATE_FORMAT).parseDateTime(nextLine[1]));
            String note = nextLine[2];
            entry.setNote(note != null && note.length() > 0 ? note : null);
            entry = EntryDao.getInstance().createOrUpdate(entry);
        } else if (key.equalsIgnoreCase(Measurement.BACKUP_KEY) && entry != null) {
            try {
                Category category = Helper.valueOf(Category.class, nextLine[1]);
                Measurement measurement = category.toClass().newInstance();
                List<Float> valueList = new ArrayList<>();
                for (int position = 2; position < nextLine.length; position++) {
                    String valueString = nextLine[position];
                    try {
                        valueList.add(FloatUtils.parseNumber(valueString));
                    } catch (NumberFormatException exception) {
                        Log.e(TAG, exception.toString());
                    }
                }
                float[] values = new float[valueList.size()];
                for (int position = 0; position < valueList.size(); position++) {
                    values[position] = valueList.get(position);
                }
                measurement.setValues(values);
                measurement.setEntry(entry);
                MeasurementDao.getInstance(category.toClass()).createOrUpdate(measurement);
            } catch (InstantiationException exception) {
                Log.e(TAG, exception.toString());
            } catch (IllegalAccessException exception) {
                Log.e(TAG, exception.toString());
            }
        }
    }
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Category (com.faltenreich.diaguard.shared.data.database.entity.Category)31 ArrayList (java.util.ArrayList)18 Measurement (com.faltenreich.diaguard.shared.data.database.entity.Measurement)15 Entry (com.faltenreich.diaguard.shared.data.database.entity.Entry)13 List (java.util.List)10 EntryTag (com.faltenreich.diaguard.shared.data.database.entity.EntryTag)7 FoodEaten (com.faltenreich.diaguard.shared.data.database.entity.FoodEaten)7 Meal (com.faltenreich.diaguard.shared.data.database.entity.Meal)7 Tag (com.faltenreich.diaguard.shared.data.database.entity.Tag)7 View (android.view.View)6 ImageView (android.widget.ImageView)5 CategoryValueListItem (com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem)5 Context (android.content.Context)4 Point (com.pdfjet.Point)4 DateTime (org.joda.time.DateTime)4 LayoutInflater (android.view.LayoutInflater)3 LinearLayout (android.widget.LinearLayout)3 TextView (android.widget.TextView)3 CellBuilder (com.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder)3 BloodSugar (com.faltenreich.diaguard.shared.data.database.entity.BloodSugar)3