use of com.faltenreich.diaguard.shared.data.database.entity.Tag in project Diaguard by Faltenreich.
the class PdfNoteFactory method createNote.
@Nullable
public static PdfNote createNote(PdfExportConfig config, Entry entry) {
List<String> entryNotesAndTagsOfDay = new ArrayList<>();
List<String> foodOfDay = new ArrayList<>();
if (config.exportNotes() && !StringUtils.isBlank(entry.getNote())) {
entryNotesAndTagsOfDay.add(entry.getNote());
}
if (config.exportTags()) {
List<EntryTag> entryTags = EntryTagDao.getInstance().getAll(entry);
for (EntryTag entryTag : entryTags) {
Tag tag = entryTag.getTag();
if (tag != null) {
entryNotesAndTagsOfDay.add(entryTag.getTag().getName());
}
}
}
if (config.exportFood()) {
Meal meal = (Meal) MeasurementDao.getInstance(Meal.class).getMeasurement(entry);
if (meal != null) {
for (FoodEaten foodEaten : FoodEatenDao.getInstance().getAll(meal)) {
String foodNote = foodEaten.print();
if (foodNote != null) {
foodOfDay.add(foodNote);
}
}
}
}
boolean hasEntryNotesAndTags = !entryNotesAndTagsOfDay.isEmpty();
boolean hasFood = !foodOfDay.isEmpty();
if (hasEntryNotesAndTags || hasFood) {
List<String> notes = new ArrayList<>();
if (hasEntryNotesAndTags) {
notes.add(TextUtils.join(", ", entryNotesAndTagsOfDay));
}
if (hasFood) {
notes.add(TextUtils.join(", ", foodOfDay));
}
String note = TextUtils.join("\n", notes);
return new PdfNote(entry.getDate(), note);
}
return null;
}
use of com.faltenreich.diaguard.shared.data.database.entity.Tag in project Diaguard by Faltenreich.
the class TagImport method importData.
@Override
public void importData() {
try {
CSVReader reader = CsvImport.getCsvReader(context, TAGS_CSV_FILE_NAME);
String languageCode = locale.getLanguage();
String[] nextLine = reader.readNext();
int languageRow = CsvImport.getLanguageColumn(languageCode, nextLine);
List<Tag> tags = new ArrayList<>();
while ((nextLine = reader.readNext()) != null) {
if (nextLine.length >= 1) {
Tag tag = new Tag();
tag.setName(nextLine[languageRow]);
tags.add(tag);
}
}
TagDao.getInstance().deleteAll();
Collections.reverse(tags);
TagDao.getInstance().bulkCreateOrUpdate(tags);
Log.i(TAG, String.format("Imported %d tags from csv", tags.size()));
PreferenceStore.getInstance().setDidImportTags(locale, true);
} catch (IOException exception) {
Log.e(TAG, exception.toString());
}
}
use of com.faltenreich.diaguard.shared.data.database.entity.Tag in project Diaguard by Faltenreich.
the class LogEntryViewHolder method onBind.
@Override
public void onBind(LogEntryListItem item) {
Entry entry = item.getEntry();
List<EntryTag> entryTags = item.getEntryTags();
List<FoodEaten> foodEatenList = item.getFoodEatenList();
getBinding().dateLabel.setText(entry.getDate().toString("HH:mm"));
TextView noteLabel = getBinding().noteLabel;
if (entry.getNote() != null && entry.getNote().length() > 0) {
noteLabel.setVisibility(View.VISIBLE);
noteLabel.setText(entry.getNote());
} else {
noteLabel.setVisibility(View.GONE);
}
TextView foodLabel = getBinding().foodLabel;
if (foodEatenList != null && foodEatenList.size() > 0) {
List<String> foodNotes = new ArrayList<>();
for (FoodEaten foodEaten : foodEatenList) {
String foodEatenAsString = foodEaten.print();
if (foodEatenAsString != null) {
foodNotes.add(foodEatenAsString);
}
}
if (foodNotes.size() > 0) {
foodLabel.setVisibility(View.VISIBLE);
foodLabel.setText(TextUtils.join("\n", foodNotes));
} else {
foodLabel.setVisibility(View.GONE);
}
} else {
foodLabel.setVisibility(View.GONE);
}
ChipGroup entryTagChipGroup = getBinding().entryTagChipGroup;
entryTagChipGroup.setVisibility(entryTags != null && entryTags.size() > 0 ? View.VISIBLE : View.GONE);
entryTagChipGroup.removeAllViews();
if (entryTags != null) {
for (EntryTag entryTag : entryTags) {
Tag tag = entryTag.getTag();
if (tag != null) {
ChipView chipView = new ChipView(getContext());
chipView.setText(tag.getName());
chipView.setOnClickListener(view -> listener.onTagSelected(tag, view));
entryTagChipGroup.addView(chipView);
}
}
}
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout measurementsLayout = getBinding().measurementsLayout;
if (inflater != null) {
measurementsLayout.removeAllViews();
List<Measurement> measurements = entry.getMeasurementCache();
if (measurements.size() > 0) {
measurementsLayout.setVisibility(View.VISIBLE);
for (Measurement measurement : measurements) {
Category category = measurement.getCategory();
View viewMeasurement = inflater.inflate(R.layout.list_item_log_measurement, measurementsLayout, false);
ImageView categoryImage = viewMeasurement.findViewById(R.id.image);
int imageResourceId = category.getIconImageResourceId();
categoryImage.setImageDrawable(ContextCompat.getDrawable(getContext(), imageResourceId));
categoryImage.setColorFilter(ContextCompat.getColor(getContext(), R.color.gray_dark));
TextView value = viewMeasurement.findViewById(R.id.value);
value.setText(measurement.print(getContext()));
if (category == Category.BLOODSUGAR) {
BloodSugar bloodSugar = (BloodSugar) measurement;
if (PreferenceStore.getInstance().limitsAreHighlighted()) {
int backgroundColor = ContextCompat.getColor(getContext(), R.color.green);
if (bloodSugar.getMgDl() > PreferenceStore.getInstance().getLimitHyperglycemia()) {
backgroundColor = ContextCompat.getColor(getContext(), R.color.red);
} else if (bloodSugar.getMgDl() < PreferenceStore.getInstance().getLimitHypoglycemia()) {
backgroundColor = ContextCompat.getColor(getContext(), R.color.blue);
}
categoryImage.setColorFilter(backgroundColor);
}
}
measurementsLayout.addView(viewMeasurement);
}
} else {
measurementsLayout.setVisibility(View.GONE);
}
}
}
use of com.faltenreich.diaguard.shared.data.database.entity.Tag in project Diaguard by Faltenreich.
the class PdfLog method init.
private void init() {
PdfExportConfig config = cache.getConfig();
Context context = config.getContext();
List<List<Cell>> data = new ArrayList<>();
List<Cell> headerRow = new ArrayList<>();
Cell headerCell = new CellBuilder(new Cell(cache.getFontBold())).setWidth(getLabelWidth()).setText(DateTimeUtils.toWeekDayAndDate(cache.getDateTime())).build();
headerRow.add(headerCell);
data.add(headerRow);
for (Entry entry : entriesOfDay) {
List<Measurement> measurements = EntryDao.getInstance().getMeasurements(entry, cache.getConfig().getCategories());
entry.setMeasurementCache(measurements);
}
int rowIndex = 0;
for (Entry entry : entriesOfDay) {
int backgroundColor = rowIndex % 2 == 0 ? cache.getColorDivider() : Color.white;
int oldSize = data.size();
String time = entry.getDate().toString("HH:mm");
for (Measurement measurement : entry.getMeasurementCache()) {
Category category = measurement.getCategory();
int textColor = Color.black;
if (category == Category.BLOODSUGAR && config.highlightLimits()) {
BloodSugar bloodSugar = (BloodSugar) measurement;
float value = bloodSugar.getMgDl();
if (value > PreferenceStore.getInstance().getLimitHyperglycemia()) {
textColor = cache.getColorHyperglycemia();
} else if (value < PreferenceStore.getInstance().getLimitHypoglycemia()) {
textColor = cache.getColorHypoglycemia();
}
}
String measurementText = measurement.print(context);
if (category == Category.MEAL && config.exportFood()) {
List<String> foodOfDay = new ArrayList<>();
Meal meal = (Meal) MeasurementDao.getInstance(Meal.class).getMeasurement(entry);
if (meal != null) {
for (FoodEaten foodEaten : FoodEatenDao.getInstance().getAll(meal)) {
String foodNote = foodEaten.print();
if (foodNote != null) {
foodOfDay.add(foodNote);
}
}
}
if (!foodOfDay.isEmpty()) {
String foodText = TextUtils.join(", ", foodOfDay);
measurementText = String.format("%s\n%s", measurementText, foodText);
}
}
data.add(getRow(cache, data.size() == oldSize ? time : null, context.getString(category.getStringAcronymResId()), measurementText, backgroundColor, textColor));
}
if (config.exportTags()) {
List<EntryTag> entryTags = EntryTagDao.getInstance().getAll(entry);
if (!entryTags.isEmpty()) {
List<String> tagNames = new ArrayList<>();
for (EntryTag entryTag : entryTags) {
Tag tag = entryTag.getTag();
if (tag != null) {
String tagName = tag.getName();
if (!StringUtils.isBlank(tagName)) {
tagNames.add(tagName);
}
}
}
data.add(getRow(cache, data.size() == oldSize ? time : null, context.getString(R.string.tags), TextUtils.join(", ", tagNames), backgroundColor));
}
}
if (config.exportNotes()) {
if (!StringUtils.isBlank(entry.getNote())) {
data.add(getRow(cache, data.size() == oldSize ? time : null, context.getString(R.string.note), entry.getNote(), backgroundColor));
}
}
rowIndex++;
}
boolean hasData = data.size() > 1;
if (!hasData) {
data.add(CellFactory.createEmptyRow(cache));
}
try {
table.setData(data);
} catch (Exception exception) {
Log.e(TAG, exception.toString());
}
}
use of com.faltenreich.diaguard.shared.data.database.entity.Tag in project Diaguard by Faltenreich.
the class TagAutoCompleteAdapter method getResults.
private List<Tag> getResults() {
List<Tag> results = new ArrayList<>();
for (Map.Entry<Tag, Boolean> entry : tags.entrySet()) {
if (entry.getValue()) {
results.add(entry.getKey());
}
}
Collections.sort(results, (lhs, rhs) -> {
// Sort descending by updatedAt
DateTime rhsDateTime = rhs != null ? rhs.getUpdatedAt() : DateTime.now();
DateTime lhsDateTime = rhs != null ? lhs.getUpdatedAt() : DateTime.now();
return rhsDateTime != null ? lhsDateTime != null ? rhsDateTime.compareTo(lhsDateTime) : -1 : 1;
});
return results;
}
Aggregations