1
0
Fork 0

settings code cleanup

This commit is contained in:
sspanak 2024-04-05 15:51:33 +03:00 committed by Dimo Karaivanov
parent a09e6f65e7
commit ca6b0badc9
5 changed files with 17 additions and 37 deletions

View file

@ -16,4 +16,12 @@ class BaseSettings {
prefs = PreferenceManager.getDefaultSharedPreferences(context); prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefsEditor = prefs.edit(); prefsEditor = prefs.edit();
} }
protected int getStringifiedInt(String key, int defaultValue) {
try {
return Integer.parseInt(prefs.getString(key, String.valueOf(defaultValue)));
} catch (NumberFormatException ignored) {
return defaultValue;
}
}
} }

View file

@ -11,19 +11,11 @@ class SettingsHacks extends BaseSettings {
/************* debugging settings *************/ /************* debugging settings *************/
public int getLogLevel() { public int getLogLevel() {
try { return getStringifiedInt("pref_log_level", Logger.LEVEL);
return Integer.parseInt(prefs.getString("pref_log_level", String.valueOf(Logger.LEVEL)));
} catch (NumberFormatException ignored) {
return Logger.LEVEL;
}
} }
public int getInputHandlingMode() { public int getInputHandlingMode() {
try { return getStringifiedInt("pref_input_handling_mode", ItemInputHandlingMode.NORMAL);
return Integer.parseInt(prefs.getString("pref_input_handling_mode", String.valueOf(ItemInputHandlingMode.NORMAL)));
} catch (NumberFormatException ignored) {
return ItemInputHandlingMode.NORMAL;
}
} }
@ -49,10 +41,6 @@ class SettingsHacks extends BaseSettings {
*/ */
public int getKeyPadDebounceTime() { public int getKeyPadDebounceTime() {
try { return getStringifiedInt("pref_key_pad_debounce_time", 0);
return Integer.parseInt(prefs.getString("pref_key_pad_debounce_time", "0"));
} catch (NumberFormatException e) {
return 0;
}
} }
} }

View file

@ -38,14 +38,12 @@ class SettingsHotkeys extends SettingsHacks {
.apply(); .apply();
} }
public int getFunctionKey(String functionName) { public int getFunctionKey(String functionName) {
try { return getStringifiedInt(functionName, 0);
return Integer.parseInt(prefs.getString(functionName, "0"));
} catch (NumberFormatException e) {
return 0;
}
} }
public int getKeyAddWord() { public int getKeyAddWord() {
return getFunctionKey(SectionKeymap.ITEM_ADD_WORD); return getFunctionKey(SectionKeymap.ITEM_ADD_WORD);
} }

View file

@ -6,13 +6,7 @@ class SettingsTyping extends SettingsInput {
SettingsTyping(Context context) { super(context); } SettingsTyping(Context context) { super(context); }
public int getAbcAutoAcceptTimeout() { public int getAbcAutoAcceptTimeout() {
int time; int time = getStringifiedInt("pref_abc_auto_accept_timeout", 800);
try {
time = Integer.parseInt(prefs.getString("pref_abc_auto_accept_time", "800"));
} catch (NumberFormatException e) {
time = 800;
}
return time > 0 ? time + getKeyPadDebounceTime() : time; return time > 0 ? time + getKeyPadDebounceTime() : time;
} }
public boolean getAutoSpace() { return prefs.getBoolean("auto_space", true); } public boolean getAutoSpace() { return prefs.getBoolean("auto_space", true); }

View file

@ -29,19 +29,11 @@ public class SettingsUI extends SettingsTyping {
} }
public int getTheme() { public int getTheme() {
try { return getStringifiedInt("pref_theme", AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
return Integer.parseInt(prefs.getString("pref_theme", String.valueOf(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)));
} catch (NumberFormatException e) {
return AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
}
} }
public int getMainViewLayout() { public int getMainViewLayout() {
try { return getStringifiedInt("pref_layout_type", LAYOUT_SMALL);
return Integer.parseInt(prefs.getString("pref_layout_type", String.valueOf(LAYOUT_SMALL)));
} catch(NumberFormatException e) {
return LAYOUT_SMALL;
}
} }
public boolean isMainLayoutNumpad() { return getMainViewLayout() == LAYOUT_NUMPAD; } public boolean isMainLayoutNumpad() { return getMainViewLayout() == LAYOUT_NUMPAD; }