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

Side by Side Diff: libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/SharedPrefsStorage.java

Issue 29379647: Issue 4948 - add possibility to not send data depending on connection properties (Closed)
Patch Set: migrated from FilterEngine* to FilterEnginePtr*, minor improvements Created March 15, 2017, 12:48 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 19 matching lines...) Expand all
30 public class SharedPrefsStorage extends AdblockSettingsStorage 30 public class SharedPrefsStorage extends AdblockSettingsStorage
31 { 31 {
32 private static final String SETTINGS_ENABLED_KEY = "enabled"; 32 private static final String SETTINGS_ENABLED_KEY = "enabled";
33 private static final String SETTINGS_AA_ENABLED_KEY = "aa_enabled"; 33 private static final String SETTINGS_AA_ENABLED_KEY = "aa_enabled";
34 private static final String SETTINGS_SUBSCRIPTIONS_KEY = "subscriptions"; 34 private static final String SETTINGS_SUBSCRIPTIONS_KEY = "subscriptions";
35 private static final String SETTINGS_SUBSCRIPTION_KEY = "subscription"; 35 private static final String SETTINGS_SUBSCRIPTION_KEY = "subscription";
36 private static final String SETTINGS_SUBSCRIPTION_URL_KEY = "url"; 36 private static final String SETTINGS_SUBSCRIPTION_URL_KEY = "url";
37 private static final String SETTINGS_SUBSCRIPTION_TITLE_KEY = "title"; 37 private static final String SETTINGS_SUBSCRIPTION_TITLE_KEY = "title";
38 private static final String SETTINGS_WL_DOMAINS_KEY = "whitelisted_domains"; 38 private static final String SETTINGS_WL_DOMAINS_KEY = "whitelisted_domains";
39 private static final String SETTINGS_WL_DOMAIN_KEY = "domain"; 39 private static final String SETTINGS_WL_DOMAIN_KEY = "domain";
40 private static final String SETTINGS_ALLOWED_CONNECTION_TYPE_KEY = "allowed_co nnection_type";
40 41
41 private SharedPreferences prefs; 42 private SharedPreferences prefs;
42 private boolean commit = true; 43 private boolean commit = true;
43 44
44 public SharedPrefsStorage(SharedPreferences prefs) 45 public SharedPrefsStorage(SharedPreferences prefs)
45 { 46 {
46 this.prefs = prefs; 47 this.prefs = prefs;
47 } 48 }
48 49
49 public boolean isCommit() 50 public boolean isCommit()
(...skipping 16 matching lines...) Expand all
66 { 67 {
67 if (!prefs.contains(SETTINGS_ENABLED_KEY)) 68 if (!prefs.contains(SETTINGS_ENABLED_KEY))
68 { 69 {
69 // settings were not saved yet 70 // settings were not saved yet
70 return null; 71 return null;
71 } 72 }
72 73
73 AdblockSettings settings = new AdblockSettings(); 74 AdblockSettings settings = new AdblockSettings();
74 settings.setAdblockEnabled(prefs.getBoolean(SETTINGS_ENABLED_KEY, true)); 75 settings.setAdblockEnabled(prefs.getBoolean(SETTINGS_ENABLED_KEY, true));
75 settings.setAcceptableAdsEnabled(prefs.getBoolean(SETTINGS_AA_ENABLED_KEY, t rue)); 76 settings.setAcceptableAdsEnabled(prefs.getBoolean(SETTINGS_AA_ENABLED_KEY, t rue));
77 String connectionType = prefs.getString(SETTINGS_ALLOWED_CONNECTION_TYPE_KEY , null);
78 settings.setAllowedConnectionType(ConnectionType.findByValue(connectionType) );
76 79
77 loadSubscriptions(settings); 80 loadSubscriptions(settings);
78 loadWhitelistedDomains(settings); 81 loadWhitelistedDomains(settings);
79 82
80 return settings; 83 return settings;
81 } 84 }
82 85
83 private void loadWhitelistedDomains(AdblockSettings settings) 86 private void loadWhitelistedDomains(AdblockSettings settings)
84 { 87 {
85 if (prefs.contains(SETTINGS_WL_DOMAINS_KEY)) 88 if (prefs.contains(SETTINGS_WL_DOMAINS_KEY))
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 145
143 @Override 146 @Override
144 public void save(AdblockSettings settings) 147 public void save(AdblockSettings settings)
145 { 148 {
146 SharedPreferences.Editor editor = prefs 149 SharedPreferences.Editor editor = prefs
147 .edit() 150 .edit()
148 .clear() 151 .clear()
149 .putBoolean(SETTINGS_ENABLED_KEY, settings.isAdblockEnabled()) 152 .putBoolean(SETTINGS_ENABLED_KEY, settings.isAdblockEnabled())
150 .putBoolean(SETTINGS_AA_ENABLED_KEY, settings.isAcceptableAdsEnabled()); 153 .putBoolean(SETTINGS_AA_ENABLED_KEY, settings.isAcceptableAdsEnabled());
151 154
155 if (settings.getAllowedConnectionType() != null)
156 {
157 editor.putString(SETTINGS_ALLOWED_CONNECTION_TYPE_KEY, settings.getAllowed ConnectionType().getValue());
158 }
159
152 saveSubscriptions(settings, editor); 160 saveSubscriptions(settings, editor);
153 saveWhitelistedDomains(settings, editor); 161 saveWhitelistedDomains(settings, editor);
154 162
155 if (commit) 163 if (commit)
156 { 164 {
157 editor.commit(); 165 editor.commit();
158 } 166 }
159 else 167 else
160 { 168 {
161 // faster but not finished most likely before return 169 // faster but not finished most likely before return
(...skipping 29 matching lines...) Expand all
191 { 199 {
192 Subscription eachSubscription = settings.getSubscriptions().get(i); 200 Subscription eachSubscription = settings.getSubscriptions().get(i);
193 201
194 // warning: saving `title` and `url` fields only 202 // warning: saving `title` and `url` fields only
195 editor.putString(getSubscriptionTitleKey(i), eachSubscription.title); 203 editor.putString(getSubscriptionTitleKey(i), eachSubscription.title);
196 editor.putString(getSubscriptionURLKey(i), eachSubscription.url); 204 editor.putString(getSubscriptionURLKey(i), eachSubscription.url);
197 } 205 }
198 } 206 }
199 } 207 }
200 } 208 }
OLDNEW

Powered by Google App Engine
This is Rietveld