From 0f5e89c5e3c90f643b194f30b623594d1cf5471d Mon Sep 17 00:00:00 2001 From: Joey Peter Date: Sun, 31 Jul 2022 20:57:56 +0200 Subject: [PATCH] fix: app crashes on first start (#111) --- .../integrations/utils/SharedPrefHelper.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/utils/SharedPrefHelper.java b/app/src/main/java/app/revanced/integrations/utils/SharedPrefHelper.java index d1e015c07f..1ae5401c4a 100644 --- a/app/src/main/java/app/revanced/integrations/utils/SharedPrefHelper.java +++ b/app/src/main/java/app/revanced/integrations/utils/SharedPrefHelper.java @@ -26,17 +26,29 @@ public static Boolean getBoolean(Context context, SharedPrefNames prefName, Stri public static Long getLong(Context context, SharedPrefNames prefName, String key, Long _default) { SharedPreferences sharedPreferences = getPreferences(context, prefName); - return Long.valueOf(sharedPreferences.getString(key, _default + "")); + try { + return Long.valueOf(sharedPreferences.getString(key, _default + "")); + } catch (ClassCastException ex) { + return sharedPreferences.getLong(key, _default); + } } public static Float getFloat(Context context, SharedPrefNames prefName, String key, Float _default) { SharedPreferences sharedPreferences = getPreferences(context, prefName); - return Float.valueOf(sharedPreferences.getString(key, _default + "")); + try { + return Float.valueOf(sharedPreferences.getString(key, _default + "")); + } catch (ClassCastException ex) { + return sharedPreferences.getFloat(key, _default); + } } public static Integer getInt(Context context, SharedPrefNames prefName, String key, Integer _default) { SharedPreferences sharedPreferences = getPreferences(context, prefName); - return Integer.valueOf(sharedPreferences.getString(key, _default + "")); + try { + return Integer.valueOf(sharedPreferences.getString(key, _default + "")); + } catch (ClassCastException ex) { + return sharedPreferences.getInt(key, _default); + } } public static SharedPreferences getPreferences(Context context, SharedPrefNames name) {