| 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,17 +38,16 @@ 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 java.util.regex.Pattern; |
| import org.adblockplus.adblockplussbrowser.R; |
| -import org.adblockplus.sbrowser.contentblocker.MainPreferences; |
| import android.content.Context; |
| import android.content.Intent; |
| import android.content.SharedPreferences; |
| import android.content.pm.PackageInfo; |
| import android.content.pm.PackageManager; |
| import android.content.pm.ResolveInfo; |
| import android.net.ConnectivityManager; |
| @@ -107,16 +106,17 @@ public final class Engine |
| private final ReentrantLock accessLock = new ReentrantLock(); |
| private DefaultSubscriptions defaultSubscriptions; |
| private Subscriptions subscriptions; |
| private JSONPrefs jsonPrefs; |
| private AppInfo appInfo; |
| private LinkedBlockingQueue<EngineEvent> engineEvents = new LinkedBlockingQueue<EngineEvent>(); |
| private Thread handlerThread; |
| private Downloader downloader; |
| + private SubscriptionUpdateCallback subscriptionUpdateCallback; |
| private final Context serviceContext; |
| private boolean wasFirstRun = false; |
| private long nextUpdateBroadcast = Long.MAX_VALUE; |
| private Engine(final Context context) |
| { |
| this.serviceContext = context; |
| } |
| @@ -184,27 +184,24 @@ public final class Engine |
| { |
| // Should never happen, as checkAAStatusAndProceed() should not be called if the user |
| // has no compatible SBrowser installed. Nevertheless we have to handle the Exception. |
| Log.d(TAG, "No compatible Samsung Browser found.", e); |
| return false; |
| } |
| } |
| + public void setSubscriptionUpdateCallback(final SubscriptionUpdateCallback subscriptionUpdateCallback) |
| + { |
| + this.subscriptionUpdateCallback = subscriptionUpdateCallback; |
| + } |
| + |
| public void requestUpdateBroadcast() |
| { |
| - this.lock(); |
| - try |
| - { |
| - this.nextUpdateBroadcast = System.currentTimeMillis() + BROADCAST_COMBINATION_DELAY_MILLIS; |
| - } |
| - finally |
| - { |
| - this.unlock(); |
| - } |
| + this.nextUpdateBroadcast = System.currentTimeMillis() + BROADCAST_COMBINATION_DELAY_MILLIS; |
| } |
| private void writeFileAndSendUpdateBroadcast() |
| { |
| createAndWriteFile(); |
| runOnUiThread(new Runnable() |
| { |
| @@ -251,32 +248,35 @@ public final class Engine |
| } |
| return false; |
| } |
| return current.isConnected(); |
| } |
| public List<SubscriptionInfo> getListedSubscriptions() |
| { |
| - this.lock(); |
| - try |
| - { |
| - return this.subscriptions.getSubscriptions(this); |
| - } |
| - finally |
| - { |
| - this.unlock(); |
| - } |
| + return this.subscriptions.getSubscriptions(this); |
| } |
| public void changeSubscriptionState(final String id, final boolean enabled) |
| { |
| + if (this.subscriptionUpdateCallback != null) |
| + { |
| + this.subscriptionUpdateCallback.subscriptionUpdateRequested(enabled); |
| + } |
| this.engineEvents.add(new ChangeEnabledStateEvent(id, enabled)); |
| } |
| + public void subscriptionStateChanged() { |
|
anton
2017/06/26 14:45:54
"{" should be on the next line.
LGTM in general
|
| + if (this.subscriptionUpdateCallback != null) |
| + { |
| + this.subscriptionUpdateCallback.subscriptionUpdatedApplied(); |
| + } |
| + } |
| + |
| 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() |
| { |
| @@ -801,9 +801,15 @@ public final class Engine |
| this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(), headers); |
| } |
| } |
| public void connectivityChanged() |
| { |
| this.downloader.connectivityChanged(); |
| } |
| + |
| + public interface SubscriptionUpdateCallback |
| + { |
| + void subscriptionUpdateRequested(boolean enabled); |
| + void subscriptionUpdatedApplied(); |
| + } |
| } |