| Index: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java |
| =================================================================== |
| --- a/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java |
| +++ b/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java |
| @@ -38,16 +38,17 @@ import java.util.List; |
| import java.util.Map; |
| import java.util.Set; |
| import java.util.TreeSet; |
| import java.util.concurrent.LinkedBlockingQueue; |
| import java.util.concurrent.TimeUnit; |
| import java.util.concurrent.locks.ReentrantLock; |
| import org.adblockplus.adblockplussbrowser.R; |
| +import org.adblockplus.sbrowser.contentblocker.MoreBlockingPreferenceCategory; |
| import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; |
| import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils; |
| import android.content.Context; |
| import android.content.Intent; |
| import android.content.pm.PackageInfo; |
| import android.content.pm.PackageManager; |
| import android.content.pm.ResolveInfo; |
| @@ -251,16 +252,31 @@ public final class Engine |
| public void subscriptionStateChanged() |
| { |
| if (this.subscriptionUpdateCallback != null) |
| { |
| subscriptionUpdateCallback.subscriptionUpdatedApplied(); |
| } |
| } |
| + public void createAndAddSubscriptionFromUrl(final String url, final SubscriptionAddedCallback callback) throws IOException |
| + { |
| + final Subscription sub = Subscription.create(url); |
| + sub.putMeta(Subscription.KEY_TITLE, url); |
| + sub.setEnabled(true); |
| + subscriptions.add(sub); |
| + subscriptions.persistSubscription(sub); |
| + callback.subscriptionAdded(); |
| + } |
| + |
| + public void removeSubscriptionById(final String subscriptionId) |
| + { |
| + subscriptions.remove(subscriptionId); |
| + } |
| + |
| void downloadFinished(final String id, final int responseCode, final String response, |
| final Map<String, String> headers) |
| { |
| this.engineEvents.add(new DownloadFinishedEvent(id, responseCode, response, headers)); |
| } |
| private void createAndWriteFile() |
| { |
| @@ -606,16 +622,50 @@ public final class Engine |
| else |
| { |
| sb.append("4%2B"); // "4+" URL encoded |
| } |
| return new URL(sb.toString()); |
| } |
| + public List<SubscriptionInfo> getMoreBlockingPreferenceSubscriptions() |
| + { |
| + List<SubscriptionInfo> moreBlockingPreferenceSubscriptions = new ArrayList<>(5); |
| + 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.
|
| + { |
| + final DefaultSubscriptionInfo info = getDefaultSubscriptionInfoForUrl(sub.getUrl()); |
| + Integer resInt = MoreBlockingPreferenceCategory.URL_TO_RES_ID_MAP.get(sub.getUrl()); |
| + |
| + if (sub.getType() == SubscriptionInfo.Type.CUSTOM) |
| + { |
| + moreBlockingPreferenceSubscriptions.add(sub); |
| + } |
| + |
| + if (info != null && !info.isComplete() && sub.isEnabled()) |
| + { |
| + moreBlockingPreferenceSubscriptions.add(sub); |
| + } |
| + |
| + if ((!(isAcceptableAdsUrl(sub)) || sub.getTitle().startsWith("__")) |
| + && resInt != null |
| + && (info == null || info.getPrefixes().isEmpty() || sub.getType() != SubscriptionInfo.Type.ADS)) |
| + { |
| + moreBlockingPreferenceSubscriptions.add(sub); |
| + } |
| + } |
| + |
| + return moreBlockingPreferenceSubscriptions; |
| + } |
| + |
| + private boolean isAcceptableAdsUrl(final SubscriptionInfo subscriptionInfo) |
| + { |
| + return getPrefsDefault(SUBSCRIPTIONS_EXCEPTIONSURL).equals(subscriptionInfo.getUrl()); |
| + } |
| + |
| private static class EventHandler implements Runnable |
| { |
| private static final String TAG = EventHandler.class.getSimpleName(); |
| private final Engine engine; |
| public EventHandler(final Engine engine) |
| { |
| this.engine = engine; |
| @@ -782,9 +832,14 @@ public final class Engine |
| this.downloader.connectivityChanged(); |
| } |
| public interface SubscriptionUpdateCallback |
| { |
| void subscriptionUpdateRequested(boolean enabled); |
| void subscriptionUpdatedApplied(); |
| } |
| + |
| + public interface SubscriptionAddedCallback |
| + { |
| + void subscriptionAdded(); |
| + } |
| } |