From ea9d39c26509a163f7fe7c78d903ae4b499cc6a9 Mon Sep 17 00:00:00 2001 From: zerrium Date: Fri, 19 Mar 2021 11:10:42 +0700 Subject: [PATCH] Added Set support for SettingsHelper and sharedPreferences --- .../awais/instagrabber/utils/Constants.java | 5 +++++ .../instagrabber/utils/SettingsHelper.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/src/main/java/awais/instagrabber/utils/Constants.java b/app/src/main/java/awais/instagrabber/utils/Constants.java index cb56eba2..cf63db1c 100644 --- a/app/src/main/java/awais/instagrabber/utils/Constants.java +++ b/app/src/main/java/awais/instagrabber/utils/Constants.java @@ -1,5 +1,8 @@ package awais.instagrabber.utils; +import java.util.HashSet; +import java.util.Set; + public final class Constants { // string prefs public static final String FOLDER_PATH = "custom_path"; @@ -9,6 +12,8 @@ public final class Constants { public static final String APP_THEME = "app_theme_v19"; public static final String APP_LANGUAGE = "app_language_v19"; public static final String STORY_SORT = "story_sort"; + // set string prefs + public static final String KEYWORD_FILTERS = "keyword_filters"; // int prefs, do not export public static final String PREV_INSTALL_VERSION = "prevVersion"; public static final String BROWSER_UA_CODE = "browser_ua_code"; diff --git a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java index b6238a97..9f5ee813 100755 --- a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java +++ b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java @@ -8,6 +8,9 @@ import androidx.annotation.NonNull; import androidx.annotation.StringDef; import androidx.appcompat.app.AppCompatDelegate; +import java.util.HashSet; +import java.util.Set; + import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH; import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH_FREQ_NUMBER; import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH_FREQ_UNIT; @@ -38,6 +41,7 @@ import static awais.instagrabber.utils.Constants.MUTED_VIDEOS; import static awais.instagrabber.utils.Constants.PREF_DARK_THEME; import static awais.instagrabber.utils.Constants.PREF_EMOJI_VARIANTS; import static awais.instagrabber.utils.Constants.PREF_HASHTAG_POSTS_LAYOUT; +import static awais.instagrabber.utils.Constants.KEYWORD_FILTERS; import static awais.instagrabber.utils.Constants.PREF_LIGHT_THEME; import static awais.instagrabber.utils.Constants.PREF_LIKED_POSTS_LAYOUT; import static awais.instagrabber.utils.Constants.PREF_LOCATION_POSTS_LAYOUT; @@ -68,6 +72,12 @@ public final class SettingsHelper { return stringDefault; } + public Set getStringSet(@StringSetSettings final String key) { + final Set stringSetDefault = new HashSet<>(); + if (sharedPreferences != null) return sharedPreferences.getStringSet(key, stringSetDefault); + return stringSetDefault; + } + public int getInteger(@IntegerSettings final String key) { final int integerDefault = getIntegerDefault(key); if (sharedPreferences != null) return sharedPreferences.getInt(key, integerDefault); @@ -122,6 +132,10 @@ public final class SettingsHelper { if (sharedPreferences != null) sharedPreferences.edit().putString(key, val).apply(); } + public void putStringSet(@StringSetSettings final String key, final Set val) { + if (sharedPreferences != null) sharedPreferences.edit().putStringSet(key, val).apply(); + } + public void putInteger(@IntegerSettings final String key, final int val) { if (sharedPreferences != null) sharedPreferences.edit().putInt(key, val).apply(); } @@ -146,4 +160,7 @@ public final class SettingsHelper { @StringDef({PREV_INSTALL_VERSION, BROWSER_UA_CODE, APP_UA_CODE, PREF_ENABLE_DM_AUTO_REFRESH_FREQ_NUMBER}) public @interface IntegerSettings {} + + @StringDef({KEYWORD_FILTERS}) + public @interface StringSetSettings {} } \ No newline at end of file