Left: | ||
Right: |
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 | 74 |
75 static | 75 static |
76 { | 76 { |
77 for (int i = 0; i < BUILTIN_TITLES.length; i++) | 77 for (int i = 0; i < BUILTIN_TITLES.length; i++) |
78 { | 78 { |
79 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)); |
80 } | 80 } |
81 | 81 |
82 IGNORED_URLS.add("https://easylist-downloads.adblockplus.org/exceptionrules. txt"); | 82 IGNORED_URLS.add("https://easylist-downloads.adblockplus.org/exceptionrules. txt"); |
83 } | 83 } |
84 | 84 |
jens
2019/01/10 14:10:59
Context could be final.
diegocarloslima
2019/01/16 13:44:21
Acknowledged.
| |
85 private synchronized static void initRecommendedSubscriptions() | 85 private synchronized static void initRecommendedSubscriptions(Context context) |
86 { | 86 { |
87 if (recommendedSubscriptions == null) | 87 if (recommendedSubscriptions == null) |
88 { | 88 { |
89 recommendedSubscriptions = SubscriptionContainer.create(false); | 89 recommendedSubscriptions = SubscriptionContainer.create(context, false); |
90 | 90 |
91 for (SubscriptionContainer.Subscription s : recommendedSubscriptions.getSu bscriptions(false)) | 91 for (SubscriptionContainer.Subscription s : recommendedSubscriptions.getSu bscriptions(false)) |
92 { | 92 { |
93 IGNORED_URLS.add(s.url); | 93 IGNORED_URLS.add(s.url); |
94 } | 94 } |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 public MoreSubscriptionsPreferenceGroup(final Context context, final Attribute Set attrs) | 98 public MoreSubscriptionsPreferenceGroup(final Context context, final Attribute Set attrs) |
99 { | 99 { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 this.setEnabled(false); | 138 this.setEnabled(false); |
139 this.setShouldDisableView(true); | 139 this.setShouldDisableView(true); |
140 | 140 |
141 super.onAttachedToActivity(); | 141 super.onAttachedToActivity(); |
142 | 142 |
143 this.progressDialog = new ProgressDialog(this.getContext()); | 143 this.progressDialog = new ProgressDialog(this.getContext()); |
144 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); | 144 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
145 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)); |
146 this.progressDialog.show(); | 146 this.progressDialog.show(); |
147 | 147 |
148 AddOnBridge.postToHandler(new Runnable() | 148 ExtensionBridge.postToHandler(new Runnable() |
149 { | 149 { |
150 @Override | 150 @Override |
151 public void run() | 151 public void run() |
152 { | 152 { |
153 initRecommendedSubscriptions(); | 153 initRecommendedSubscriptions(getContext()); |
154 MoreSubscriptionsPreferenceGroup.this.activeSubscriptions.refresh(); | 154 MoreSubscriptionsPreferenceGroup.this.activeSubscriptions.refresh(); |
155 | 155 |
156 ThreadUtils.postToUiThread(new Runnable() | 156 ThreadUtils.postToUiThread(new Runnable() |
157 { | 157 { |
158 @Override | 158 @Override |
159 public void run() | 159 public void run() |
160 { | 160 { |
161 MoreSubscriptionsPreferenceGroup.this.initEntries(); | 161 MoreSubscriptionsPreferenceGroup.this.initEntries(); |
162 } | 162 } |
163 }); | 163 }); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 } | 212 } |
213 | 213 |
214 private void addNewSubscription(final String url) | 214 private void addNewSubscription(final String url) |
215 { | 215 { |
216 this.progressDialog = new ProgressDialog(this.getContext()); | 216 this.progressDialog = new ProgressDialog(this.getContext()); |
217 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); | 217 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
218 this.progressDialog | 218 this.progressDialog |
219 .setMessage(this.getContext().getString(R.string.abb_add_subscription_ad ding)); | 219 .setMessage(this.getContext().getString(R.string.abb_add_subscription_ad ding)); |
220 this.progressDialog.show(); | 220 this.progressDialog.show(); |
221 | 221 |
222 AddOnBridge.postToHandler(new Runnable() | 222 ExtensionBridge.postToHandler(new Runnable() |
223 { | 223 { |
224 @Override | 224 @Override |
225 public void run() | 225 public void run() |
226 { | 226 { |
227 try | 227 try |
228 { | 228 { |
229 final Semaphore finished = new Semaphore(0); | 229 final Semaphore finished = new Semaphore(0); |
230 | 230 |
231 AddOnBridge.addSubscription(url, null, new AdblockPlusApiCallback() | 231 ExtensionBridge.addSubscription(url, null, new AdblockPlusApiCallback( ) |
232 { | 232 { |
233 @Override | 233 @Override |
234 public void onApiRequestSucceeded(GeckoBundle bundle) | 234 public void onApiRequestSucceeded(GeckoBundle bundle) |
235 { | 235 { |
236 finished.release(); | 236 finished.release(); |
237 } | 237 } |
238 | 238 |
239 @Override | 239 @Override |
240 public void onApiRequestFailed(String errorMessage) | 240 public void onApiRequestFailed(String errorMessage) |
241 { | 241 { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 this.addNewSubscription(input); | 275 this.addNewSubscription(input); |
276 } | 276 } |
277 | 277 |
278 private static class ActiveSubscriptionContainer implements AdblockPlusApiCall back | 278 private static class ActiveSubscriptionContainer implements AdblockPlusApiCall back |
279 { | 279 { |
280 public final HashMap<String, String> enabledSubscriptions = new HashMap<Stri ng, String>(); | 280 public final HashMap<String, String> enabledSubscriptions = new HashMap<Stri ng, String>(); |
281 private final Semaphore entriesReady = new Semaphore(0); | 281 private final Semaphore entriesReady = new Semaphore(0); |
282 | 282 |
283 public void refresh() | 283 public void refresh() |
284 { | 284 { |
285 AddOnBridge.queryActiveSubscriptions(this); | 285 ExtensionBridge.queryActiveSubscriptions(this); |
286 this.entriesReady.acquireUninterruptibly(); | 286 this.entriesReady.acquireUninterruptibly(); |
287 } | 287 } |
288 | 288 |
289 @Override | 289 @Override |
290 public void onApiRequestSucceeded(GeckoBundle bundle) | 290 public void onApiRequestSucceeded(GeckoBundle bundle) |
291 { | 291 { |
292 try | 292 try |
293 { | 293 { |
294 this.enabledSubscriptions.clear(); | 294 this.enabledSubscriptions.clear(); |
295 for (final GeckoBundle sub : bundle.getBundleArray("value")) | 295 for (final GeckoBundle sub : bundle.getBundleArray("value")) |
(...skipping 27 matching lines...) Expand all Loading... | |
323 @Override | 323 @Override |
324 public boolean onPreferenceChange(Preference preference, Object newValue) | 324 public boolean onPreferenceChange(Preference preference, Object newValue) |
325 { | 325 { |
326 if (preference instanceof CheckBoxPreference && newValue instanceof Boolea n) | 326 if (preference instanceof CheckBoxPreference && newValue instanceof Boolea n) |
327 { | 327 { |
328 final CheckBoxPreference cbp = (CheckBoxPreference) preference; | 328 final CheckBoxPreference cbp = (CheckBoxPreference) preference; |
329 final boolean enable = ((Boolean) newValue).booleanValue(); | 329 final boolean enable = ((Boolean) newValue).booleanValue(); |
330 | 330 |
331 if (enable) | 331 if (enable) |
332 { | 332 { |
333 AddOnBridge.addSubscription(cbp.getKey(), null, this); | 333 ExtensionBridge.addSubscription(cbp.getKey(), null, this); |
334 } | 334 } |
335 else | 335 else |
336 { | 336 { |
337 AddOnBridge.removeSubscription(cbp.getKey(), this); | 337 ExtensionBridge.removeSubscription(cbp.getKey(), this); |
338 } | 338 } |
339 } | 339 } |
340 return true; | 340 return true; |
341 } | 341 } |
342 | 342 |
343 @Override | 343 @Override |
344 public void onApiRequestSucceeded(GeckoBundle bundle) | 344 public void onApiRequestSucceeded(GeckoBundle bundle) |
345 { | 345 { |
346 // ignored | 346 // ignored |
347 } | 347 } |
348 | 348 |
349 @Override | 349 @Override |
350 public void onApiRequestFailed(String errorMessage) | 350 public void onApiRequestFailed(String errorMessage) |
351 { | 351 { |
352 // ignored | 352 // ignored |
353 } | 353 } |
354 } | 354 } |
355 } | 355 } |
OLD | NEW |