diff options
author | cyBerta <cyberta@riseup.net> | 2019-12-30 17:16:44 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2019-12-30 17:16:44 +0100 |
commit | d57d75e13daceb4bccc5e4aa1b7769be27a9a5c5 (patch) | |
tree | bba577c67f2225719481ba79ee6daa98592084a4 /app/src/main/java/se | |
parent | 988bd203ee14a589eef58a4aa6bd51a5b005d072 (diff) |
reduce code duplication in PreferenceHelper
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java | 36 |
1 files changed, 6 insertions, 30 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java index bf97b5c5..40bb2eca 100644 --- a/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java @@ -224,51 +224,27 @@ public class PreferenceHelper { } public static boolean getUsePluggableTransports(Context context) { - if (context == null) { - return false; - } - SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - return preferences.getBoolean(USE_PLUGGABLE_TRANSPORTS, false); + return getBoolean(context, USE_PLUGGABLE_TRANSPORTS, false); } public static void usePluggableTransports(Context context, boolean isEnabled) { - if (context == null) { - return; - } - SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - preferences.edit().putBoolean(USE_PLUGGABLE_TRANSPORTS, isEnabled).apply(); + putBoolean(context, USE_PLUGGABLE_TRANSPORTS, isEnabled); } public static void saveBattery(Context context, boolean isEnabled) { - if (context == null) { - return; - } - SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - preferences.edit().putBoolean(DEFAULT_SHARED_PREFS_BATTERY_SAVER, isEnabled).apply(); + putBoolean(context, DEFAULT_SHARED_PREFS_BATTERY_SAVER, isEnabled); } public static boolean getSaveBattery(Context context) { - if (context == null) { - return false; - } - SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - return preferences.getBoolean(DEFAULT_SHARED_PREFS_BATTERY_SAVER, false); + return getBoolean(context, DEFAULT_SHARED_PREFS_BATTERY_SAVER, false); } public static void saveShowAlwaysOnDialog(Context context, boolean showAlwaysOnDialog) { - if (context == null) { - return; - } - SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - preferences.edit().putBoolean(ALWAYS_ON_SHOW_DIALOG, showAlwaysOnDialog).apply(); + putBoolean(context, ALWAYS_ON_SHOW_DIALOG, showAlwaysOnDialog); } public static boolean getShowAlwaysOnDialog(Context context) { - if (context == null) { - return true; - } - SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - return preferences.getBoolean(ALWAYS_ON_SHOW_DIALOG, true); + return getBoolean(context, ALWAYS_ON_SHOW_DIALOG, true); } public static JSONObject getEipDefinitionFromPreferences(SharedPreferences preferences) { |