Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/WhitelistedWebsitesPreferenceCategory.java

Issue 29716681: Issue 6454 - IllegalStateException crash (Closed)
Patch Set: Adjusting engine check Created March 9, 2018, 11:42 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/WhitelistedWebsitesPreferenceCategory.java
===================================================================
--- a/adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/WhitelistedWebsitesPreferenceCategory.java
+++ b/adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/WhitelistedWebsitesPreferenceCategory.java
@@ -28,14 +28,15 @@
import org.adblockplus.adblockplussbrowser.R;
import org.adblockplus.sbrowser.contentblocker.engine.Engine;
-import org.adblockplus.sbrowser.contentblocker.engine.EngineService;
+import org.adblockplus.sbrowser.contentblocker.engine.EngineManager;
import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
-public class WhitelistedWebsitesPreferenceCategory extends PreferenceCategory
+public class WhitelistedWebsitesPreferenceCategory extends PreferenceCategory implements
+ EngineManager.OnEngineCreatedCallback
{
private final Set<String> whitelistedWebsites = new TreeSet<>();
private Engine engine;
@@ -51,20 +52,17 @@
protected void onAttachedToActivity()
{
super.onAttachedToActivity();
- EngineService.startService(this.getContext().getApplicationContext(),
- new EngineService.OnEngineCreatedCallback()
- {
- @Override
- public void onEngineCreated(Engine engine, boolean success)
- {
- if (!success)
- {
- return;
- }
- WhitelistedWebsitesPreferenceCategory.this.engine = engine;
- WhitelistedWebsitesPreferenceCategory.this.initEntries();
- }
- });
+ EngineManager.getInstance().retrieveEngine(getContext(), this);
+ }
+
+ @Override
+ public void onEngineCreated(Engine engine)
+ {
+ this.engine = engine;
+ if (this.engine != null)
+ {
+ initEntries();
+ }
}
private void initEntries()
@@ -123,11 +121,15 @@
this.storeWhitelistedWebsites();
}
- private void storeWhitelistedWebsites() {
+ private void storeWhitelistedWebsites()
+ {
SharedPrefsUtils.putStringSet(
this.getContext(), R.string.key_whitelisted_websites, this.whitelistedWebsites);
this.refreshEntries();
- this.engine.requestUpdateBroadcast();
+ if (engine != null)
+ {
+ this.engine.requestUpdateBroadcast();
+ }
}
private static class WhitelistedWebsitePreference extends DialogPreference

Powered by Google App Engine
This is Rietveld