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 10 matching lines...) Expand all Loading... |
21 import android.content.Context; | 21 import android.content.Context; |
22 import android.content.DialogInterface; | 22 import android.content.DialogInterface; |
23 import android.preference.DialogPreference; | 23 import android.preference.DialogPreference; |
24 import android.preference.PreferenceCategory; | 24 import android.preference.PreferenceCategory; |
25 import android.text.Html; | 25 import android.text.Html; |
26 import android.util.AttributeSet; | 26 import android.util.AttributeSet; |
27 import android.view.View; | 27 import android.view.View; |
28 | 28 |
29 import org.adblockplus.adblockplussbrowser.R; | 29 import org.adblockplus.adblockplussbrowser.R; |
30 import org.adblockplus.sbrowser.contentblocker.engine.Engine; | 30 import org.adblockplus.sbrowser.contentblocker.engine.Engine; |
31 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; | 31 import org.adblockplus.sbrowser.contentblocker.engine.EngineManager; |
32 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; | 32 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; |
33 | 33 |
34 import java.util.Collections; | 34 import java.util.Collections; |
35 import java.util.Set; | 35 import java.util.Set; |
36 import java.util.TreeSet; | 36 import java.util.TreeSet; |
37 | 37 |
38 public class WhitelistedWebsitesPreferenceCategory extends PreferenceCategory | 38 public class WhitelistedWebsitesPreferenceCategory extends PreferenceCategory im
plements |
| 39 EngineManager.OnEngineCreatedCallback |
39 { | 40 { |
40 private final Set<String> whitelistedWebsites = new TreeSet<>(); | 41 private final Set<String> whitelistedWebsites = new TreeSet<>(); |
41 private Engine engine; | 42 private Engine engine; |
42 | 43 |
43 public WhitelistedWebsitesPreferenceCategory(Context context, AttributeSet att
rs) | 44 public WhitelistedWebsitesPreferenceCategory(Context context, AttributeSet att
rs) |
44 { | 45 { |
45 super(context, attrs); | 46 super(context, attrs); |
46 // This is required to remove the title TextView of the PreferenceCategory | 47 // This is required to remove the title TextView of the PreferenceCategory |
47 this.setLayoutResource(R.layout.empty_view); | 48 this.setLayoutResource(R.layout.empty_view); |
48 } | 49 } |
49 | 50 |
50 @Override | 51 @Override |
51 protected void onAttachedToActivity() | 52 protected void onAttachedToActivity() |
52 { | 53 { |
53 super.onAttachedToActivity(); | 54 super.onAttachedToActivity(); |
54 EngineService.startService(this.getContext().getApplicationContext(), | 55 EngineManager.getInstance().retrieveEngine(getContext(), this); |
55 new EngineService.OnEngineCreatedCallback() | 56 } |
56 { | 57 |
57 @Override | 58 @Override |
58 public void onEngineCreated(Engine engine, boolean success) | 59 public void onEngineCreated(Engine engine) |
59 { | 60 { |
60 if (!success) | 61 this.engine = engine; |
61 { | 62 if (this.engine != null) |
62 return; | 63 { |
63 } | 64 initEntries(); |
64 WhitelistedWebsitesPreferenceCategory.this.engine = engine; | 65 } |
65 WhitelistedWebsitesPreferenceCategory.this.initEntries(); | |
66 } | |
67 }); | |
68 } | 66 } |
69 | 67 |
70 private void initEntries() | 68 private void initEntries() |
71 { | 69 { |
72 final Set<String> whitelistedWebsites = SharedPrefsUtils.getStringSet( | 70 final Set<String> whitelistedWebsites = SharedPrefsUtils.getStringSet( |
73 this.getContext(), R.string.key_whitelisted_websites, Collections.<Strin
g>emptySet()); | 71 this.getContext(), R.string.key_whitelisted_websites, Collections.<Strin
g>emptySet()); |
74 | 72 |
75 this.whitelistedWebsites.clear(); | 73 this.whitelistedWebsites.clear(); |
76 this.whitelistedWebsites.addAll(whitelistedWebsites); | 74 this.whitelistedWebsites.addAll(whitelistedWebsites); |
77 this.refreshEntries(); | 75 this.refreshEntries(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 this.whitelistedWebsites.add(url); | 114 this.whitelistedWebsites.add(url); |
117 this.storeWhitelistedWebsites(); | 115 this.storeWhitelistedWebsites(); |
118 } | 116 } |
119 | 117 |
120 private void removeWhitelistedWebsite(String url) | 118 private void removeWhitelistedWebsite(String url) |
121 { | 119 { |
122 this.whitelistedWebsites.remove(url); | 120 this.whitelistedWebsites.remove(url); |
123 this.storeWhitelistedWebsites(); | 121 this.storeWhitelistedWebsites(); |
124 } | 122 } |
125 | 123 |
126 private void storeWhitelistedWebsites() { | 124 private void storeWhitelistedWebsites() |
| 125 { |
127 SharedPrefsUtils.putStringSet( | 126 SharedPrefsUtils.putStringSet( |
128 this.getContext(), R.string.key_whitelisted_websites, this.whitelistedWe
bsites); | 127 this.getContext(), R.string.key_whitelisted_websites, this.whitelistedWe
bsites); |
129 this.refreshEntries(); | 128 this.refreshEntries(); |
130 this.engine.requestUpdateBroadcast(); | 129 if (engine != null) |
| 130 { |
| 131 this.engine.requestUpdateBroadcast(); |
| 132 } |
131 } | 133 } |
132 | 134 |
133 private static class WhitelistedWebsitePreference extends DialogPreference | 135 private static class WhitelistedWebsitePreference extends DialogPreference |
134 { | 136 { |
135 private final DialogInterface.OnClickListener onDeleteClickListener; | 137 private final DialogInterface.OnClickListener onDeleteClickListener; |
136 | 138 |
137 WhitelistedWebsitePreference(Context context, String url, | 139 WhitelistedWebsitePreference(Context context, String url, |
138 DialogInterface.OnClickListener onDeleteClickListener) | 140 DialogInterface.OnClickListener onDeleteClickListener) |
139 { | 141 { |
140 super(context); | 142 super(context); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 { | 184 { |
183 if (WhitelistedWebsitePreference.this.onDeleteClickListener != null) | 185 if (WhitelistedWebsitePreference.this.onDeleteClickListener != null) |
184 { | 186 { |
185 WhitelistedWebsitePreference.this.onDeleteClickListener.onClick(dial
og, which); | 187 WhitelistedWebsitePreference.this.onDeleteClickListener.onClick(dial
og, which); |
186 } | 188 } |
187 } | 189 } |
188 }); | 190 }); |
189 } | 191 } |
190 } | 192 } |
191 } | 193 } |
OLD | NEW |