wangzhibo
4 天以前 ae6f40460dcd56af6c5f60ba52c883854c3bac55
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*  Copyright (C) 2016-2024 Andreas Shimokawa, Anemograph, Carsten Pfeiffer,
    Daniel Dakhno, Daniele Gobbetti, Davis Mosenkovs, Dikay900, Felix Konstantin
    Maurer, José Rebelo, Petr Vaněk, Johannes Krude
 
    This file is part of Gadgetbridge.
 
    Gadgetbridge is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    Gadgetbridge is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
 
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.util.preferences;
 
import java.util.Locale;
 
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.*;
 
import android.content.SharedPreferences;
import android.text.format.DateFormat;
 
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
 
public class DevicePrefs extends Prefs {
    private GBDevice gbDevice;
 
    public DevicePrefs(final SharedPreferences preferences, GBDevice gbDevice) {
        super(preferences);
        this.gbDevice = gbDevice;
    }
 
    public boolean getBatteryShowInNotification(final int batteryIndex) {
        return getBoolean(PREF_BATTERY_SHOW_IN_NOTIFICATION + batteryIndex, true);
    }
 
    public boolean getBatteryNotifyLowEnabled(final BatteryConfig batteryConfig) {
        return getBoolean(PREF_BATTERY_NOTIFY_LOW_ENABLED + batteryConfig.getBatteryIndex(), true);
    }
 
    public int getBatteryNotifyLowThreshold(final BatteryConfig batteryConfig) {
        return getInt(PREF_BATTERY_NOTIFY_LOW_THRESHOLD + batteryConfig.getBatteryIndex(), batteryConfig.getDefaultLowThreshold());
    }
 
    public boolean getBatteryNotifyFullEnabled(final BatteryConfig batteryConfig) {
        return getBoolean(PREF_BATTERY_NOTIFY_FULL_ENABLED + batteryConfig.getBatteryIndex(), true);
    }
 
    public int getBatteryNotifyFullThreshold(final BatteryConfig batteryConfig) {
        return getInt(PREF_BATTERY_NOTIFY_FULL_THRESHOLD + batteryConfig.getBatteryIndex(), batteryConfig.getDefaultFullThreshold());
    }
 
    public boolean getBatteryPollingEnabled() {
        return getBoolean(PREF_BATTERY_POLLING_ENABLE, true);
    }
 
    public int getBatteryPollingIntervalMinutes() {
        return getInt(PREF_BATTERY_POLLING_INTERVAL, 15);
    }
 
    public boolean getFetchUnknownFiles() {
        return getBoolean("fetch_unknown_files", false);
    }
 
    public String getTimeFormat() {
        String timeFormat = getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO);
        if (DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO.equals(timeFormat)) {
            if (DateFormat.is24HourFormat(GBApplication.getContext())) {
                timeFormat = DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H;
            } else {
                timeFormat = DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_12H;
            }
        }
 
        return timeFormat;
    }
 
    public String getDateFormatDayMonthOrder() {
        String dateFormat = getString(DeviceSettingsPreferenceConst.PREF_DATEFORMAT, DeviceSettingsPreferenceConst.PREF_DATEFORMAT_AUTO);
        if (DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO.equals(dateFormat)) {
            String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), "dM");
            boolean quoted = false;
            for (char c: pattern.toCharArray()) {
                if (c == '\'') {
                    quoted = !quoted;
                    continue;
                }
                if (quoted)
                    continue;
                if (c == 'd')
                    return DeviceSettingsPreferenceConst.PREF_DATEFORMAT_DAY_MONTH;
                if (c == 'M' || c == 'L')
                    return DeviceSettingsPreferenceConst.PREF_DATEFORMAT_MONTH_DAY;
            }
            return DeviceSettingsPreferenceConst.PREF_DATEFORMAT_DAY_MONTH;
        }
 
        return dateFormat;
    }
 
    public int getReservedReminderCalendarSlots() {
        if (!gbDevice.getDeviceCoordinator().getReserveReminderSlotsForCalendar())
            return 0;
        if (!getBoolean(DeviceSettingsPreferenceConst.PREF_SYNC_CALENDAR, false))
            return 0;
        return getInt(DeviceSettingsPreferenceConst.PREF_RESERVE_REMINDERS_CALENDAR, 9);
    }
 
}