MCPcopy Create free account
hub / github.com/FongMi/CatVodSpider / Prefers

Class Prefers

app/src/main/java/com/github/catvod/utils/Prefers.java:9–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import com.github.catvod.spider.Init;
8
9public class Prefers {
10
11 private static SharedPreferences getPrefers() {
12 return Init.context().getSharedPreferences(Init.context().getPackageName() + "_preferences", MODE_PRIVATE);
13 }
14
15 public static String getString(String key, String defaultValue) {
16 return getPrefers().getString(key, defaultValue);
17 }
18
19 public static String getString(String key) {
20 return getString(key, "");
21 }
22
23 public static int getInt(String key, int defaultValue) {
24 return getPrefers().getInt(key, defaultValue);
25 }
26
27 public static int getInt(String key) {
28 return getInt(key, 0);
29 }
30
31 public static boolean getBoolean(String key, boolean defaultValue) {
32 return getPrefers().getBoolean(key, defaultValue);
33 }
34
35 public static boolean getBoolean(String key) {
36 return getPrefers().getBoolean(key, false);
37 }
38
39 public static void put(String key, Object obj) {
40 if (obj == null) return;
41 if (obj instanceof String) {
42 getPrefers().edit().putString(key, (String) obj).apply();
43 } else if (obj instanceof Boolean) {
44 getPrefers().edit().putBoolean(key, (Boolean) obj).apply();
45 } else if (obj instanceof Float) {
46 getPrefers().edit().putFloat(key, (Float) obj).apply();
47 } else if (obj instanceof Integer) {
48 getPrefers().edit().putInt(key, (Integer) obj).apply();
49 } else if (obj instanceof Long) {
50 getPrefers().edit().putLong(key, (Long) obj).apply();
51 }
52 }
53}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected