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;
}
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]);
}
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();
}
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);
}
}
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);
}
Aggregations