Search in sources :

Example 1 with ChipView

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

Example 2 with ChipView

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);
        }
    }
}
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) ChipView(com.faltenreich.diaguard.shared.view.chip.ChipView) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) View(android.view.View) ChipView(com.faltenreich.diaguard.shared.view.chip.ChipView) TextView(android.widget.TextView) BloodSugar(com.faltenreich.diaguard.shared.data.database.entity.BloodSugar) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) Tag(com.faltenreich.diaguard.shared.data.database.entity.Tag) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag) ImageView(android.widget.ImageView) ChipGroup(com.google.android.material.chip.ChipGroup) LinearLayout(android.widget.LinearLayout)

Aggregations

EntryTag (com.faltenreich.diaguard.shared.data.database.entity.EntryTag)2 ChipView (com.faltenreich.diaguard.shared.view.chip.ChipView)2 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 BloodSugar (com.faltenreich.diaguard.shared.data.database.entity.BloodSugar)1 Category (com.faltenreich.diaguard.shared.data.database.entity.Category)1 Entry (com.faltenreich.diaguard.shared.data.database.entity.Entry)1 FoodEaten (com.faltenreich.diaguard.shared.data.database.entity.FoodEaten)1 Measurement (com.faltenreich.diaguard.shared.data.database.entity.Measurement)1 Tag (com.faltenreich.diaguard.shared.data.database.entity.Tag)1 ChipGroup (com.google.android.material.chip.ChipGroup)1 ArrayList (java.util.ArrayList)1