Search in sources :

Example 1 with UnitChangedEvent

use of com.faltenreich.diaguard.shared.event.preference.UnitChangedEvent in project Diaguard by Faltenreich.

the class PreferenceFragment method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (!isAdded()) {
        return;
    }
    if (key.equals(getString(R.string.preference_unit_bloodsugar))) {
        Events.post(new UnitChangedEvent(Category.BLOODSUGAR));
    } else if (key.equals(getString(R.string.preference_unit_meal))) {
        Events.post(new UnitChangedEvent(Category.MEAL));
    } else if (key.equals(getString(R.string.preference_unit_meal_factor))) {
        Events.post(new MealFactorUnitChangedEvent());
    } else if (key.equals(getString(R.string.preference_unit_hba1c))) {
        Events.post(new UnitChangedEvent(Category.HBA1C));
    } else if (key.equals(getString(R.string.preference_unit_weight))) {
        Events.post(new UnitChangedEvent(Category.WEIGHT));
    } else if (key.equals(getString(R.string.preference_timeline_show_dots)) || key.equals(getString(R.string.preference_timeline_show_lines))) {
        Events.post(new TimelinePreferenceChangedEvent());
    } else if (key.equals(getString(R.string.preference_theme))) {
        Theme theme = PreferenceStore.getInstance().getTheme();
        ThemeUtils.setDefaultNightMode(theme);
        ThemeUtils.setUiMode(getActivity(), theme);
    } else if (key.equals(getString(R.string.preference_decimal_places))) {
        int decimalPlaces = PreferenceStore.getInstance().getDecimalPlaces();
        PreferenceCache.getInstance().setDecimalPlaces(decimalPlaces);
    }
}
Also used : MealFactorUnitChangedEvent(com.faltenreich.diaguard.shared.event.preference.MealFactorUnitChangedEvent) Theme(com.faltenreich.diaguard.shared.view.theme.Theme) TimelinePreferenceChangedEvent(com.faltenreich.diaguard.shared.event.preference.TimelinePreferenceChangedEvent) UnitChangedEvent(com.faltenreich.diaguard.shared.event.preference.UnitChangedEvent) MealFactorUnitChangedEvent(com.faltenreich.diaguard.shared.event.preference.MealFactorUnitChangedEvent)

Aggregations

MealFactorUnitChangedEvent (com.faltenreich.diaguard.shared.event.preference.MealFactorUnitChangedEvent)1 TimelinePreferenceChangedEvent (com.faltenreich.diaguard.shared.event.preference.TimelinePreferenceChangedEvent)1 UnitChangedEvent (com.faltenreich.diaguard.shared.event.preference.UnitChangedEvent)1 Theme (com.faltenreich.diaguard.shared.view.theme.Theme)1