| 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 27 matching lines...) Expand all Loading... | |
| 38 * Suggested preference name to store settings | 38 * Suggested preference name to store settings |
| 39 */ | 39 */ |
| 40 public static final String PREFERENCE_NAME = "ADBLOCK"; | 40 public static final String PREFERENCE_NAME = "ADBLOCK"; |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Suggested preference name to store intercepted subscription requests | 43 * Suggested preference name to store intercepted subscription requests |
| 44 */ | 44 */ |
| 45 public static final String PRELOAD_PREFERENCE_NAME = "ADBLOCK_PRELOAD"; | 45 public static final String PRELOAD_PREFERENCE_NAME = "ADBLOCK_PRELOAD"; |
| 46 private static AdblockHelper _instance; | 46 private static AdblockHelper _instance; |
| 47 | 47 |
| 48 private boolean isInitialized; | |
| 48 private SingleInstanceEngineProvider provider; | 49 private SingleInstanceEngineProvider provider; |
| 49 private AdblockSettingsStorage storage; | 50 private AdblockSettingsStorage storage; |
| 50 | 51 |
| 51 private final SingleInstanceEngineProvider.EngineCreatedListener engineCreated Listener = | 52 private final SingleInstanceEngineProvider.EngineCreatedListener engineCreated Listener = |
| 52 new SingleInstanceEngineProvider.EngineCreatedListener() | 53 new SingleInstanceEngineProvider.EngineCreatedListener() |
| 53 { | 54 { |
| 54 @Override | 55 @Override |
| 55 public void onAdblockEngineCreated(AdblockEngine engine) | 56 public void onAdblockEngineCreated(AdblockEngine engine) |
| 56 { | 57 { |
| 57 AdblockSettings settings = storage.load(); | 58 AdblockSettings settings = storage.load(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 * Adblock Plus library will download subscription files and s tore them on | 135 * Adblock Plus library will download subscription files and s tore them on |
| 135 * the path passed. The path should exist and the directory co ntent should not be | 136 * the path passed. The path should exist and the directory co ntent should not be |
| 136 * cleared out occasionally. Using `context.getCacheDir().getA bsolutePath()` is not | 137 * cleared out occasionally. Using `context.getCacheDir().getA bsolutePath()` is not |
| 137 * recommended because it can be cleared by the system. | 138 * recommended because it can be cleared by the system. |
| 138 * @param developmentBuild debug or release? | 139 * @param developmentBuild debug or release? |
| 139 * @param preferenceName Shared Preferences name to store adblock settings | 140 * @param preferenceName Shared Preferences name to store adblock settings |
| 140 */ | 141 */ |
| 141 public SingleInstanceEngineProvider init(Context context, String basePath, | 142 public SingleInstanceEngineProvider init(Context context, String basePath, |
| 142 boolean developmentBuild, String pref erenceName) | 143 boolean developmentBuild, String pref erenceName) |
| 143 { | 144 { |
| 145 if (isInitialized) | |
| 146 { | |
| 147 new IllegalStateException("Usage exception: already initialized. Check `is Init()`"); | |
| 148 } | |
| 149 | |
| 144 initProvider(context, basePath, developmentBuild); | 150 initProvider(context, basePath, developmentBuild); |
| 145 initStorage(context, preferenceName); | 151 initStorage(context, preferenceName); |
| 152 isInitialized = true; | |
| 146 return provider; | 153 return provider; |
| 147 } | 154 } |
| 148 | 155 |
| 156 /** | |
| 157 * Check if it is already initialized | |
| 158 * @return | |
| 159 */ | |
| 160 public boolean isInit() { | |
|
jens
2018/02/07 09:36:25
for consistency I would probably call this method
anton
2018/02/07 09:52:55
initialize method is called `init()` to i've names
jens
2018/02/07 10:03:23
Okay, I don't insist to change it.
But it's kind
| |
| 161 return isInitialized; | |
| 162 } | |
| 163 | |
| 149 private void initProvider(Context context, String basePath, boolean developmen tBuild) | 164 private void initProvider(Context context, String basePath, boolean developmen tBuild) |
| 150 { | 165 { |
| 151 provider = new SingleInstanceEngineProvider(context, basePath, developmentBu ild); | 166 provider = new SingleInstanceEngineProvider(context, basePath, developmentBu ild); |
| 152 provider.addEngineCreatedListener(engineCreatedListener); | 167 provider.addEngineCreatedListener(engineCreatedListener); |
| 153 provider.addEngineDisposedListener(engineDisposedListener); | 168 provider.addEngineDisposedListener(engineDisposedListener); |
| 154 } | 169 } |
| 155 | 170 |
| 156 private void initStorage(Context context, String settingsPreferenceName) | 171 private void initStorage(Context context, String settingsPreferenceName) |
| 157 { | 172 { |
| 158 // read and apply current settings | 173 // read and apply current settings |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 | 216 |
| 202 /** | 217 /** |
| 203 * @deprecated The method is deprecated: use .getProvider().getCounter() inste ad | 218 * @deprecated The method is deprecated: use .getProvider().getCounter() inste ad |
| 204 */ | 219 */ |
| 205 @Deprecated | 220 @Deprecated |
| 206 public int getCounter() | 221 public int getCounter() |
| 207 { | 222 { |
| 208 return provider.getCounter(); | 223 return provider.getCounter(); |
| 209 } | 224 } |
| 210 } | 225 } |
| OLD | NEW |