Fix config bugs
This commit is contained in:
parent
ecf3d30349
commit
650b2ce6b1
@ -239,19 +239,19 @@ public class Config {
|
|||||||
App app = App.self;
|
App app = App.self;
|
||||||
switch (getConfigType(key)) {
|
switch (getConfigType(key)) {
|
||||||
case PREF_INT:
|
case PREF_INT:
|
||||||
return (T) (Integer) app.prefs.getInt(key, 0);
|
return (T) (Integer) app.prefs.getInt(key, getDef(key));
|
||||||
case PREF_STR_INT:
|
case PREF_STR_INT:
|
||||||
return (T) (Integer) Utils.getPrefsInt(app.prefs, key, 0);
|
return (T) (Integer) Utils.getPrefsInt(app.prefs, key, getDef(key));
|
||||||
case PREF_BOOL:
|
case PREF_BOOL:
|
||||||
return (T) (Boolean) app.prefs.getBoolean(key, false);
|
return (T) (Boolean) app.prefs.getBoolean(key, getDef(key));
|
||||||
case PREF_STR:
|
case PREF_STR:
|
||||||
return (T) app.prefs.getString(key, null);
|
return (T) app.prefs.getString(key, getDef(key));
|
||||||
case DB_INT:
|
case DB_INT:
|
||||||
return (T) (Integer) app.mDB.getSettings(key, 0);
|
return (T) (Integer) app.mDB.getSettings(key, getDef(key));
|
||||||
case DB_BOOL:
|
case DB_BOOL:
|
||||||
return (T) (Boolean) (app.mDB.getSettings(key, 0) != 0);
|
return (T) (Boolean) (app.mDB.getSettings(key, getDef(key) ? 1 : 0) != 0);
|
||||||
case DB_STR:
|
case DB_STR:
|
||||||
return (T) app.mDB.getStrings(key, null);
|
return (T) app.mDB.getStrings(key, getDef(key));
|
||||||
}
|
}
|
||||||
/* Will never get here (IllegalArgumentException in getConfigType) */
|
/* Will never get here (IllegalArgumentException in getConfigType) */
|
||||||
return null;
|
return null;
|
||||||
@ -342,6 +342,24 @@ public class Config {
|
|||||||
//defs.put(Key.SU_MANAGER, null);
|
//defs.put(Key.SU_MANAGER, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static <T> T getDef(String key) {
|
||||||
|
Object val = defs.get(key);
|
||||||
|
switch (getConfigType(key)) {
|
||||||
|
case PREF_INT:
|
||||||
|
case DB_INT:
|
||||||
|
case PREF_STR_INT:
|
||||||
|
return val != null ? (T) val : (T) (Integer) 0;
|
||||||
|
case DB_BOOL:
|
||||||
|
case PREF_BOOL:
|
||||||
|
return val != null ? (T) val : (T) (Boolean) false;
|
||||||
|
case DB_STR:
|
||||||
|
case PREF_STR:
|
||||||
|
return (T) val;
|
||||||
|
}
|
||||||
|
/* Will never get here (IllegalArgumentException in getConfigType) */
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static void setDefs(SharedPreferences pref, SharedPreferences.Editor editor) {
|
private static void setDefs(SharedPreferences pref, SharedPreferences.Editor editor) {
|
||||||
App app = App.self;
|
App app = App.self;
|
||||||
for (String key : defs.keySet()) {
|
for (String key : defs.keySet()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user