| 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 25 matching lines...) Expand all Loading... | |
| 36 import java.util.HashMap; | 36 import java.util.HashMap; |
| 37 import java.util.List; | 37 import java.util.List; |
| 38 import java.util.Map; | 38 import java.util.Map; |
| 39 import java.util.Set; | 39 import java.util.Set; |
| 40 import java.util.TreeSet; | 40 import java.util.TreeSet; |
| 41 import java.util.concurrent.LinkedBlockingQueue; | 41 import java.util.concurrent.LinkedBlockingQueue; |
| 42 import java.util.concurrent.TimeUnit; | 42 import java.util.concurrent.TimeUnit; |
| 43 import java.util.concurrent.locks.ReentrantLock; | 43 import java.util.concurrent.locks.ReentrantLock; |
| 44 | 44 |
| 45 import org.adblockplus.adblockplussbrowser.R; | 45 import org.adblockplus.adblockplussbrowser.R; |
| 46 import org.adblockplus.sbrowser.contentblocker.MoreBlockingPreferenceCategory; | |
| 46 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; | 47 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; |
| 47 import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils; | 48 import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils; |
| 48 | 49 |
| 49 import android.content.Context; | 50 import android.content.Context; |
| 50 import android.content.Intent; | 51 import android.content.Intent; |
| 51 import android.content.pm.PackageInfo; | 52 import android.content.pm.PackageInfo; |
| 52 import android.content.pm.PackageManager; | 53 import android.content.pm.PackageManager; |
| 53 import android.content.pm.ResolveInfo; | 54 import android.content.pm.ResolveInfo; |
| 54 import android.net.ConnectivityManager; | 55 import android.net.ConnectivityManager; |
| 55 import android.net.NetworkInfo; | 56 import android.net.NetworkInfo; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 } | 250 } |
| 250 | 251 |
| 251 public void subscriptionStateChanged() | 252 public void subscriptionStateChanged() |
| 252 { | 253 { |
| 253 if (this.subscriptionUpdateCallback != null) | 254 if (this.subscriptionUpdateCallback != null) |
| 254 { | 255 { |
| 255 subscriptionUpdateCallback.subscriptionUpdatedApplied(); | 256 subscriptionUpdateCallback.subscriptionUpdatedApplied(); |
| 256 } | 257 } |
| 257 } | 258 } |
| 258 | 259 |
| 260 public void createAndAddSubscriptionFromUrl(final String url, final Subscripti onAddedCallback 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 sb.append(downloadCount); | 620 sb.append(downloadCount); |
| 605 } | 621 } |
| 606 else | 622 else |
| 607 { | 623 { |
| 608 sb.append("4%2B"); // "4+" URL encoded | 624 sb.append("4%2B"); // "4+" URL encoded |
| 609 } | 625 } |
| 610 | 626 |
| 611 return new URL(sb.toString()); | 627 return new URL(sb.toString()); |
| 612 } | 628 } |
| 613 | 629 |
| 630 public List<SubscriptionInfo> getMoreBlockingPreferenceSubscriptions() | |
| 631 { | |
| 632 List<SubscriptionInfo> moreBlockingPreferenceSubscriptions = new ArrayList<> (5); | |
| 633 for(SubscriptionInfo sub : getListedSubscriptions()) | |
|
anton
2017/08/25 10:40:40
it seems that space is required after `for`
jens
2017/08/25 11:35:06
Acknowledged.
| |
| 634 { | |
| 635 final DefaultSubscriptionInfo info = getDefaultSubscriptionInfoForUrl(sub. getUrl()); | |
| 636 Integer resInt = MoreBlockingPreferenceCategory.URL_TO_RES_ID_MAP.get(sub. getUrl()); | |
| 637 | |
| 638 if (sub.getType() == SubscriptionInfo.Type.CUSTOM) | |
| 639 { | |
| 640 moreBlockingPreferenceSubscriptions.add(sub); | |
| 641 } | |
| 642 | |
| 643 if (info != null && !info.isComplete() && sub.isEnabled()) | |
| 644 { | |
| 645 moreBlockingPreferenceSubscriptions.add(sub); | |
| 646 } | |
| 647 | |
| 648 if ((!(isAcceptableAdsUrl(sub)) || sub.getTitle().startsWith("__")) | |
| 649 && resInt != null | |
| 650 && (info == null || info.getPrefixes().isEmpty() || sub.getType() != S ubscriptionInfo.Type.ADS)) | |
| 651 { | |
| 652 moreBlockingPreferenceSubscriptions.add(sub); | |
| 653 } | |
| 654 } | |
| 655 | |
| 656 return moreBlockingPreferenceSubscriptions; | |
| 657 } | |
| 658 | |
| 659 private boolean isAcceptableAdsUrl(final SubscriptionInfo subscriptionInfo) | |
| 660 { | |
| 661 return getPrefsDefault(SUBSCRIPTIONS_EXCEPTIONSURL).equals(subscriptionInfo. getUrl()); | |
| 662 } | |
| 663 | |
| 614 private static class EventHandler implements Runnable | 664 private static class EventHandler implements Runnable |
| 615 { | 665 { |
| 616 private static final String TAG = EventHandler.class.getSimpleName(); | 666 private static final String TAG = EventHandler.class.getSimpleName(); |
| 617 private final Engine engine; | 667 private final Engine engine; |
| 618 | 668 |
| 619 public EventHandler(final Engine engine) | 669 public EventHandler(final Engine engine) |
| 620 { | 670 { |
| 621 this.engine = engine; | 671 this.engine = engine; |
| 622 } | 672 } |
| 623 | 673 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 780 public void connectivityChanged() | 830 public void connectivityChanged() |
| 781 { | 831 { |
| 782 this.downloader.connectivityChanged(); | 832 this.downloader.connectivityChanged(); |
| 783 } | 833 } |
| 784 | 834 |
| 785 public interface SubscriptionUpdateCallback | 835 public interface SubscriptionUpdateCallback |
| 786 { | 836 { |
| 787 void subscriptionUpdateRequested(boolean enabled); | 837 void subscriptionUpdateRequested(boolean enabled); |
| 788 void subscriptionUpdatedApplied(); | 838 void subscriptionUpdatedApplied(); |
| 789 } | 839 } |
| 840 | |
| 841 public interface SubscriptionAddedCallback | |
| 842 { | |
| 843 void subscriptionAdded(); | |
| 844 } | |
| 790 } | 845 } |
| OLD | NEW |