use of com.faltenreich.diaguard.shared.view.chip.ChipView in project Diaguard by Faltenreich.
the class EntryEditFragment method addTag.
private void addTag(Tag tag) {
int index = viewModel.getIndexOfTag(tag);
if (index == -1) {
EntryTag entryTag = new EntryTag();
entryTag.setEntry(viewModel.getEntry());
entryTag.setTag(tag);
viewModel.getEntryTags().add(entryTag);
}
ChipView chip = new ChipView(getContext());
chip.setTag(tag);
chip.setText(tag.getName());
chip.setCloseIconVisible(true);
chip.setOnCloseIconClickListener(view -> removeTag(tag, chip));
chip.setOnClickListener(view -> removeTag(tag, chip));
tagListView.addView(chip);
tagAdapter.set(tag, false);
dismissTagDropDown();
tagListView.setVisibility(View.VISIBLE);
}
use of com.faltenreich.diaguard.shared.view.chip.ChipView 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);
}
}
}
Aggregations