Index: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/WhitelistedWebsitesPreferenceCategory.java |
=================================================================== |
--- a/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/WhitelistedWebsitesPreferenceCategory.java |
+++ b/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/WhitelistedWebsitesPreferenceCategory.java |
@@ -15,27 +15,26 @@ |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
package org.adblockplus.sbrowser.contentblocker; |
import android.app.AlertDialog; |
import android.content.Context; |
import android.content.DialogInterface; |
-import android.content.SharedPreferences; |
import android.preference.DialogPreference; |
import android.preference.PreferenceCategory; |
-import android.preference.PreferenceManager; |
import android.text.Html; |
import android.util.AttributeSet; |
import android.view.View; |
import org.adblockplus.adblockplussbrowser.R; |
import org.adblockplus.sbrowser.contentblocker.engine.Engine; |
import org.adblockplus.sbrowser.contentblocker.engine.EngineService; |
+import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; |
import java.util.Collections; |
import java.util.Set; |
import java.util.TreeSet; |
public class WhitelistedWebsitesPreferenceCategory extends PreferenceCategory |
{ |
private final Set<String> whitelistedWebsites = new TreeSet<>(); |
@@ -65,21 +64,21 @@ public class WhitelistedWebsitesPreferen |
WhitelistedWebsitesPreferenceCategory.this.engine = engine; |
WhitelistedWebsitesPreferenceCategory.this.initEntries(); |
} |
}); |
} |
private void initEntries() |
{ |
- final SharedPreferences prefs = |
- PreferenceManager.getDefaultSharedPreferences(this.getContext().getApplicationContext()); |
- final String key = this.getContext().getString(R.string.key_whitelisted_websites); |
+ final Set<String> whitelistedWebsites = SharedPrefsUtils.getStringSet( |
+ this.getContext(), R.string.key_whitelisted_websites, Collections.<String>emptySet()); |
+ |
this.whitelistedWebsites.clear(); |
- this.whitelistedWebsites.addAll(prefs.getStringSet(key, Collections.<String>emptySet())); |
+ this.whitelistedWebsites.addAll(whitelistedWebsites); |
this.refreshEntries(); |
} |
private void refreshEntries() |
{ |
this.removeAll(); |
for (final String url : this.whitelistedWebsites) |
{ |
@@ -109,31 +108,28 @@ public class WhitelistedWebsitesPreferen |
} |
}); |
this.addPreference(urlPreference); |
} |
private void whitelistWebsite(String url) |
{ |
this.whitelistedWebsites.add(url); |
- final SharedPreferences prefs = |
- PreferenceManager.getDefaultSharedPreferences(this.getContext().getApplicationContext()); |
- final String key = this.getContext().getString(R.string.key_whitelisted_websites); |
- prefs.edit().putStringSet(key, this.whitelistedWebsites).apply(); |
- this.refreshEntries(); |
- this.engine.requestUpdateBroadcast(); |
+ this.storeWhitelistedWebsites(); |
} |
private void removeWhitelistedWebsite(String url) |
{ |
this.whitelistedWebsites.remove(url); |
- final SharedPreferences prefs = |
- PreferenceManager.getDefaultSharedPreferences(this.getContext().getApplicationContext()); |
- final String key = this.getContext().getString(R.string.key_whitelisted_websites); |
- prefs.edit().putStringSet(key, this.whitelistedWebsites).apply(); |
+ this.storeWhitelistedWebsites(); |
+ } |
+ |
+ private void storeWhitelistedWebsites() { |
+ SharedPrefsUtils.putStringSet( |
+ this.getContext(), R.string.key_whitelisted_websites, this.whitelistedWebsites); |
this.refreshEntries(); |
this.engine.requestUpdateBroadcast(); |
} |
private static class WhitelistedWebsitePreference extends DialogPreference |
{ |
private final DialogInterface.OnClickListener onDeleteClickListener; |