OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 package org.adblockplus.sbrowser.contentblocker; | 18 package org.adblockplus.sbrowser.contentblocker; |
19 | 19 |
20 import android.app.AlertDialog; | 20 import android.app.AlertDialog; |
21 import android.content.Context; | 21 import android.content.Context; |
22 import android.content.DialogInterface; | 22 import android.content.DialogInterface; |
23 import android.content.SharedPreferences; | |
24 import android.preference.DialogPreference; | 23 import android.preference.DialogPreference; |
25 import android.preference.PreferenceCategory; | 24 import android.preference.PreferenceCategory; |
26 import android.preference.PreferenceManager; | |
27 import android.text.Html; | 25 import android.text.Html; |
28 import android.util.AttributeSet; | 26 import android.util.AttributeSet; |
29 import android.view.View; | 27 import android.view.View; |
30 | 28 |
31 import org.adblockplus.adblockplussbrowser.R; | 29 import org.adblockplus.adblockplussbrowser.R; |
32 import org.adblockplus.sbrowser.contentblocker.engine.Engine; | 30 import org.adblockplus.sbrowser.contentblocker.engine.Engine; |
33 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; | 31 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; |
| 32 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; |
34 | 33 |
35 import java.util.Collections; | 34 import java.util.Collections; |
36 import java.util.Set; | 35 import java.util.Set; |
37 import java.util.TreeSet; | 36 import java.util.TreeSet; |
38 | 37 |
39 public class WhitelistedWebsitesPreferenceCategory extends PreferenceCategory | 38 public class WhitelistedWebsitesPreferenceCategory extends PreferenceCategory |
40 { | 39 { |
41 private final Set<String> whitelistedWebsites = new TreeSet<>(); | 40 private final Set<String> whitelistedWebsites = new TreeSet<>(); |
42 private Engine engine; | 41 private Engine engine; |
43 | 42 |
(...skipping 19 matching lines...) Expand all Loading... |
63 return; | 62 return; |
64 } | 63 } |
65 WhitelistedWebsitesPreferenceCategory.this.engine = engine; | 64 WhitelistedWebsitesPreferenceCategory.this.engine = engine; |
66 WhitelistedWebsitesPreferenceCategory.this.initEntries(); | 65 WhitelistedWebsitesPreferenceCategory.this.initEntries(); |
67 } | 66 } |
68 }); | 67 }); |
69 } | 68 } |
70 | 69 |
71 private void initEntries() | 70 private void initEntries() |
72 { | 71 { |
73 final SharedPreferences prefs = | 72 final Set<String> whitelistedWebsites = SharedPrefsUtils.getStringSet( |
74 PreferenceManager.getDefaultSharedPreferences(this.getContext().getAppli
cationContext()); | 73 this.getContext(), R.string.key_whitelisted_websites, Collections.<Strin
g>emptySet()); |
75 final String key = this.getContext().getString(R.string.key_whitelisted_webs
ites); | 74 |
76 this.whitelistedWebsites.clear(); | 75 this.whitelistedWebsites.clear(); |
77 this.whitelistedWebsites.addAll(prefs.getStringSet(key, Collections.<String>
emptySet())); | 76 this.whitelistedWebsites.addAll(whitelistedWebsites); |
78 this.refreshEntries(); | 77 this.refreshEntries(); |
79 } | 78 } |
80 | 79 |
81 private void refreshEntries() | 80 private void refreshEntries() |
82 { | 81 { |
83 this.removeAll(); | 82 this.removeAll(); |
84 for (final String url : this.whitelistedWebsites) | 83 for (final String url : this.whitelistedWebsites) |
85 { | 84 { |
86 final WhitelistedWebsitePreference whitelistedWebsitePreference = | 85 final WhitelistedWebsitePreference whitelistedWebsitePreference = |
87 new WhitelistedWebsitePreference(this.getContext(), url, new DialogInt
erface.OnClickListener() | 86 new WhitelistedWebsitePreference(this.getContext(), url, new DialogInt
erface.OnClickListener() |
(...skipping 19 matching lines...) Expand all Loading... |
107 { | 106 { |
108 WhitelistedWebsitesPreferenceCategory.this.whitelistWebsite(url); | 107 WhitelistedWebsitesPreferenceCategory.this.whitelistWebsite(url); |
109 } | 108 } |
110 }); | 109 }); |
111 this.addPreference(urlPreference); | 110 this.addPreference(urlPreference); |
112 } | 111 } |
113 | 112 |
114 private void whitelistWebsite(String url) | 113 private void whitelistWebsite(String url) |
115 { | 114 { |
116 this.whitelistedWebsites.add(url); | 115 this.whitelistedWebsites.add(url); |
117 final SharedPreferences prefs = | 116 this.storeWhitelistedWebsites(); |
118 PreferenceManager.getDefaultSharedPreferences(this.getContext().getAppli
cationContext()); | |
119 final String key = this.getContext().getString(R.string.key_whitelisted_webs
ites); | |
120 prefs.edit().putStringSet(key, this.whitelistedWebsites).apply(); | |
121 this.refreshEntries(); | |
122 this.engine.requestUpdateBroadcast(); | |
123 } | 117 } |
124 | 118 |
125 private void removeWhitelistedWebsite(String url) | 119 private void removeWhitelistedWebsite(String url) |
126 { | 120 { |
127 this.whitelistedWebsites.remove(url); | 121 this.whitelistedWebsites.remove(url); |
128 final SharedPreferences prefs = | 122 this.storeWhitelistedWebsites(); |
129 PreferenceManager.getDefaultSharedPreferences(this.getContext().getAppli
cationContext()); | 123 } |
130 final String key = this.getContext().getString(R.string.key_whitelisted_webs
ites); | 124 |
131 prefs.edit().putStringSet(key, this.whitelistedWebsites).apply(); | 125 private void storeWhitelistedWebsites() { |
| 126 SharedPrefsUtils.putStringSet( |
| 127 this.getContext(), R.string.key_whitelisted_websites, this.whitelistedWe
bsites); |
132 this.refreshEntries(); | 128 this.refreshEntries(); |
133 this.engine.requestUpdateBroadcast(); | 129 this.engine.requestUpdateBroadcast(); |
134 } | 130 } |
135 | 131 |
136 private static class WhitelistedWebsitePreference extends DialogPreference | 132 private static class WhitelistedWebsitePreference extends DialogPreference |
137 { | 133 { |
138 private final DialogInterface.OnClickListener onDeleteClickListener; | 134 private final DialogInterface.OnClickListener onDeleteClickListener; |
139 | 135 |
140 WhitelistedWebsitePreference(Context context, String url, | 136 WhitelistedWebsitePreference(Context context, String url, |
141 DialogInterface.OnClickListener onDeleteClickListener) | 137 DialogInterface.OnClickListener onDeleteClickListener) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 { | 181 { |
186 if (WhitelistedWebsitePreference.this.onDeleteClickListener != null) | 182 if (WhitelistedWebsitePreference.this.onDeleteClickListener != null) |
187 { | 183 { |
188 WhitelistedWebsitePreference.this.onDeleteClickListener.onClick(dial
og, which); | 184 WhitelistedWebsitePreference.this.onDeleteClickListener.onClick(dial
og, which); |
189 } | 185 } |
190 } | 186 } |
191 }); | 187 }); |
192 } | 188 } |
193 } | 189 } |
194 } | 190 } |
OLD | NEW |