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 24 matching lines...) Expand all Loading... |
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 UrlInputDialog.UrlReadyCallback |
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<>(); |
46 private static final HashSet<String> IGNORED_URLS = new HashSet<String>(); | 46 private static final HashSet<String> IGNORED_URLS = new HashSet<>(); |
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; |
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, |
(...skipping 10 matching lines...) Expand all Loading... |
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 static | 73 static |
74 { | 74 { |
75 for (int i = 0; i < BUILTIN_TITLES.length; i++) | 75 for (int i = 0; i < BUILTIN_TITLES.length; i++) |
76 { | 76 { |
77 BUILTIN_URL_TO_INDEX.put(BUILTIN_LISTS[i * 2 + 1], Integer.valueOf(i)); | 77 BUILTIN_URL_TO_INDEX.put(BUILTIN_LISTS[i * 2 + 1], i); |
78 } | 78 } |
79 | 79 |
80 IGNORED_URLS.add("https://easylist-downloads.adblockplus.org/exceptionrules.
txt"); | 80 IGNORED_URLS.add("https://easylist-downloads.adblockplus.org/exceptionrules.
txt"); |
81 } | 81 } |
82 | 82 |
83 private synchronized static void initRecommendedSubscriptions() | 83 private synchronized static void initRecommendedSubscriptions() |
84 { | 84 { |
85 if (recommendedSubscriptions == null) | 85 if (recommendedSubscriptions == null) |
86 { | 86 { |
87 recommendedSubscriptions = SubscriptionContainer.create(false); | 87 recommendedSubscriptions = SubscriptionContainer.create(false); |
(...skipping 17 matching lines...) Expand all Loading... |
105 this.activeSubscriptions = new ActiveSubscriptionContainer(context); | 105 this.activeSubscriptions = new ActiveSubscriptionContainer(context); |
106 } | 106 } |
107 | 107 |
108 @Override | 108 @Override |
109 protected View onCreateView(final ViewGroup parent) | 109 protected View onCreateView(final ViewGroup parent) |
110 { | 110 { |
111 this.setLayoutResource(R.layout.abb_minimal_widget); | 111 this.setLayoutResource(R.layout.abb_minimal_widget); |
112 return super.onCreateView(parent); | 112 return super.onCreateView(parent); |
113 } | 113 } |
114 | 114 |
115 public static Preference createCheckBoxOrSwitch(final Context context) | |
116 { | |
117 if (Build.VERSION.SDK_INT < 14) | |
118 { | |
119 return new CustomCheckBoxPreference(context); | |
120 } | |
121 try | |
122 { | |
123 return (Preference) Class.forName("android.preference.SwitchPreference") | |
124 .getConstructor(Context.class) | |
125 .newInstance(context); | |
126 } | |
127 catch (Exception e) | |
128 { | |
129 Log.e(TAG, "Failed to create SwitchPreference, falling back to CheckBoxPre
ference", e); | |
130 return new CustomCheckBoxPreference(context); | |
131 } | |
132 } | |
133 | |
134 @Override | 115 @Override |
135 protected void onAttachedToActivity() | 116 protected void onAttachedToActivity() |
136 { | 117 { |
137 this.setEnabled(false); | 118 this.setEnabled(false); |
138 this.setShouldDisableView(true); | 119 this.setShouldDisableView(true); |
139 | 120 |
140 super.onAttachedToActivity(); | 121 super.onAttachedToActivity(); |
141 | 122 |
142 this.progressDialog = new ProgressDialog(this.getContext()); | 123 this.progressDialog = new ProgressDialog(this.getContext()); |
143 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); | 124 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 { | 252 { |
272 return; | 253 return; |
273 } | 254 } |
274 | 255 |
275 Log.d(TAG, "Adding: " + url); | 256 Log.d(TAG, "Adding: " + url); |
276 this.addNewSubscription(url); | 257 this.addNewSubscription(url); |
277 } | 258 } |
278 | 259 |
279 private static class ActiveSubscriptionContainer implements AdblockPlusApiCall
back | 260 private static class ActiveSubscriptionContainer implements AdblockPlusApiCall
back |
280 { | 261 { |
281 public final HashMap<String, String> enabledSubscriptions = new HashMap<Stri
ng, String>(); | 262 public final HashMap<String, String> enabledSubscriptions = new HashMap<>(); |
282 private final Semaphore entriesReady = new Semaphore(0); | 263 private final Semaphore entriesReady = new Semaphore(0); |
283 private final Context context; | 264 private final Context context; |
284 | 265 |
285 ActiveSubscriptionContainer(Context context) | 266 ActiveSubscriptionContainer(Context context) |
286 { | 267 { |
287 this.context = context; | 268 this.context = context; |
288 } | 269 } |
289 | 270 |
290 public void refresh() | 271 public void refresh() |
291 { | 272 { |
292 AddOnBridge.queryActiveSubscriptions(this); | 273 AddOnBridge.queryActiveSubscriptions(this); |
293 this.entriesReady.acquireUninterruptibly(); | 274 this.entriesReady.acquireUninterruptibly(); |
294 } | 275 } |
295 | 276 |
296 @Override | 277 @Override |
297 public void onApiRequestSucceeded(NativeJSObject jsObject) | 278 public void onApiRequestSucceeded(NativeJSObject jsObject) |
298 { | 279 { |
299 try | 280 try |
300 { | 281 { |
301 this.enabledSubscriptions.clear(); | 282 this.enabledSubscriptions.clear(); |
302 if (jsObject.getBoolean("success")) | 283 if (jsObject.getBoolean("success")) |
303 { | 284 { |
304 NativeJSObject[] subs = jsObject.getObjectArray("value"); | 285 NativeJSObject[] subs = jsObject.getObjectArray("value"); |
305 for (int i = 0; i < subs.length; i++) | 286 for (final NativeJSObject sub : subs) |
306 { | 287 { |
307 final String url = subs[i].getString("url"); | 288 final String url = sub.getString("url"); |
308 | 289 |
309 String title = subs[i].has("title") ? subs[i].getString("title") : u
rl; | 290 String title = sub.has("title") ? sub.getString("title") : url; |
310 if (title.startsWith("~user~")) | 291 if (title.startsWith("~user~")) |
311 { | 292 { |
312 title = this.context.getString(R.string.abb_pref_category_whitelis
ted_sites); | 293 title = this.context.getString(R.string.abb_pref_category_whitelis
ted_sites); |
313 } | 294 } |
314 | 295 |
315 if (!IGNORED_URLS.contains(url)) | 296 if (!IGNORED_URLS.contains(url)) |
316 { | 297 { |
317 Log.d(TAG, "Adding: " + url + ", " + title); | 298 Log.d(TAG, "Adding: " + url + ", " + title); |
318 this.enabledSubscriptions.put(url, title); | 299 this.enabledSubscriptions.put(url, title); |
319 } | 300 } |
(...skipping 15 matching lines...) Expand all Loading... |
335 | 316 |
336 private static class CheckBoxChangeListener implements OnPreferenceChangeListe
ner, | 317 private static class CheckBoxChangeListener implements OnPreferenceChangeListe
ner, |
337 AdblockPlusApiCallback | 318 AdblockPlusApiCallback |
338 { | 319 { |
339 @Override | 320 @Override |
340 public boolean onPreferenceChange(Preference preference, Object newValue) | 321 public boolean onPreferenceChange(Preference preference, Object newValue) |
341 { | 322 { |
342 if (preference instanceof CheckBoxPreference && newValue instanceof Boolea
n) | 323 if (preference instanceof CheckBoxPreference && newValue instanceof Boolea
n) |
343 { | 324 { |
344 final CheckBoxPreference cbp = (CheckBoxPreference) preference; | 325 final CheckBoxPreference cbp = (CheckBoxPreference) preference; |
345 final boolean enable = ((Boolean) newValue).booleanValue(); | 326 final boolean enable = (Boolean) newValue; |
346 | 327 |
347 if (enable) | 328 if (enable) |
348 { | 329 { |
349 AddOnBridge.addSubscription(this, cbp.getKey(), null); | 330 AddOnBridge.addSubscription(this, cbp.getKey(), null); |
350 } | 331 } |
351 else | 332 else |
352 { | 333 { |
353 AddOnBridge.removeSubscription(this, cbp.getKey()); | 334 AddOnBridge.removeSubscription(this, cbp.getKey()); |
354 } | 335 } |
355 } | 336 } |
356 return true; | 337 return true; |
357 } | 338 } |
358 | 339 |
359 @Override | 340 @Override |
360 public void onApiRequestSucceeded(NativeJSObject jsObject) | 341 public void onApiRequestSucceeded(NativeJSObject jsObject) |
361 { | 342 { |
362 // ignored | 343 // ignored |
363 } | 344 } |
364 | 345 |
365 @Override | 346 @Override |
366 public void onApiRequestFailed(String errorMessage) | 347 public void onApiRequestFailed(String errorMessage) |
367 { | 348 { |
368 // ignored | 349 // ignored |
369 } | 350 } |
370 } | 351 } |
371 } | 352 } |
OLD | NEW |