OLD | NEW |
| (Empty) |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-present eyeo GmbH | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
16 */ | |
17 | |
18 package org.adblockplus.libadblockplus.android.settings; | |
19 | |
20 import org.adblockplus.libadblockplus.android.AdblockEngine; | |
21 import org.adblockplus.libadblockplus.android.ConnectionType; | |
22 import org.adblockplus.libadblockplus.android.Subscription; | |
23 | |
24 import java.util.LinkedList; | |
25 import java.util.List; | |
26 | |
27 /** | |
28 * Settings storage base class | |
29 */ | |
30 public abstract class AdblockSettingsStorage | |
31 { | |
32 /** | |
33 * Load settings from the storage | |
34 * | |
35 * Warning: can return null if not saved yet | |
36 * Warning: subscriptions can have `url` and `title` only to be identified amo
ng available in AdblockEngine | |
37 * @return AdblockSettings instance or null | |
38 */ | |
39 public abstract AdblockSettings load(); | |
40 | |
41 /** | |
42 * Save settings to the storage | |
43 * | |
44 * @param settings should be not null | |
45 */ | |
46 public abstract void save(AdblockSettings settings); | |
47 | |
48 /** | |
49 * Get default settings | |
50 * | |
51 * @param adblockEngine adblock engine | |
52 * @return not null default settings | |
53 */ | |
54 public static AdblockSettings getDefaultSettings(AdblockEngine adblockEngine) | |
55 { | |
56 AdblockSettings settings = new AdblockSettings(); | |
57 | |
58 // read actual values from adblock engine | |
59 settings.setAdblockEnabled(adblockEngine.isEnabled()); | |
60 settings.setAcceptableAdsEnabled(adblockEngine.isAcceptableAdsEnabled()); | |
61 String allowedConnectionTypeValue = adblockEngine.getFilterEngine().getAllow
edConnectionType(); | |
62 settings.setAllowedConnectionType(ConnectionType.findByValue(allowedConnecti
onTypeValue)); | |
63 | |
64 // we need to filter out exceptions subscription to show languages subscript
ions only | |
65 Subscription[] listedSubscriptions = adblockEngine.getListedSubscriptions(); | |
66 List<Subscription> subscriptionsWithoutAA = new LinkedList<Subscription>(); | |
67 String acceptableAdsURL = adblockEngine.getAcceptableAdsSubscriptionURL(); | |
68 | |
69 for (Subscription eachListedSubscription : listedSubscriptions) | |
70 { | |
71 if (!eachListedSubscription.url.equals(acceptableAdsURL)) | |
72 { | |
73 subscriptionsWithoutAA.add(eachListedSubscription); | |
74 } | |
75 } | |
76 | |
77 settings.setSubscriptions(subscriptionsWithoutAA); | |
78 | |
79 return settings; | |
80 } | |
81 } | |
OLD | NEW |