Skip to content
This repository was archived by the owner on Oct 26, 2023. It is now read-only.

Commit 4cd8bc1

Browse files
committed
convert old preferences
1 parent 21fde10 commit 4cd8bc1

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

app/src/main/java/com/james/status/Status.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import android.app.Application;
44
import android.content.Context;
55
import android.content.Intent;
6+
import android.content.SharedPreferences;
7+
import android.preference.PreferenceManager;
68
import android.support.annotation.Nullable;
79
import android.util.Log;
810
import android.widget.Toast;
@@ -12,6 +14,7 @@
1214

1315
import java.util.ArrayList;
1416
import java.util.List;
17+
import java.util.Map;
1518

1619
public class Status extends Application {
1720

@@ -26,6 +29,70 @@ public void onCreate() {
2629
onActivityResultListeners = new ArrayList<>();
2730
onColorPickedListeners = new ArrayList<>();
2831
onIconPreferenceChangedListeners = new ArrayList<>();
32+
33+
if ((int) PreferenceData.LAST_PREF_VERSION.getValue(this) == 0) {
34+
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
35+
Map<String, ?> items = prefs.getAll();
36+
SharedPreferences.Editor editor = prefs.edit();
37+
for (String key : items.keySet()) {
38+
if (key.startsWith("COLOR/")) {
39+
String[] packages = key.substring("COLOR/".length()).split("/");
40+
if (packages.length == 2 && prefs.contains("COLOR/" + packages[0] + "/" + packages[1])) {
41+
try {
42+
PreferenceData.APP_COLOR.setValue(this, prefs.getInt(key, 0), packages[0] + "/" + packages[1]);
43+
} catch (Exception ignored) {
44+
}
45+
}
46+
} else if (key.startsWith("CACHE_COLOR/")) {
47+
String[] packages = key.substring("CACHE_COLOR/".length()).split("/");
48+
if (packages.length == 2 && prefs.contains("CACHE_COLOR/" + packages[0] + "/" + packages[1])) {
49+
try {
50+
PreferenceData.APP_COLOR_CACHE.setValue(this, prefs.getInt(key, 0), packages[0] + "/" + packages[1]);
51+
} catch (Exception ignored) {
52+
}
53+
}
54+
} else if (key.startsWith("CACHE_VERSION/")) {
55+
String[] packages = key.substring("CACHE_VERSION/".length()).split("/");
56+
if (packages.length == 2 && prefs.contains("CACHE_VERSION/" + packages[0] + "/" + packages[1])) {
57+
try {
58+
PreferenceData.APP_COLOR_CACHE_VERSION.setValue(this, prefs.getInt(key, 0), packages[0] + "/" + packages[1]);
59+
} catch (Exception ignored) {
60+
}
61+
}
62+
} else if (key.startsWith("FULLSCREEN/")) {
63+
String[] packages = key.substring("FULLSCREEN/".length()).split("/");
64+
if (packages.length == 2 && prefs.contains("FULLSCREEN/" + packages[0] + "/" + packages[1])) {
65+
try {
66+
if (prefs.getBoolean(key, false))
67+
PreferenceData.APP_FULLSCREEN.setValue(this, true, packages[0] + "/" + packages[1]);
68+
} catch (Exception ignored) {
69+
}
70+
}
71+
} else if (key.startsWith("IGNORE_AUTO_DETECT/")) {
72+
String[] packages = key.substring("IGNORE_AUTO_DETECT/".length()).split("/");
73+
if (packages.length == 2 && prefs.contains("IGNORE_AUTO_DETECT/" + packages[0] + "/" + packages[1])) {
74+
try {
75+
if (prefs.getBoolean(key, false))
76+
PreferenceData.APP_FULLSCREEN.setValue(this, true, packages[0] + "/" + packages[1]);
77+
} catch (Exception ignored) {
78+
}
79+
}
80+
} else if (key.startsWith("NOTIFICATIONS/")) {
81+
String[] packages = key.substring("NOTIFICATIONS/".length()).split("/");
82+
if (packages.length == 2 && prefs.contains("NOTIFICATIONS/" + packages[0] + "/" + packages[1])) {
83+
try {
84+
if (!prefs.getBoolean(key, true))
85+
PreferenceData.APP_NOTIFICATIONS.setValue(this, false, packages[0] + "/" + packages[1]);
86+
} catch (Exception ignored) {
87+
}
88+
}
89+
} else continue;
90+
91+
editor.remove(key);
92+
}
93+
editor.putInt("LAST_PREF_VERSION", PreferenceData.PREF_VERSION);
94+
editor.apply();
95+
}
2996
}
3097

3198
public void addListener(OnActivityResultListener listener) {

0 commit comments

Comments
 (0)