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;
}
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;
}
}
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();
}
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;
}
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());
}
}
}
}
Aggregations