Search in sources :

Example 1 with Theme

use of com.faltenreich.diaguard.shared.view.theme.Theme in project Diaguard by Faltenreich.

the class PreferenceStore method getTheme.

public Theme getTheme() {
    Theme themeDefault = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P ? Theme.SYSTEM : Theme.LIGHT;
    String themeKey = sharedPreferences.getString(getKey(R.string.preference_theme), null);
    if (themeKey != null) {
        Theme theme = Theme.fromKey(themeKey);
        return theme != null ? theme : themeDefault;
    } else {
        setTheme(themeDefault);
        return themeDefault;
    }
}
Also used : Theme(com.faltenreich.diaguard.shared.view.theme.Theme)

Example 2 with Theme

use of com.faltenreich.diaguard.shared.view.theme.Theme 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)

Example 3 with Theme

use of com.faltenreich.diaguard.shared.view.theme.Theme in project Diaguard by Faltenreich.

the class DiaguardApplication method init.

private void init() {
    context = getApplicationContext();
    JodaTimeAndroid.init(this);
    PreferenceStore.getInstance().init(this);
    Database.getInstance().init(this);
    new Import(this).importDataIfNeeded();
    PreferenceStore.getInstance().migrate();
    Migrator.getInstance().start();
    NotificationUtils.setupNotifications(this);
    Theme theme = PreferenceStore.getInstance().getTheme();
    ThemeUtils.setDefaultNightMode(theme);
    ThemeUtils.setUiMode(this, theme);
    ImageLoader.getInstance().init(this);
}
Also used : Import(com.faltenreich.diaguard.shared.data.database.importing.Import) Theme(com.faltenreich.diaguard.shared.view.theme.Theme)

Aggregations

Theme (com.faltenreich.diaguard.shared.view.theme.Theme)3 Import (com.faltenreich.diaguard.shared.data.database.importing.Import)1 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