| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 249 } |
| 250 | 250 |
| 251 public void subscriptionStateChanged() | 251 public void subscriptionStateChanged() |
| 252 { | 252 { |
| 253 if (this.subscriptionUpdateCallback != null) | 253 if (this.subscriptionUpdateCallback != null) |
| 254 { | 254 { |
| 255 subscriptionUpdateCallback.subscriptionUpdatedApplied(); | 255 subscriptionUpdateCallback.subscriptionUpdatedApplied(); |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| 259 public void createAndAddSubscriptionFromUrl(final String url, |
| 260 final SubscriptionAddedCallback callback) throws IOException |
| 261 { |
| 262 final Subscription sub = Subscription.create(url); |
| 263 sub.putMeta(Subscription.KEY_TITLE, url); |
| 264 sub.setEnabled(true); |
| 265 subscriptions.add(sub); |
| 266 subscriptions.persistSubscription(sub); |
| 267 callback.subscriptionAdded(); |
| 268 } |
| 269 |
| 270 public void removeSubscriptionById(final String subscriptionId) |
| 271 { |
| 272 subscriptions.remove(subscriptionId); |
| 273 } |
| 274 |
| 259 void downloadFinished(final String id, final int responseCode, final String re
sponse, | 275 void downloadFinished(final String id, final int responseCode, final String re
sponse, |
| 260 final Map<String, String> headers) | 276 final Map<String, String> headers) |
| 261 { | 277 { |
| 262 this.engineEvents.add(new DownloadFinishedEvent(id, responseCode, response,
headers)); | 278 this.engineEvents.add(new DownloadFinishedEvent(id, responseCode, response,
headers)); |
| 263 } | 279 } |
| 264 | 280 |
| 265 private void createAndWriteFile() | 281 private void createAndWriteFile() |
| 266 { | 282 { |
| 267 this.lock(); | 283 this.lock(); |
| 268 try | 284 try |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 engine.wasFirstRun = engine.subscriptions.wasUnitialized(); | 418 engine.wasFirstRun = engine.subscriptions.wasUnitialized(); |
| 403 if (engine.subscriptions.wasUnitialized()) | 419 if (engine.subscriptions.wasUnitialized()) |
| 404 { | 420 { |
| 405 Log.d(TAG, "Subscription storage was uninitialized, initializing..."); | 421 Log.d(TAG, "Subscription storage was uninitialized, initializing..."); |
| 406 | 422 |
| 407 try (final InputStream easylistTxt = context.getResources().openRawResourc
e(R.raw.easylist)) | 423 try (final InputStream easylistTxt = context.getResources().openRawResourc
e(R.raw.easylist)) |
| 408 { | 424 { |
| 409 final Subscription easylist = engine.subscriptions.add(Subscription | 425 final Subscription easylist = engine.subscriptions.add(Subscription |
| 410 // Use bundled EasyList as default and update it with locale specifi
c list later | 426 // Use bundled EasyList as default and update it with locale specifi
c list later |
| 411 // see: https://issues.adblockplus.org/ticket/5237 | 427 // see: https://issues.adblockplus.org/ticket/5237 |
| 412 .create(SubscriptionUtils.chooseDefaultSubscriptionUrl(engine.defaul
tSubscriptions.getAdsSubscriptions())) | 428 .create(SubscriptionUtils.chooseDefaultSubscriptionUrl( |
| 429 engine.defaultSubscriptions.getAdsSubscriptions())) |
| 413 .parseLines(readLines(easylistTxt))); | 430 .parseLines(readLines(easylistTxt))); |
| 414 easylist.putMeta(Subscription.KEY_UPDATE_TIMESTAMP, "0"); | 431 easylist.putMeta(Subscription.KEY_UPDATE_TIMESTAMP, "0"); |
| 415 easylist.setEnabled(true); | 432 easylist.setEnabled(true); |
| 416 } | 433 } |
| 417 Log.d(TAG, "Added and enabled bundled easylist"); | 434 Log.d(TAG, "Added and enabled bundled easylist"); |
| 418 | 435 |
| 419 try (final InputStream exceptionsTxt = context.getResources() | 436 try (final InputStream exceptionsTxt = context.getResources() |
| 420 .openRawResource(R.raw.exceptionrules)) | 437 .openRawResource(R.raw.exceptionrules)) |
| 421 { | 438 { |
| 422 final Subscription exceptions = engine.subscriptions.add(Subscription | 439 final Subscription exceptions = engine.subscriptions.add(Subscription |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 sb.append(downloadCount); | 621 sb.append(downloadCount); |
| 605 } | 622 } |
| 606 else | 623 else |
| 607 { | 624 { |
| 608 sb.append("4%2B"); // "4+" URL encoded | 625 sb.append("4%2B"); // "4+" URL encoded |
| 609 } | 626 } |
| 610 | 627 |
| 611 return new URL(sb.toString()); | 628 return new URL(sb.toString()); |
| 612 } | 629 } |
| 613 | 630 |
| 631 public boolean isAcceptableAdsUrl(final SubscriptionInfo subscriptionInfo) |
| 632 { |
| 633 return getPrefsDefault(SUBSCRIPTIONS_EXCEPTIONSURL).equals(subscriptionInfo.
getUrl()); |
| 634 } |
| 635 |
| 614 private static class EventHandler implements Runnable | 636 private static class EventHandler implements Runnable |
| 615 { | 637 { |
| 616 private static final String TAG = EventHandler.class.getSimpleName(); | 638 private static final String TAG = EventHandler.class.getSimpleName(); |
| 617 private final Engine engine; | 639 private final Engine engine; |
| 618 | 640 |
| 619 public EventHandler(final Engine engine) | 641 public EventHandler(final Engine engine) |
| 620 { | 642 { |
| 621 this.engine = engine; | 643 this.engine = engine; |
| 622 } | 644 } |
| 623 | 645 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 public void connectivityChanged() | 802 public void connectivityChanged() |
| 781 { | 803 { |
| 782 this.downloader.connectivityChanged(); | 804 this.downloader.connectivityChanged(); |
| 783 } | 805 } |
| 784 | 806 |
| 785 public interface SubscriptionUpdateCallback | 807 public interface SubscriptionUpdateCallback |
| 786 { | 808 { |
| 787 void subscriptionUpdateRequested(boolean enabled); | 809 void subscriptionUpdateRequested(boolean enabled); |
| 788 void subscriptionUpdatedApplied(); | 810 void subscriptionUpdatedApplied(); |
| 789 } | 811 } |
| 812 |
| 813 public interface SubscriptionAddedCallback |
| 814 { |
| 815 void subscriptionAdded(); |
| 816 } |
| 790 } | 817 } |
| OLD | NEW |