use of com.faltenreich.diaguard.shared.data.database.entity.Category in project Diaguard by Faltenreich.
the class TimelineDayFragment method invalidateData.
private void invalidateData() {
if (getContext() == null) {
return;
}
if (data.needsChartData()) {
Log.d(TAG, "Invalidating data for chart on " + data.getDay().toString());
DataLoader.getInstance().load(getContext(), new DataLoaderListener<DayChartData>() {
@Override
public DayChartData onShouldLoad(Context context) {
List<Measurement> values = new ArrayList<>();
List<Entry> entries = EntryDao.getInstance().getEntriesOfDay(data.getDay());
if (entries != null && entries.size() > 0) {
for (Entry entry : entries) {
// TODO: Improve performance by using transaction / bulk fetch
List<Measurement> measurements = EntryDao.getInstance().getMeasurements(entry, new Category[] { Category.BLOODSUGAR });
values.addAll(measurements);
}
}
return new DayChartData(context, PreferenceStore.getInstance().showDotsInTimeline(), PreferenceStore.getInstance().showLinesInTimeline(), values);
}
@Override
public void onDidLoad(DayChartData chartData) {
data.setChartData(chartData);
invalidateChart();
}
});
} else {
invalidateChart();
}
if (data.needsListData()) {
Log.d(TAG, "Invalidating data for list on " + data.getDay().toString());
DataLoader.getInstance().load(getContext(), new DataLoaderListener<List<CategoryValueListItem>>() {
@Override
public List<CategoryValueListItem> onShouldLoad(Context context) {
List<CategoryValueListItem> listItems = new ArrayList<>();
LinkedHashMap<Category, CategoryValueListItem[]> values = EntryDao.getInstance().getAverageDataTable(data.getDay(), categories, SKIP_EVERY_X_HOUR);
for (Map.Entry<Category, CategoryValueListItem[]> mapEntry : values.entrySet()) {
Collections.addAll(listItems, mapEntry.getValue());
}
return listItems;
}
@Override
public void onDidLoad(List<CategoryValueListItem> listData) {
data.setListData(listData);
invalidateList();
}
});
} else {
invalidateList();
}
}
use of com.faltenreich.diaguard.shared.data.database.entity.Category in project Diaguard by Faltenreich.
the class CategoryValueViewHolder method showUnit.
private void showUnit() {
Category category = getItem().getCategory();
String unitAcronym = PreferenceStore.getInstance().getUnitName(category);
ViewUtils.showToast(getContext(), unitAcronym);
}
use of com.faltenreich.diaguard.shared.data.database.entity.Category in project Diaguard by Faltenreich.
the class EntryEditFragment method initLayout.
private void initLayout() {
dateButton.setOnClickListener(view -> showDatePicker());
timeButton.setOnClickListener(view -> showTimePicker());
tagInput.setAdapter(tagAdapter);
tagInput.setOnEditorActionListener((textView, action, keyEvent) -> {
if (action == EditorInfo.IME_ACTION_DONE) {
String name = textView.getText().toString().trim();
if (!StringUtils.isBlank(name)) {
addTag(name);
textView.setText(null);
}
return true;
}
return false;
});
tagInput.setOnFocusChangeListener((view, hasFocus) -> {
// Attempt to fix android.view.WindowManager$BadTokenException
new Handler().post(() -> {
try {
if (hasFocus)
tagInput.showDropDown();
} catch (Exception exception) {
Log.e(TAG, exception.toString());
}
});
});
tagInput.setOnClickListener(view -> tagInput.showDropDown());
tagInput.setOnItemClickListener((adapterView, view, position, l) -> {
tagInput.setText(null);
addTag(tagAdapter.getItem(position));
});
tagListView.setVisibility(View.GONE);
tagEditButton.setOnClickListener(view -> openTagSettings());
EditTextUtils.afterTextChanged(noteInput, () -> viewModel.getEntry().setNote(noteInput.getText().toString()));
alarmContainer.setVisibility(viewModel.isEditing() ? View.GONE : View.VISIBLE);
alarmButton.setOnClickListener(view -> showAlarmPicker());
fabMenu.setOnCategorySelectedListener((category -> addCategory(category, true)));
fabMenu.setOnMiscellaneousSelectedListener(this::openCategoryPicker);
invalidateAlarm();
}
use of com.faltenreich.diaguard.shared.data.database.entity.Category in project Diaguard by Faltenreich.
the class EntryEditFragment method setEntry.
private void setEntry(@NonNull Entry entry) {
noteInput.setText(entry.getNote());
// FIXME: Previous order gets ignored on Fragment recreation
List<Measurement> measurements = entry.getMeasurementCache();
if (measurements != null && !measurements.isEmpty()) {
Collections.sort(measurements, CategoryComparatorFactory.getInstance().createComparatorFromMeasurements());
for (Measurement measurement : measurements) {
addMeasurement(measurement, false);
}
} else if (!entry.isPersisted() && !isRecreated) {
for (Category category : viewModel.getPinnedCategories()) {
if (!hasCategory(category)) {
addCategory(category, false);
}
}
}
if (viewModel.getEntryTags() != null) {
for (EntryTag entryTag : viewModel.getEntryTags()) {
Tag tag = entryTag.getTag();
if (tag != null) {
addTag(entryTag.getTag());
}
}
}
invalidateDateTime();
fabMenu.restock();
}
use of com.faltenreich.diaguard.shared.data.database.entity.Category in project Diaguard by Faltenreich.
the class MeasurementFloatingActionMenu method restock.
public void restock() {
removeAllMenuButtons();
Category[] activeCategories = PreferenceStore.getInstance().getActiveCategories();
int menuButtonCount = 0;
int position = 0;
while (position < activeCategories.length && menuButtonCount < MAX_BUTTON_COUNT) {
Category category = activeCategories[position];
if (!categoriesToSkip.contains(category)) {
addMenuButton(category);
menuButtonCount++;
}
position++;
}
FloatingActionButton fabAll = FloatingActionButtonFactory.createFloatingActionButton(getContext(), getContext().getString(R.string.all), R.drawable.ic_more, ColorUtils.getBackgroundSecondary(getContext()));
addMenuButton(fabAll);
fabAll.setOnClickListener(view -> {
close(true);
if (onMiscellaneousSelectedListener != null) {
onMiscellaneousSelectedListener.onMiscellaneousSelected();
}
});
}
Aggregations