wangzhibo
2026-08-30 af6b816e29ebe329c59cfdd368bf41d2a4940946
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
package com.jsbogang.womp.ble;
 
import android.content.Context;
import android.content.SharedPreferences;
 
import com.jsbogang.womp.workbench.WompConfig;
 
public final class DevicePrefs {
    private DevicePrefs() {}
 
    private static SharedPreferences p(Context c) {
        return c.getSharedPreferences(WompConfig.DEVICE_PREFS, Context.MODE_PRIVATE);
    }
 
    public static void bind(Context c, String mac, String name, String password, int watchDay) {
        p(c).edit()
                .putBoolean("bound", true)
                .putString("mac", mac == null ? "" : mac)
                .putString("name", name == null ? "" : name)
                .putString("password", password == null || password.isEmpty() ? "0000" : password)
                .putInt("watchDay", Math.max(watchDay, 1))
                .apply();
    }
 
    public static void unbind(Context c) {
        p(c).edit().clear().apply();
    }
 
    public static boolean isBound(Context c) {
        return p(c).getBoolean("bound", false) && !getMac(c).isEmpty();
    }
 
    public static String getMac(Context c) {
        return p(c).getString("mac", "");
    }
 
    public static String getName(Context c) {
        return p(c).getString("name", "");
    }
 
    public static String getPassword(Context c) {
        return p(c).getString("password", "0000");
    }
 
    public static int getWatchDay(Context c) {
        return p(c).getInt("watchDay", 3);
    }
 
    public static void setWatchDay(Context c, int watchDay) {
        p(c).edit().putInt("watchDay", Math.max(watchDay, 1)).apply();
    }
 
    public static void setLiveStep(Context c, int step) {
        String today = new java.text.SimpleDateFormat("yyyy-MM-dd", java.util.Locale.CHINA)
                .format(new java.util.Date());
        p(c).edit().putInt("liveStep", Math.max(step, 0)).putString("liveStepDate", today).apply();
    }
 
    public static int getLiveStep(Context c) {
        String today = new java.text.SimpleDateFormat("yyyy-MM-dd", java.util.Locale.CHINA)
                .format(new java.util.Date());
        if (!today.equals(p(c).getString("liveStepDate", ""))) {
            return 0;
        }
        return p(c).getInt("liveStep", 0);
    }
}