fixed auto updating filters

This commit is contained in:
gdlbo
2024-02-19 15:39:41 +03:00
parent 67f1477907
commit d10d5eca4b
2 changed files with 12 additions and 3 deletions
@@ -31,8 +31,14 @@ public class FiltersPreferences {
return AndroidUtils.getGlobalContext().getSharedPreferences("ru.vtosters.sponsorpost.filters.prefs", Context.MODE_PRIVATE);
}
public static void clearAll() {
preferences.edit().clear().apply();
public static void clearAllCachedLists() {
SharedPreferences.Editor editor = preferences.edit();
preferences.getAll().keySet().stream()
.filter(key -> key.endsWith(":" + PREF_KEY_LIST))
.forEach(editor::remove);
editor.apply();
}
public static boolean getSavedKeyValue(int id) {
@@ -2,6 +2,7 @@ package ru.vtosters.sponsorpost.utils;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.utils.NetworkUtils;
import ru.vtosters.lite.utils.newsfeed.NewsFeedFiltersUtils;
import ru.vtosters.sponsorpost.data.Filter;
import ru.vtosters.sponsorpost.data.Post;
import ru.vtosters.sponsorpost.services.FilterService;
@@ -23,7 +24,7 @@ public class Updates {
List<Filter> localFilters = FiltersPreferences.getAllDownloadedFilters();
if (!filters.isEmpty()) {
FiltersPreferences.clearAll(); // removes deleted filters from server
FiltersPreferences.clearAllCachedLists(); // removes deleted filters from server and cache
for (Filter filter : filters) {
Filter localFilter = findLocalFilterById(localFilters, filter.getId());
@@ -39,6 +40,8 @@ public class Updates {
}
}
}
NewsFeedFiltersUtils.updateFilters();
}
}