Search in sources :

Example 26 with Category

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

the class EntryDao method getMeasurements.

public List<Measurement> getMeasurements(Entry entry, Category[] categories) {
    List<Measurement> measurements = new ArrayList<>();
    for (Category category : categories) {
        Measurement measurement = MeasurementDao.getInstance(category.toClass()).getMeasurement(entry);
        if (measurement != null) {
            measurements.add(measurement);
        }
    }
    Collections.sort(measurements, CategoryComparatorFactory.getInstance().createComparatorFromMeasurements());
    return measurements;
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) ArrayList(java.util.ArrayList)

Example 27 with Category

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

the class PreferenceStore method getActiveCategories.

public Category[] getActiveCategories(@Nullable Category excluded) {
    List<Category> sortedCategories = getSortedCategories();
    List<Category> activeCategories = new ArrayList<>();
    for (Category category : sortedCategories) {
        if (category != excluded && isCategoryActive(category)) {
            activeCategories.add(category);
        }
    }
    return activeCategories.toArray(new Category[0]);
}
Also used : Category(com.faltenreich.diaguard.shared.data.database.entity.Category) ArrayList(java.util.ArrayList)

Example 28 with Category

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

the class EntryEditFragment method openCategoryPicker.

private void openCategoryPicker() {
    Category[] activeCategories = viewModel.getActiveCategories();
    String[] categoryNames = new String[activeCategories.length];
    boolean[] visibleCategoriesOld = new boolean[activeCategories.length];
    for (int position = 0; position < activeCategories.length; position++) {
        Category category = activeCategories[position];
        categoryNames[position] = getString(category.getStringResId());
        visibleCategoriesOld[position] = hasCategory(category);
    }
    boolean[] visibleCategories = visibleCategoriesOld.clone();
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle(R.string.categories).setMultiChoiceItems(categoryNames, visibleCategoriesOld, (dialog, which, isChecked) -> visibleCategories[which] = isChecked).setPositiveButton(getString(R.string.ok), (dialog, which) -> {
        for (int position = activeCategories.length - 1; position >= 0; position--) {
            Category category = activeCategories[position];
            if (visibleCategories[position]) {
                scrollView.smoothScrollTo(0, 0);
                if (!hasCategory(category)) {
                    addCategory(category, true);
                }
            } else {
                removeCategory(category);
            }
        }
    }).setNegativeButton(getString(R.string.cancel), (dialog, which) -> dialog.cancel()).setNeutralButton(R.string.settings, (dialog, which) -> openCategorySettings());
    AlertDialog dialog = builder.create();
    dialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) MeasurementView(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) FoodSearchEvent(com.faltenreich.diaguard.shared.event.ui.FoodSearchEvent) NestedScrollView(androidx.core.widget.NestedScrollView) NonNull(androidx.annotation.NonNull) EntryTagDao(com.faltenreich.diaguard.shared.data.database.dao.EntryTagDao) ImageView(android.widget.ImageView) FoodSearchFragment(com.faltenreich.diaguard.feature.food.search.FoodSearchFragment) Tag(com.faltenreich.diaguard.shared.data.database.entity.Tag) Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Food(com.faltenreich.diaguard.shared.data.database.entity.Food) Handler(android.os.Handler) View(android.view.View) Button(android.widget.Button) Log(android.util.Log) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) CategoryComparatorFactory(com.faltenreich.diaguard.feature.category.CategoryComparatorFactory) BaseFragment(com.faltenreich.diaguard.shared.view.fragment.BaseFragment) EntryDao(com.faltenreich.diaguard.shared.data.database.dao.EntryDao) FragmentEntryEditBinding(com.faltenreich.diaguard.databinding.FragmentEntryEditBinding) TimePickerFragment(com.faltenreich.diaguard.feature.datetime.TimePickerFragment) ChipView(com.faltenreich.diaguard.shared.view.chip.ChipView) ThreadMode(org.greenrobot.eventbus.ThreadMode) NumberPickerDialog(com.faltenreich.diaguard.shared.view.picker.NumberPickerDialog) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) R(com.faltenreich.diaguard.R) StringUtils(com.faltenreich.diaguard.shared.data.primitive.StringUtils) List(java.util.List) Nullable(androidx.annotation.Nullable) EditorInfo(android.view.inputmethod.EditorInfo) AlarmUtils(com.faltenreich.diaguard.feature.alarm.AlarmUtils) MainButton(com.faltenreich.diaguard.feature.navigation.MainButton) LocalTime(org.joda.time.LocalTime) ChipGroup(com.google.android.material.chip.ChipGroup) TagDao(com.faltenreich.diaguard.shared.data.database.dao.TagDao) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Helper(com.faltenreich.diaguard.shared.Helper) EntryDeletedEvent(com.faltenreich.diaguard.shared.event.data.EntryDeletedEvent) EntryAddedEvent(com.faltenreich.diaguard.shared.event.data.EntryAddedEvent) ToolbarDescribing(com.faltenreich.diaguard.feature.navigation.ToolbarDescribing) Events(com.faltenreich.diaguard.shared.event.Events) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) Menu(android.view.Menu) TagAutoCompleteAdapter(com.faltenreich.diaguard.feature.tag.TagAutoCompleteAdapter) DatePickerFragment(com.faltenreich.diaguard.feature.datetime.DatePickerFragment) TagListFragment(com.faltenreich.diaguard.feature.tag.TagListFragment) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag) ViewUtils(com.faltenreich.diaguard.shared.view.ViewUtils) LayoutInflater(android.view.LayoutInflater) ObjectFactory(com.faltenreich.diaguard.shared.data.reflect.ObjectFactory) DateTime(org.joda.time.DateTime) MeasurementFloatingActionMenu(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementFloatingActionMenu) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) MainButtonProperties(com.faltenreich.diaguard.feature.navigation.MainButtonProperties) AutoCompleteTextView(android.widget.AutoCompleteTextView) Subscribe(org.greenrobot.eventbus.Subscribe) MeasurementDao(com.faltenreich.diaguard.shared.data.database.dao.MeasurementDao) EntryUpdatedEvent(com.faltenreich.diaguard.shared.event.data.EntryUpdatedEvent) ToolbarProperties(com.faltenreich.diaguard.feature.navigation.ToolbarProperties) EditTextUtils(com.faltenreich.diaguard.shared.view.edittext.EditTextUtils) CategoryListFragment(com.faltenreich.diaguard.feature.category.CategoryListFragment) Collections(java.util.Collections) EditText(android.widget.EditText) DateTimeConstants(org.joda.time.DateTimeConstants) Category(com.faltenreich.diaguard.shared.data.database.entity.Category)

Example 29 with Category

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

the class CategoryComparatorFactory method invalidate.

public void invalidate() {
    sortCache = new HashMap<>();
    Comparator<Category> comparator = (first, second) -> PreferenceStore.getInstance().getCategorySortIndex(first) - PreferenceStore.getInstance().getCategorySortIndex(second);
    List<Category> categories = PreferenceStore.getInstance().getSortedCategories(comparator);
    for (int sortIndex = 0; sortIndex < categories.size(); sortIndex++) {
        Category category = categories.get(sortIndex);
        sortCache.put(category, sortIndex);
    }
}
Also used : List(java.util.List) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) PreferenceStore(com.faltenreich.diaguard.feature.preference.data.PreferenceStore) HashMap(java.util.HashMap) Comparator(java.util.Comparator) Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Category(com.faltenreich.diaguard.shared.data.database.entity.Category)

Example 30 with Category

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

the class MeasurementView method initLayout.

private void initLayout() {
    Category category = measurement.getCategory();
    setRadius(getContext().getResources().getDimension(R.dimen.card_corner_radius));
    setCardElevation(getContext().getResources().getDimension(R.dimen.card_elevation));
    setUseCompatPadding(true);
    setOnTouchListener(new SwipeDismissTouchListener(this, null, new SwipeDismissTouchListener.DismissCallbacks() {

        @Override
        public boolean canDismiss(Object token) {
            return true;
        }

        @Override
        public void onDismiss(View view, Object token) {
            remove();
        }
    }));
    deleteButton.setOnClickListener((view) -> remove());
    pinnedCheckbox.setChecked(PreferenceStore.getInstance().isCategoryPinned(category));
    pinnedCheckbox.setOnCheckedChangeListener((checkbox, isChecked) -> togglePinnedCategory(isChecked));
    pinnedCheckbox.setSaveEnabled(false);
    String categoryName = getContext().getString(category.getStringResId());
    showcaseImageView.setImageResource(category.getShowcaseImageResourceId());
    categoryImageView.setImageResource(category.getIconImageResourceId());
    categoryLabel.setText(categoryName);
    deleteButton.setContentDescription(String.format(getContext().getString(R.string.remove_placeholder), categoryName));
    contentLayout.addView(inputView);
}
Also used : Category(com.faltenreich.diaguard.shared.data.database.entity.Category) SwipeDismissTouchListener(com.faltenreich.diaguard.shared.view.swipe.SwipeDismissTouchListener) GenericInputView(com.faltenreich.diaguard.feature.entry.edit.input.GenericInputView) PressureInputView(com.faltenreich.diaguard.feature.entry.edit.input.PressureInputView) ImageView(android.widget.ImageView) InsulinInputView(com.faltenreich.diaguard.feature.entry.edit.input.InsulinInputView) View(android.view.View) CardView(androidx.cardview.widget.CardView) MeasurementInputView(com.faltenreich.diaguard.feature.entry.edit.input.MeasurementInputView) MealInputView(com.faltenreich.diaguard.feature.entry.edit.input.MealInputView) TextView(android.widget.TextView)

Aggregations

Category (com.faltenreich.diaguard.shared.data.database.entity.Category)31 ArrayList (java.util.ArrayList)18 Measurement (com.faltenreich.diaguard.shared.data.database.entity.Measurement)15 Entry (com.faltenreich.diaguard.shared.data.database.entity.Entry)13 List (java.util.List)10 EntryTag (com.faltenreich.diaguard.shared.data.database.entity.EntryTag)7 FoodEaten (com.faltenreich.diaguard.shared.data.database.entity.FoodEaten)7 Meal (com.faltenreich.diaguard.shared.data.database.entity.Meal)7 Tag (com.faltenreich.diaguard.shared.data.database.entity.Tag)7 View (android.view.View)6 ImageView (android.widget.ImageView)5 CategoryValueListItem (com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem)5 Context (android.content.Context)4 Point (com.pdfjet.Point)4 DateTime (org.joda.time.DateTime)4 LayoutInflater (android.view.LayoutInflater)3 LinearLayout (android.widget.LinearLayout)3 TextView (android.widget.TextView)3 CellBuilder (com.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder)3 BloodSugar (com.faltenreich.diaguard.shared.data.database.entity.BloodSugar)3