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 29559597: Issue 5810 - Use "specialization" as Subscription display title (Closed)
Patch Set: fix Created Sept. 29, 2017, 8:38 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-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 16 matching lines...) Expand all
27 /** 27 /**
28 * Settings storage implementation in Shared Preferences 28 * Settings storage implementation in Shared Preferences
29 */ 29 */
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_SPECIALIZATION_KEY = "specia lization";
37 private static final String SETTINGS_SUBSCRIPTION_TITLE_KEY = "title"; 38 private static final String SETTINGS_SUBSCRIPTION_TITLE_KEY = "title";
38 private static final String SETTINGS_WL_DOMAINS_KEY = "whitelisted_domains"; 39 private static final String SETTINGS_WL_DOMAINS_KEY = "whitelisted_domains";
39 private static final String SETTINGS_WL_DOMAIN_KEY = "domain"; 40 private static final String SETTINGS_WL_DOMAIN_KEY = "domain";
40 private static final String SETTINGS_ALLOWED_CONNECTION_TYPE_KEY = "allowed_co nnection_type"; 41 private static final String SETTINGS_ALLOWED_CONNECTION_TYPE_KEY = "allowed_co nnection_type";
41 42
42 private SharedPreferences prefs; 43 private SharedPreferences prefs;
43 private boolean commit = true; 44 private boolean commit = true;
44 45
45 public SharedPrefsStorage(SharedPreferences prefs) 46 public SharedPrefsStorage(SharedPreferences prefs)
46 { 47 {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // count 109 // count
109 int subscriptionsCount = prefs.getInt(SETTINGS_SUBSCRIPTIONS_KEY, 0); 110 int subscriptionsCount = prefs.getInt(SETTINGS_SUBSCRIPTIONS_KEY, 0);
110 111
111 // each subscription 112 // each subscription
112 List<Subscription> subscriptions = new LinkedList<Subscription>(); 113 List<Subscription> subscriptions = new LinkedList<Subscription>();
113 for (int i = 0; i < subscriptionsCount; i++) 114 for (int i = 0; i < subscriptionsCount; i++)
114 { 115 {
115 Subscription subscription = new Subscription(); 116 Subscription subscription = new Subscription();
116 subscription.title = prefs.getString(getSubscriptionTitleKey(i), ""); 117 subscription.title = prefs.getString(getSubscriptionTitleKey(i), "");
117 subscription.url = prefs.getString(getSubscriptionURLKey(i), ""); 118 subscription.url = prefs.getString(getSubscriptionURLKey(i), "");
119 subscription.specialization = prefs.getString(getSubscriptionSpecializat ionKey(i), "");
118 subscriptions.add(subscription); 120 subscriptions.add(subscription);
119 } 121 }
120 settings.setSubscriptions(subscriptions); 122 settings.setSubscriptions(subscriptions);
121 } 123 }
122 } 124 }
123 125
124 private String getArrayItemKey(int index, String entity) 126 private String getArrayItemKey(int index, String entity)
125 { 127 {
126 // f.e. "domain0" 128 // f.e. "domain0"
127 return entity + index; 129 return entity + index;
128 } 130 }
129 131
130 private String getArrayItemKey(int index, String entity, String field) 132 private String getArrayItemKey(int index, String entity, String field)
131 { 133 {
132 // f.e. `subscription0.field` 134 // f.e. `subscription0.field`
133 return getArrayItemKey(index, entity) + "." + field; 135 return getArrayItemKey(index, entity) + "." + field;
134 } 136 }
135 137
136 private String getSubscriptionTitleKey(int index) 138 private String getSubscriptionTitleKey(int index)
137 { 139 {
138 return getArrayItemKey(index, SETTINGS_SUBSCRIPTION_KEY, SETTINGS_SUBSCRIPTI ON_TITLE_KEY); 140 return getArrayItemKey(index, SETTINGS_SUBSCRIPTION_KEY, SETTINGS_SUBSCRIPTI ON_TITLE_KEY);
139 } 141 }
140 142
141 private String getSubscriptionURLKey(int index) 143 private String getSubscriptionURLKey(int index)
142 { 144 {
143 return getArrayItemKey(index, SETTINGS_SUBSCRIPTION_KEY, SETTINGS_SUBSCRIPTI ON_URL_KEY); 145 return getArrayItemKey(index, SETTINGS_SUBSCRIPTION_KEY, SETTINGS_SUBSCRIPTI ON_URL_KEY);
144 } 146 }
145 147
148 private String getSubscriptionSpecializationKey(int index)
149 {
150 return getArrayItemKey(index, SETTINGS_SUBSCRIPTION_KEY, SETTINGS_SUBSCRIPTI ON_SPECIALIZATION_KEY);
151 }
152
146 @Override 153 @Override
147 public void save(AdblockSettings settings) 154 public void save(AdblockSettings settings)
148 { 155 {
149 SharedPreferences.Editor editor = prefs 156 SharedPreferences.Editor editor = prefs
150 .edit() 157 .edit()
151 .clear() 158 .clear()
152 .putBoolean(SETTINGS_ENABLED_KEY, settings.isAdblockEnabled()) 159 .putBoolean(SETTINGS_ENABLED_KEY, settings.isAdblockEnabled())
153 .putBoolean(SETTINGS_AA_ENABLED_KEY, settings.isAcceptableAdsEnabled()); 160 .putBoolean(SETTINGS_AA_ENABLED_KEY, settings.isAcceptableAdsEnabled());
154 161
155 if (settings.getAllowedConnectionType() != null) 162 if (settings.getAllowedConnectionType() != null)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if (settings.getSubscriptions() != null) 199 if (settings.getSubscriptions() != null)
193 { 200 {
194 // count 201 // count
195 editor.putInt(SETTINGS_SUBSCRIPTIONS_KEY, settings.getSubscriptions().size ()); 202 editor.putInt(SETTINGS_SUBSCRIPTIONS_KEY, settings.getSubscriptions().size ());
196 203
197 // each subscription 204 // each subscription
198 for (int i = 0; i < settings.getSubscriptions().size(); i++) 205 for (int i = 0; i < settings.getSubscriptions().size(); i++)
199 { 206 {
200 Subscription eachSubscription = settings.getSubscriptions().get(i); 207 Subscription eachSubscription = settings.getSubscriptions().get(i);
201 208
202 // warning: saving `title` and `url` fields only 209 // warning: saving `title`, `url` and `specialization` fields only
203 editor.putString(getSubscriptionTitleKey(i), eachSubscription.title); 210 editor.putString(getSubscriptionTitleKey(i), eachSubscription.title);
204 editor.putString(getSubscriptionURLKey(i), eachSubscription.url); 211 editor.putString(getSubscriptionURLKey(i), eachSubscription.url);
212 editor.putString(getSubscriptionSpecializationKey(i), eachSubscription.s pecialization);
205 } 213 }
206 } 214 }
207 } 215 }
208 } 216 }
OLDNEW

Powered by Google App Engine
This is Rietveld