Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SettingsFragment.java « settings « ui « deck « nextcloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ea8d90f223aada6e5f8e4e8b93b0817fa4ddb1b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package it.niedermann.nextcloud.deck.ui.settings;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;

import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.persistence.sync.SyncWorker;
import it.niedermann.nextcloud.deck.ui.branding.Branded;
import it.niedermann.nextcloud.deck.ui.branding.BrandedSwitchPreference;

import static it.niedermann.nextcloud.deck.DeckApplication.setAppTheme;
import static it.niedermann.nextcloud.deck.ui.branding.BrandingUtil.readBrandMainColor;

public class SettingsFragment extends PreferenceFragmentCompat implements Branded {

    private BrandedSwitchPreference wifiOnlyPref;
    private BrandedSwitchPreference themePref;
    private BrandedSwitchPreference brandingPref;

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        setPreferencesFromResource(R.xml.settings, rootKey);

        wifiOnlyPref = findPreference(getString(R.string.pref_key_wifi_only));

        if (wifiOnlyPref != null) {
            wifiOnlyPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
                final Boolean syncOnWifiOnly = (Boolean) newValue;
                DeckLog.log("syncOnWifiOnly: " + syncOnWifiOnly);
                return true;
            });
        } else {
            DeckLog.error("Could not find preference with key: \"" + getString(R.string.pref_key_wifi_only) + "\"");
        }

        themePref = findPreference(getString(R.string.pref_key_dark_theme));
        if (themePref != null) {
            themePref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
                final Boolean darkTheme = (Boolean) newValue;
                DeckLog.log("darkTheme: " + darkTheme);
                setAppTheme(darkTheme);
                requireActivity().setResult(Activity.RESULT_OK);
                requireActivity().recreate();
                return true;
            });
        } else {
            DeckLog.error("Could not find preference with key: \"" + getString(R.string.pref_key_dark_theme) + "\"");
        }

        brandingPref = findPreference(getString(R.string.pref_key_branding));
        if (brandingPref != null) {
            brandingPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
                final Boolean branding = (Boolean) newValue;
                DeckLog.log("branding: " + branding);
                requireActivity().setResult(Activity.RESULT_OK);
                requireActivity().recreate();
                return true;
            });
        } else {
            DeckLog.error("Could not find preference with key: \"" + getString(R.string.pref_key_dark_theme) + "\"");
        }

        final ListPreference backgroundSyncPref = findPreference(getString(R.string.pref_key_background_sync));
        if (backgroundSyncPref != null) {
            backgroundSyncPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
                SyncWorker.update(requireContext().getApplicationContext(), (String) newValue);
                return true;
            });
        } else {
            DeckLog.error("Could not find preference with key: \"" + getString(R.string.pref_key_background_sync) + "\"");
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        @Nullable Context context = getContext();
        if (context != null) {
            applyBrand(readBrandMainColor(context));
        }
    }

    @Override
    public void applyBrand(int mainColor) {
        wifiOnlyPref.applyBrand(mainColor);
        themePref.applyBrand(mainColor);
        brandingPref.applyBrand(mainColor);
    }
}