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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 |
(...skipping 21 matching lines...) Expand all Loading... |
32 import android.os.Build; | 32 import android.os.Build; |
33 import android.preference.CheckBoxPreference; | 33 import android.preference.CheckBoxPreference; |
34 import android.preference.Preference; | 34 import android.preference.Preference; |
35 import android.preference.PreferenceGroup; | 35 import android.preference.PreferenceGroup; |
36 import android.util.AttributeSet; | 36 import android.util.AttributeSet; |
37 import android.util.Log; | 37 import android.util.Log; |
38 import android.view.View; | 38 import android.view.View; |
39 import android.view.ViewGroup; | 39 import android.view.ViewGroup; |
40 | 40 |
41 public class MoreSubscriptionsPreferenceGroup extends PreferenceGroup implements | 41 public class MoreSubscriptionsPreferenceGroup extends PreferenceGroup implements |
42 UrlInputDialog.UrlReadyCallback | 42 InputValidatorDialogPreference.OnInputReadyListener |
43 { | 43 { |
44 private static final String TAG = "AdblockBrowser.OtherPreferenceGroup"; | 44 private static final String TAG = "AdblockBrowser.OtherPreferenceGroup"; |
45 private static final HashMap<String, Integer> BUILTIN_URL_TO_INDEX = new HashM
ap<String, Integer>(); | 45 private static final HashMap<String, Integer> BUILTIN_URL_TO_INDEX = new HashM
ap<String, Integer>(); |
46 private static final HashSet<String> IGNORED_URLS = new HashSet<String>(); | 46 private static final HashSet<String> IGNORED_URLS = new HashSet<String>(); |
47 private static SubscriptionContainer recommendedSubscriptions = null; | 47 private static SubscriptionContainer recommendedSubscriptions = null; |
48 | 48 |
49 private final CheckBoxChangeListener checkBoxChangeListener = new CheckBoxChan
geListener(); | 49 private final CheckBoxChangeListener checkBoxChangeListener = new CheckBoxChan
geListener(); |
50 private final ActiveSubscriptionContainer activeSubscriptions; | 50 private final ActiveSubscriptionContainer activeSubscriptions = new ActiveSubs
criptionContainer(); |
51 private ProgressDialog progressDialog; | 51 private ProgressDialog progressDialog; |
52 | 52 |
53 private static final int[] BUILTIN_TITLES = | 53 private static final int[] BUILTIN_TITLES = |
54 { | 54 { |
55 R.string.abb_subscription_disable_tracking, | 55 R.string.abb_subscription_disable_tracking, |
56 R.string.abb_subscription_disable_malware, | 56 R.string.abb_subscription_disable_malware, |
57 R.string.abb_subscription_disable_anti_adblock, | 57 R.string.abb_subscription_disable_anti_adblock, |
58 R.string.abb_subscription_disable_social_media | 58 R.string.abb_subscription_disable_social_media |
59 }; | 59 }; |
60 | 60 |
61 private static final String[] BUILTIN_LISTS = | 61 private static final String[] BUILTIN_LISTS = |
62 { | 62 { |
63 "EasyPrivacy", | 63 "EasyPrivacy", |
64 "https://easylist-downloads.adblockplus.org/easyprivacy.txt", | 64 "https://easylist-downloads.adblockplus.org/easyprivacy.txt", |
65 "Malware Domains", | 65 "Malware Domains", |
66 "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt", | 66 "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt", |
67 "Adblock Warning Removal List", | 67 "Adblock Warning Removal List", |
68 "https://easylist-downloads.adblockplus.org/antiadblockfilters.txt", | 68 "https://easylist-downloads.adblockplus.org/antiadblockfilters.txt", |
69 "Fanboy's Social Blocking List", | 69 "Fanboy's Social Blocking List", |
70 "https://easylist-downloads.adblockplus.org/fanboy-social.txt" | 70 "https://easylist-downloads.adblockplus.org/fanboy-social.txt" |
71 }; | 71 }; |
72 | 72 |
| 73 private static final String USER_SUBSCRIPTION_PREFIX = "~user~"; |
| 74 |
73 static | 75 static |
74 { | 76 { |
75 for (int i = 0; i < BUILTIN_TITLES.length; i++) | 77 for (int i = 0; i < BUILTIN_TITLES.length; i++) |
76 { | 78 { |
77 BUILTIN_URL_TO_INDEX.put(BUILTIN_LISTS[i * 2 + 1], Integer.valueOf(i)); | 79 BUILTIN_URL_TO_INDEX.put(BUILTIN_LISTS[i * 2 + 1], Integer.valueOf(i)); |
78 } | 80 } |
79 | 81 |
80 IGNORED_URLS.add("https://easylist-downloads.adblockplus.org/exceptionrules.
txt"); | 82 IGNORED_URLS.add("https://easylist-downloads.adblockplus.org/exceptionrules.
txt"); |
81 } | 83 } |
82 | 84 |
(...skipping 12 matching lines...) Expand all Loading... |
95 | 97 |
96 public MoreSubscriptionsPreferenceGroup(final Context context, final Attribute
Set attrs) | 98 public MoreSubscriptionsPreferenceGroup(final Context context, final Attribute
Set attrs) |
97 { | 99 { |
98 this(context, attrs, 0); | 100 this(context, attrs, 0); |
99 } | 101 } |
100 | 102 |
101 public MoreSubscriptionsPreferenceGroup(final Context context, final Attribute
Set attrs, | 103 public MoreSubscriptionsPreferenceGroup(final Context context, final Attribute
Set attrs, |
102 final int defStyleAttr) | 104 final int defStyleAttr) |
103 { | 105 { |
104 super(context, attrs, defStyleAttr); | 106 super(context, attrs, defStyleAttr); |
105 this.activeSubscriptions = new ActiveSubscriptionContainer(context); | |
106 } | 107 } |
107 | 108 |
108 @Override | 109 @Override |
109 protected View onCreateView(final ViewGroup parent) | 110 protected View onCreateView(final ViewGroup parent) |
110 { | 111 { |
111 this.setLayoutResource(R.layout.abb_minimal_widget); | 112 this.setLayoutResource(R.layout.abb_minimal_widget); |
112 return super.onCreateView(parent); | 113 return super.onCreateView(parent); |
113 } | 114 } |
114 | 115 |
115 public static Preference createCheckBoxOrSwitch(final Context context) | 116 public static Preference createCheckBoxOrSwitch(final Context context) |
(...skipping 21 matching lines...) Expand all Loading... |
137 this.setEnabled(false); | 138 this.setEnabled(false); |
138 this.setShouldDisableView(true); | 139 this.setShouldDisableView(true); |
139 | 140 |
140 super.onAttachedToActivity(); | 141 super.onAttachedToActivity(); |
141 | 142 |
142 this.progressDialog = new ProgressDialog(this.getContext()); | 143 this.progressDialog = new ProgressDialog(this.getContext()); |
143 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); | 144 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
144 this.progressDialog.setMessage(this.getContext().getString(R.string.abb_adbl
ocking_waiting)); | 145 this.progressDialog.setMessage(this.getContext().getString(R.string.abb_adbl
ocking_waiting)); |
145 this.progressDialog.show(); | 146 this.progressDialog.show(); |
146 | 147 |
147 UrlInputOpenerPreference.setRedirectUrlReadyCallback(this); | |
148 | |
149 AddOnBridge.postToHandler(new Runnable() | 148 AddOnBridge.postToHandler(new Runnable() |
150 { | 149 { |
151 @Override | 150 @Override |
152 public void run() | 151 public void run() |
153 { | 152 { |
154 initRecommendedSubscriptions(); | 153 initRecommendedSubscriptions(); |
155 MoreSubscriptionsPreferenceGroup.this.activeSubscriptions.refresh(); | 154 MoreSubscriptionsPreferenceGroup.this.activeSubscriptions.refresh(); |
156 | 155 |
157 ThreadUtils.postToUiThread(new Runnable() | 156 ThreadUtils.postToUiThread(new Runnable() |
158 { | 157 { |
159 @Override | 158 @Override |
160 public void run() | 159 public void run() |
161 { | 160 { |
162 MoreSubscriptionsPreferenceGroup.this.initEntries(); | 161 MoreSubscriptionsPreferenceGroup.this.initEntries(); |
163 } | 162 } |
164 }); | 163 }); |
165 } | 164 } |
166 }); | 165 }); |
167 } | 166 } |
168 | 167 |
169 private void initEntries() | 168 private void initEntries() |
170 { | 169 { |
171 this.removeAll(); | 170 this.removeAll(); |
172 int i = 0; | 171 for (int i = 0; i < BUILTIN_TITLES.length; i++) |
173 for (; i < BUILTIN_TITLES.length; i++) | |
174 { | 172 { |
175 final CheckBoxPreference cbp = new CustomCheckBoxPreference(this.getContex
t()); | 173 final CheckBoxPreference cbp = new CustomCheckBoxPreference(this.getContex
t()); |
176 final String url = BUILTIN_LISTS[i * 2 + 1]; | 174 final String url = BUILTIN_LISTS[i * 2 + 1]; |
177 cbp.setOrder(i); | |
178 cbp.setTitle(BUILTIN_TITLES[i]); | 175 cbp.setTitle(BUILTIN_TITLES[i]); |
179 cbp.setKey(url); | 176 cbp.setKey(url); |
180 cbp.setChecked(this.activeSubscriptions.enabledSubscriptions.containsKey(u
rl)); | 177 cbp.setChecked(this.activeSubscriptions.enabledSubscriptions.containsKey(u
rl)); |
181 cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener); | 178 cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener); |
182 cbp.setPersistent(false); | 179 cbp.setPersistent(false); |
183 this.addPreference(cbp); | 180 this.addPreference(cbp); |
184 } | 181 } |
185 | 182 |
186 for (Entry<String, String> e : this.activeSubscriptions.enabledSubscriptions
.entrySet()) | 183 for (Entry<String, String> e : this.activeSubscriptions.enabledSubscriptions
.entrySet()) |
187 { | 184 { |
188 if (!BUILTIN_URL_TO_INDEX.containsKey(e.getKey())) | 185 if (!BUILTIN_URL_TO_INDEX.containsKey(e.getKey())) |
189 { | 186 { |
190 final CheckBoxPreference cbp = new CustomCheckBoxPreference(this.getCont
ext()); | 187 final CheckBoxPreference cbp = new CustomCheckBoxPreference(this.getCont
ext()); |
191 cbp.setOrder(i++); | |
192 cbp.setTitle(e.getValue()); | 188 cbp.setTitle(e.getValue()); |
193 cbp.setKey(e.getKey()); | 189 cbp.setKey(e.getKey()); |
194 cbp.setChecked(true); | 190 cbp.setChecked(true); |
195 cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener); | 191 cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener); |
196 cbp.setPersistent(false); | 192 cbp.setPersistent(false); |
197 this.addPreference(cbp); | 193 this.addPreference(cbp); |
198 } | 194 } |
199 } | 195 } |
200 | 196 |
| 197 final InputValidatorDialogPreference inputPreference = new InputValidatorDia
logPreference( |
| 198 this.getContext()); |
| 199 inputPreference.setTitle(R.string.abb_pref_category_add_other_list); |
| 200 inputPreference.setDialogTitle(R.string.abb_pref_category_add_other_list); |
| 201 inputPreference.getEditText().setHint(R.string.abb_add_subscription_url); |
| 202 inputPreference.setOnInputReadyListener(this); |
| 203 this.addPreference(inputPreference); |
| 204 |
201 this.setEnabled(true); | 205 this.setEnabled(true); |
202 this.setShouldDisableView(false); | 206 this.setShouldDisableView(false); |
203 if (this.progressDialog != null) | 207 if (this.progressDialog != null) |
204 { | 208 { |
205 this.progressDialog.dismiss(); | 209 this.progressDialog.dismiss(); |
206 this.progressDialog = null; | 210 this.progressDialog = null; |
207 } | 211 } |
208 } | 212 } |
209 | 213 |
210 private void addNewSubscription(final String url) | 214 private void addNewSubscription(final String url) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 { | 262 { |
259 MoreSubscriptionsPreferenceGroup.this.progressDialog.dismiss(); | 263 MoreSubscriptionsPreferenceGroup.this.progressDialog.dismiss(); |
260 MoreSubscriptionsPreferenceGroup.this.progressDialog = null; | 264 MoreSubscriptionsPreferenceGroup.this.progressDialog = null; |
261 } | 265 } |
262 } | 266 } |
263 } | 267 } |
264 }); | 268 }); |
265 } | 269 } |
266 | 270 |
267 @Override | 271 @Override |
268 public void callback(final String url) | 272 public void onInputReady(String input) |
269 { | 273 { |
270 if (url == null) | 274 Log.d(TAG, "Adding: " + input); |
271 { | 275 this.addNewSubscription(input); |
272 return; | |
273 } | |
274 | |
275 Log.d(TAG, "Adding: " + url); | |
276 this.addNewSubscription(url); | |
277 } | 276 } |
278 | 277 |
279 private static class ActiveSubscriptionContainer implements AdblockPlusApiCall
back | 278 private static class ActiveSubscriptionContainer implements AdblockPlusApiCall
back |
280 { | 279 { |
281 public final HashMap<String, String> enabledSubscriptions = new HashMap<Stri
ng, String>(); | 280 public final HashMap<String, String> enabledSubscriptions = new HashMap<Stri
ng, String>(); |
282 private final Semaphore entriesReady = new Semaphore(0); | 281 private final Semaphore entriesReady = new Semaphore(0); |
283 private final Context context; | |
284 | |
285 ActiveSubscriptionContainer(Context context) | |
286 { | |
287 this.context = context; | |
288 } | |
289 | 282 |
290 public void refresh() | 283 public void refresh() |
291 { | 284 { |
292 AddOnBridge.queryActiveSubscriptions(this); | 285 AddOnBridge.queryActiveSubscriptions(this); |
293 this.entriesReady.acquireUninterruptibly(); | 286 this.entriesReady.acquireUninterruptibly(); |
294 } | 287 } |
295 | 288 |
296 @Override | 289 @Override |
297 public void onApiRequestSucceeded(NativeJSObject jsObject) | 290 public void onApiRequestSucceeded(NativeJSObject jsObject) |
298 { | 291 { |
299 try | 292 try |
300 { | 293 { |
301 this.enabledSubscriptions.clear(); | 294 this.enabledSubscriptions.clear(); |
302 if (jsObject.getBoolean("success")) | 295 if (jsObject.getBoolean("success")) |
303 { | 296 { |
304 NativeJSObject[] subs = jsObject.getObjectArray("value"); | 297 NativeJSObject[] subs = jsObject.getObjectArray("value"); |
305 for (int i = 0; i < subs.length; i++) | 298 for (int i = 0; i < subs.length; i++) |
306 { | 299 { |
307 final String url = subs[i].getString("url"); | 300 final String url = subs[i].getString("url"); |
| 301 final String title = subs[i].has("title") ? subs[i].getString("title
") : url; |
308 | 302 |
309 String title = subs[i].has("title") ? subs[i].getString("title") : u
rl; | 303 if (!IGNORED_URLS.contains(url) && !url.startsWith(USER_SUBSCRIPTION
_PREFIX)) |
310 if (title.startsWith("~user~")) | |
311 { | |
312 title = this.context.getString(R.string.abb_pref_category_whitelis
ted_sites); | |
313 } | |
314 | |
315 if (!IGNORED_URLS.contains(url)) | |
316 { | 304 { |
317 Log.d(TAG, "Adding: " + url + ", " + title); | 305 Log.d(TAG, "Adding: " + url + ", " + title); |
318 this.enabledSubscriptions.put(url, title); | 306 this.enabledSubscriptions.put(url, title); |
319 } | 307 } |
320 } | 308 } |
321 } | 309 } |
322 } | 310 } |
323 finally | 311 finally |
324 { | 312 { |
325 this.entriesReady.release(); | 313 this.entriesReady.release(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 // ignored | 350 // ignored |
363 } | 351 } |
364 | 352 |
365 @Override | 353 @Override |
366 public void onApiRequestFailed(String errorMessage) | 354 public void onApiRequestFailed(String errorMessage) |
367 { | 355 { |
368 // ignored | 356 // ignored |
369 } | 357 } |
370 } | 358 } |
371 } | 359 } |
OLD | NEW |