Search in sources :

Example 1 with MeasurementView

use of com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView in project Diaguard by Faltenreich.

the class EntryEditFragment method inputIsValid.

private boolean inputIsValid() {
    boolean inputIsValid = true;
    List<Measurement> measurements = viewModel.getMeasurements();
    if (measurements.isEmpty()) {
        // Allow entries with no measurements but with a note or tag
        if (StringUtils.isBlank(viewModel.getEntry().getNote()) && tagListView.getChildCount() == 0) {
            ViewUtils.showSnackbar(root, getString(R.string.validator_value_none));
            inputIsValid = false;
        }
    } else {
        for (int index = 0; index < measurementContainer.getChildCount(); index++) {
            View view = measurementContainer.getChildAt(index);
            if (view instanceof MeasurementView<?>) {
                MeasurementView<?> measurementView = (MeasurementView<?>) view;
                if (!measurementView.getInputView().isValid()) {
                    inputIsValid = false;
                }
            }
        }
    }
    return inputIsValid;
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) MeasurementView(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView) MeasurementView(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView) NestedScrollView(androidx.core.widget.NestedScrollView) ImageView(android.widget.ImageView) View(android.view.View) ChipView(com.faltenreich.diaguard.shared.view.chip.ChipView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 2 with MeasurementView

use of com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView in project Diaguard by Faltenreich.

the class EntryEditFragment method getFoodEaten.

private List<FoodEaten> getFoodEaten() {
    for (int index = 0; index < measurementContainer.getChildCount(); index++) {
        View view = measurementContainer.getChildAt(index);
        if (view instanceof MeasurementView) {
            MeasurementView<?> measurementView = ((MeasurementView<?>) view);
            Measurement measurement = measurementView.getMeasurement();
            if (measurement instanceof Meal) {
                List<FoodEaten> foodEatenList = new ArrayList<>();
                for (FoodEaten foodEaten : ((Meal) measurement).getFoodEatenCache()) {
                    if (foodEaten.isValid()) {
                        foodEatenList.add(foodEaten);
                    }
                }
                return foodEatenList;
            }
        }
    }
    return new ArrayList<>();
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) MeasurementView(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) ArrayList(java.util.ArrayList) MeasurementView(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView) NestedScrollView(androidx.core.widget.NestedScrollView) ImageView(android.widget.ImageView) View(android.view.View) ChipView(com.faltenreich.diaguard.shared.view.chip.ChipView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Aggregations

View (android.view.View)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 ImageView (android.widget.ImageView)2 NestedScrollView (androidx.core.widget.NestedScrollView)2 MeasurementView (com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView)2 Measurement (com.faltenreich.diaguard.shared.data.database.entity.Measurement)2 ChipView (com.faltenreich.diaguard.shared.view.chip.ChipView)2 FoodEaten (com.faltenreich.diaguard.shared.data.database.entity.FoodEaten)1 Meal (com.faltenreich.diaguard.shared.data.database.entity.Meal)1 ArrayList (java.util.ArrayList)1