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 |
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.browser; | 18 package org.adblockplus.browser; |
19 | 19 |
20 import java.util.HashMap; | 20 import java.util.HashMap; |
21 import java.util.HashSet; | 21 import java.util.HashSet; |
22 import java.util.Map.Entry; | 22 import java.util.Map.Entry; |
23 import java.util.concurrent.Semaphore; | 23 import java.util.concurrent.Semaphore; |
24 | 24 |
25 import org.mozilla.gecko.R; | 25 import org.mozilla.gecko.R; |
26 import org.mozilla.gecko.preferences.CustomCheckBoxPreference; | 26 import org.mozilla.gecko.preferences.CustomCheckBoxPreference; |
27 import org.mozilla.gecko.util.NativeJSObject; | 27 import org.mozilla.gecko.util.GeckoBundle; |
28 import org.mozilla.gecko.util.ThreadUtils; | 28 import org.mozilla.gecko.util.ThreadUtils; |
29 | 29 |
30 import android.app.ProgressDialog; | 30 import android.app.ProgressDialog; |
31 import android.content.Context; | 31 import android.content.Context; |
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; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 217 |
218 AddOnBridge.postToHandler(new Runnable() | 218 AddOnBridge.postToHandler(new Runnable() |
219 { | 219 { |
220 @Override | 220 @Override |
221 public void run() | 221 public void run() |
222 { | 222 { |
223 try | 223 try |
224 { | 224 { |
225 final Semaphore finished = new Semaphore(0); | 225 final Semaphore finished = new Semaphore(0); |
226 | 226 |
227 AddOnBridge.addSubscription(new AdblockPlusApiCallback() | 227 AddOnBridge.addSubscription(url, null, new AdblockPlusApiCallback() |
228 { | 228 { |
229 @Override | 229 @Override |
230 public void onApiRequestSucceeded(NativeJSObject jsObject) | 230 public void onApiRequestSucceeded(GeckoBundle bundle) |
231 { | 231 { |
232 finished.release(); | 232 finished.release(); |
233 } | 233 } |
234 | 234 |
235 @Override | 235 @Override |
236 public void onApiRequestFailed(String errorMessage) | 236 public void onApiRequestFailed(String errorMessage) |
237 { | 237 { |
238 finished.release(); | 238 finished.release(); |
239 } | 239 } |
240 }, url, null); | 240 }); |
241 | 241 |
242 finished.acquireUninterruptibly(); | 242 finished.acquireUninterruptibly(); |
243 | 243 |
244 MoreSubscriptionsPreferenceGroup.this.activeSubscriptions.refresh(); | 244 MoreSubscriptionsPreferenceGroup.this.activeSubscriptions.refresh(); |
245 | 245 |
246 ThreadUtils.postToUiThread(new Runnable() | 246 ThreadUtils.postToUiThread(new Runnable() |
247 { | 247 { |
248 @Override | 248 @Override |
249 public void run() | 249 public void run() |
250 { | 250 { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 this.context = context; | 287 this.context = context; |
288 } | 288 } |
289 | 289 |
290 public void refresh() | 290 public void refresh() |
291 { | 291 { |
292 AddOnBridge.queryActiveSubscriptions(this); | 292 AddOnBridge.queryActiveSubscriptions(this); |
293 this.entriesReady.acquireUninterruptibly(); | 293 this.entriesReady.acquireUninterruptibly(); |
294 } | 294 } |
295 | 295 |
296 @Override | 296 @Override |
297 public void onApiRequestSucceeded(NativeJSObject jsObject) | 297 public void onApiRequestSucceeded(GeckoBundle bundle) |
298 { | 298 { |
299 try | 299 try |
300 { | 300 { |
301 this.enabledSubscriptions.clear(); | 301 this.enabledSubscriptions.clear(); |
302 if (jsObject.getBoolean("success")) | 302 final GeckoBundle[] subs = bundle.getBundleArray("value"); |
| 303 for (final GeckoBundle sub : subs) |
303 { | 304 { |
304 NativeJSObject[] subs = jsObject.getObjectArray("value"); | 305 final String url = sub.getString("url"); |
305 for (int i = 0; i < subs.length; i++) | 306 |
| 307 String title = sub.getString("title", url); |
| 308 if (title.startsWith("~user~")) |
306 { | 309 { |
307 final String url = subs[i].getString("url"); | 310 title = this.context.getString(R.string.abb_pref_category_whiteliste
d_sites); |
| 311 } |
308 | 312 |
309 String title = subs[i].has("title") ? subs[i].getString("title") : u
rl; | 313 if (!IGNORED_URLS.contains(url)) |
310 if (title.startsWith("~user~")) | 314 { |
311 { | 315 Log.d(TAG, "Adding: " + url + ", " + title); |
312 title = this.context.getString(R.string.abb_pref_category_whitelis
ted_sites); | 316 this.enabledSubscriptions.put(url, title); |
313 } | |
314 | |
315 if (!IGNORED_URLS.contains(url)) | |
316 { | |
317 Log.d(TAG, "Adding: " + url + ", " + title); | |
318 this.enabledSubscriptions.put(url, title); | |
319 } | |
320 } | 317 } |
321 } | 318 } |
322 } | 319 } |
323 finally | 320 finally |
324 { | 321 { |
325 this.entriesReady.release(); | 322 this.entriesReady.release(); |
326 } | 323 } |
327 } | 324 } |
328 | 325 |
329 @Override | 326 @Override |
330 public void onApiRequestFailed(String errorMessage) | 327 public void onApiRequestFailed(String errorMessage) |
331 { | 328 { |
332 this.entriesReady.release(); | 329 this.entriesReady.release(); |
333 } | 330 } |
334 } | 331 } |
335 | 332 |
336 private static class CheckBoxChangeListener implements OnPreferenceChangeListe
ner, | 333 private static class CheckBoxChangeListener implements OnPreferenceChangeListe
ner, |
337 AdblockPlusApiCallback | 334 AdblockPlusApiCallback |
338 { | 335 { |
339 @Override | 336 @Override |
340 public boolean onPreferenceChange(Preference preference, Object newValue) | 337 public boolean onPreferenceChange(Preference preference, Object newValue) |
341 { | 338 { |
342 if (preference instanceof CheckBoxPreference && newValue instanceof Boolea
n) | 339 if (preference instanceof CheckBoxPreference && newValue instanceof Boolea
n) |
343 { | 340 { |
344 final CheckBoxPreference cbp = (CheckBoxPreference) preference; | 341 final CheckBoxPreference cbp = (CheckBoxPreference) preference; |
345 final boolean enable = ((Boolean) newValue).booleanValue(); | 342 final boolean enable = ((Boolean) newValue).booleanValue(); |
346 | 343 |
347 if (enable) | 344 if (enable) |
348 { | 345 { |
349 AddOnBridge.addSubscription(this, cbp.getKey(), null); | 346 AddOnBridge.addSubscription(cbp.getKey(), null, this); |
350 } | 347 } |
351 else | 348 else |
352 { | 349 { |
353 AddOnBridge.removeSubscription(this, cbp.getKey()); | 350 AddOnBridge.removeSubscription(cbp.getKey(), this); |
354 } | 351 } |
355 } | 352 } |
356 return true; | 353 return true; |
357 } | 354 } |
358 | 355 |
359 @Override | 356 @Override |
360 public void onApiRequestSucceeded(NativeJSObject jsObject) | 357 public void onApiRequestSucceeded(GeckoBundle bundle) |
361 { | 358 { |
362 // ignored | 359 // ignored |
363 } | 360 } |
364 | 361 |
365 @Override | 362 @Override |
366 public void onApiRequestFailed(String errorMessage) | 363 public void onApiRequestFailed(String errorMessage) |
367 { | 364 { |
368 // ignored | 365 // ignored |
369 } | 366 } |
370 } | 367 } |
371 } | 368 } |
OLD | NEW |