Search in sources :

Example 6 with BloodSugar

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

the class PdfTimeline method fetchData.

private void fetchData() {
    bloodSugars = new ArrayList<>();
    pdfNotes = new ArrayList<>();
    for (Entry entry : entriesOfDay) {
        if (showChartForBloodSugar) {
            List<Measurement> measurements = EntryDao.getInstance().getMeasurements(entry);
            for (Measurement measurement : measurements) {
                if (measurement instanceof BloodSugar) {
                    bloodSugars.add((BloodSugar) measurement);
                }
            }
        }
        PdfNote pdfNote = PdfNoteFactory.createNote(cache.getConfig(), entry);
        if (pdfNote != null) {
            pdfNotes.add(pdfNote);
        }
    }
    List<Category> categories = new ArrayList<>();
    for (Category category : cache.getConfig().getCategories()) {
        if (category != Category.BLOODSUGAR) {
            categories.add(category);
        }
    }
    measurements = EntryDao.getInstance().getAverageDataTable(cache.getDateTime(), categories.toArray(new Category[0]), HOUR_INTERVAL);
}
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) BloodSugar(com.faltenreich.diaguard.shared.data.database.entity.BloodSugar) PdfNote(com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfNote)

Example 7 with BloodSugar

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

Example 8 with BloodSugar

use of com.faltenreich.diaguard.shared.data.database.entity.BloodSugar 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());
    }
}
Also used : PdfExportConfig(com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfExportConfig) Context(android.content.Context) Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag) ArrayList(java.util.ArrayList) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) BloodSugar(com.faltenreich.diaguard.shared.data.database.entity.BloodSugar) Point(com.pdfjet.Point) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) CellBuilder(com.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.faltenreich.diaguard.shared.data.database.entity.Tag) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag) MultilineCell(com.faltenreich.diaguard.feature.export.job.pdf.view.MultilineCell) Cell(com.pdfjet.Cell)

Example 9 with BloodSugar

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

the class CalculatorFragment method showResult.

// Values are normalized
private void showResult(String formula, String formulaContent, final float bloodSugar, final float meal, final float bolus, final float correction) {
    float insulin = bolus + correction;
    // Build AlertDialog
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    final View viewPopup = inflater.inflate(R.layout.dialog_calculator_result, null);
    final ViewGroup infoLayout = viewPopup.findViewById(R.id.dialog_calculator_result_info);
    TextView textViewFormula = viewPopup.findViewById(R.id.dialog_calculator_result_formula);
    textViewFormula.setText(formula);
    TextView textViewFormulaContent = viewPopup.findViewById(R.id.dialog_calculator_result_formula_content);
    textViewFormulaContent.setText(formulaContent);
    // Handle negative insulin
    TextView textViewInfo = viewPopup.findViewById(R.id.textViewInfo);
    if (insulin <= 0) {
        // Advice skipping bolus
        viewPopup.findViewById(R.id.result).setVisibility(View.GONE);
        textViewInfo.setVisibility(View.VISIBLE);
        if (insulin < -1) {
            // Advice consuming carbohydrates
            textViewInfo.setText(String.format("%s %s", textViewInfo.getText().toString(), getString(R.string.bolus_no2)));
        }
    } else {
        viewPopup.findViewById(R.id.result).setVisibility(View.VISIBLE);
        textViewInfo.setVisibility(View.GONE);
    }
    TextView textViewValue = viewPopup.findViewById(R.id.textViewResult);
    textViewValue.setText(FloatUtils.parseFloat(insulin));
    TextView textViewUnit = viewPopup.findViewById(R.id.textViewUnit);
    textViewUnit.setText(PreferenceStore.getInstance().getUnitAcronym(Category.INSULIN));
    dialogBuilder.setView(viewPopup).setTitle(R.string.bolus).setNegativeButton(R.string.info, (dialog, id) -> {
    /* Set down below */
    }).setPositiveButton(R.string.store_values, (dialog, id) -> storeValues(bloodSugar, meal, bolus, correction)).setNeutralButton(R.string.back, (dialog, id) -> dialog.cancel());
    AlertDialog dialog = dialogBuilder.create();
    dialog.setCanceledOnTouchOutside(true);
    dialog.show();
    dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(view -> {
        infoLayout.setVisibility(View.VISIBLE);
        view.setEnabled(false);
    });
}
Also used : AlertDialog(android.app.AlertDialog) Bundle(android.os.Bundle) FloatUtils(com.faltenreich.diaguard.shared.data.primitive.FloatUtils) FoodSearchEvent(com.faltenreich.diaguard.shared.event.ui.FoodSearchEvent) MainButton(com.faltenreich.diaguard.feature.navigation.MainButton) NonNull(androidx.annotation.NonNull) PreferenceStore(com.faltenreich.diaguard.feature.preference.data.PreferenceStore) FoodSearchFragment(com.faltenreich.diaguard.feature.food.search.FoodSearchFragment) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) ArrayList(java.util.ArrayList) FactorChangedEvent(com.faltenreich.diaguard.shared.event.preference.FactorChangedEvent) EntryAddedEvent(com.faltenreich.diaguard.shared.event.data.EntryAddedEvent) FragmentCalculatorBinding(com.faltenreich.diaguard.databinding.FragmentCalculatorBinding) ToolbarDescribing(com.faltenreich.diaguard.feature.navigation.ToolbarDescribing) Events(com.faltenreich.diaguard.shared.event.Events) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) BloodSugar(com.faltenreich.diaguard.shared.data.database.entity.BloodSugar) View(android.view.View) Validator(com.faltenreich.diaguard.shared.data.validation.Validator) EntryEditFragment(com.faltenreich.diaguard.feature.entry.edit.EntryEditFragment) FoodEatenDao(com.faltenreich.diaguard.shared.data.database.dao.FoodEatenDao) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) FoodInputView(com.faltenreich.diaguard.feature.food.input.FoodInputView) Insulin(com.faltenreich.diaguard.shared.data.database.entity.Insulin) BaseFragment(com.faltenreich.diaguard.shared.view.fragment.BaseFragment) EntryDao(com.faltenreich.diaguard.shared.data.database.dao.EntryDao) LayoutInflater(android.view.LayoutInflater) UnitChangedEvent(com.faltenreich.diaguard.shared.event.preference.UnitChangedEvent) DateTime(org.joda.time.DateTime) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) StickyHintInputView(com.faltenreich.diaguard.shared.view.edittext.StickyHintInputView) MainButtonProperties(com.faltenreich.diaguard.feature.navigation.MainButtonProperties) BloodSugarPreferenceChangedEvent(com.faltenreich.diaguard.shared.event.preference.BloodSugarPreferenceChangedEvent) ThreadMode(org.greenrobot.eventbus.ThreadMode) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) R(com.faltenreich.diaguard.R) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Subscribe(org.greenrobot.eventbus.Subscribe) MeasurementDao(com.faltenreich.diaguard.shared.data.database.dao.MeasurementDao) ToolbarProperties(com.faltenreich.diaguard.feature.navigation.ToolbarProperties) MealFactorUnitChangedEvent(com.faltenreich.diaguard.shared.event.preference.MealFactorUnitChangedEvent) ViewGroup(android.view.ViewGroup) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) View(android.view.View) FoodInputView(com.faltenreich.diaguard.feature.food.input.FoodInputView) StickyHintInputView(com.faltenreich.diaguard.shared.view.edittext.StickyHintInputView) TextView(android.widget.TextView)

Example 10 with BloodSugar

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

the class DashboardValueTask method getBloodSugarOfToday.

private List<BloodSugar> getBloodSugarOfToday() {
    List<BloodSugar> bloodSugars = new ArrayList<>();
    List<Entry> entriesWithBloodSugar = EntryDao.getInstance().getAllWithMeasurementFromToday(BloodSugar.class);
    if (entriesWithBloodSugar != null) {
        for (Entry entry : entriesWithBloodSugar) {
            BloodSugar bloodSugar = (BloodSugar) MeasurementDao.getInstance(BloodSugar.class).getMeasurement(entry);
            if (bloodSugar != null) {
                bloodSugars.add(bloodSugar);
            }
        }
    }
    return bloodSugars;
}
Also used : Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) ArrayList(java.util.ArrayList) BloodSugar(com.faltenreich.diaguard.shared.data.database.entity.BloodSugar)

Aggregations

BloodSugar (com.faltenreich.diaguard.shared.data.database.entity.BloodSugar)10 Entry (com.faltenreich.diaguard.shared.data.database.entity.Entry)8 ArrayList (java.util.ArrayList)6 FoodEaten (com.faltenreich.diaguard.shared.data.database.entity.FoodEaten)5 Category (com.faltenreich.diaguard.shared.data.database.entity.Category)4 Meal (com.faltenreich.diaguard.shared.data.database.entity.Meal)4 Insulin (com.faltenreich.diaguard.shared.data.database.entity.Insulin)3 Measurement (com.faltenreich.diaguard.shared.data.database.entity.Measurement)3 DateTime (org.joda.time.DateTime)3 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 TextView (android.widget.TextView)2 FoodInputView (com.faltenreich.diaguard.feature.food.input.FoodInputView)2 EntryTag (com.faltenreich.diaguard.shared.data.database.entity.EntryTag)2 Tag (com.faltenreich.diaguard.shared.data.database.entity.Tag)2 List (java.util.List)2 AlertDialog (android.app.AlertDialog)1 Context (android.content.Context)1 Bundle (android.os.Bundle)1 ViewGroup (android.view.ViewGroup)1