Search in sources :

Example 1 with Category

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();
    }
}
Also used : Context(android.content.Context) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) DayChartData(com.faltenreich.diaguard.feature.timeline.chart.DayChartData) ArrayList(java.util.ArrayList) List(java.util.List) CategoryValueListItem(com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with Category

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);
}
Also used : Category(com.faltenreich.diaguard.shared.data.database.entity.Category)

Example 3 with Category

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();
}
Also used : 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) Handler(android.os.Handler)

Example 4 with Category

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();
}
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) Tag(com.faltenreich.diaguard.shared.data.database.entity.Tag) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag)

Example 5 with Category

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();
        }
    });
}
Also used : Category(com.faltenreich.diaguard.shared.data.database.entity.Category) FloatingActionButton(com.github.clans.fab.FloatingActionButton)

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