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

Delta Between Two Patch Sets: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/MoreBlockingPreferenceCategory.java

Issue 29524668: Issue 3916 - Supporting Adding filter lists via URL (Closed)
Left Patch Set: fixes Created Oct. 4, 2017, 3:14 p.m.
Right Patch Set: Use TAG constant for log, fix in MoreBlockingPreferenceCategory Created Oct. 10, 2017, 1:57 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.sbrowser.contentblocker; 18 package org.adblockplus.sbrowser.contentblocker;
19 19
20 import java.io.IOException; 20 import java.io.IOException;
21 import java.util.ArrayList; 21 import java.util.ArrayList;
22 import java.util.Collections; 22 import java.util.Collections;
23 import java.util.Comparator; 23 import java.util.Comparator;
24 import java.util.HashMap; 24 import java.util.HashMap;
25 import java.util.List; 25 import java.util.List;
26 import java.util.Map;
26 27
27 import org.adblockplus.sbrowser.contentblocker.engine.DefaultSubscriptionInfo; 28 import org.adblockplus.sbrowser.contentblocker.engine.DefaultSubscriptionInfo;
28 import org.adblockplus.sbrowser.contentblocker.engine.Engine; 29 import org.adblockplus.sbrowser.contentblocker.engine.Engine;
29 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; 30 import org.adblockplus.sbrowser.contentblocker.engine.EngineService;
30 import org.adblockplus.sbrowser.contentblocker.engine.SubscriptionInfo; 31 import org.adblockplus.sbrowser.contentblocker.engine.SubscriptionInfo;
31 import org.adblockplus.adblockplussbrowser.R; 32 import org.adblockplus.adblockplussbrowser.R;
32 import org.adblockplus.sbrowser.contentblocker.preferences.MultilineCheckBoxPref erence; 33 import org.adblockplus.sbrowser.contentblocker.preferences.MultilineCheckBoxPref erence;
33 34
34 import android.content.Context; 35 import android.content.Context;
35 import android.preference.Preference; 36 import android.preference.Preference;
(...skipping 16 matching lines...) Expand all
52 }; 53 };
53 54
54 private static final String[] WHITELISTED_LIST_URLS = 55 private static final String[] WHITELISTED_LIST_URLS =
55 { 56 {
56 "https://easylist-downloads.adblockplus.org/easyprivacy.txt", 57 "https://easylist-downloads.adblockplus.org/easyprivacy.txt",
57 "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt", 58 "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt",
58 "https://easylist-downloads.adblockplus.org/antiadblockfilters.txt", 59 "https://easylist-downloads.adblockplus.org/antiadblockfilters.txt",
59 "https://easylist-downloads.adblockplus.org/fanboy-social.txt" 60 "https://easylist-downloads.adblockplus.org/fanboy-social.txt"
60 }; 61 };
61 62
62 public static final HashMap<String, Integer> URL_TO_RES_ID_MAP = new HashMap<> (); 63 private static final Map<String, Integer> URL_TO_RES_ID_MAP = new HashMap<>();
anton 2017/10/10 06:28:06 according to "programming to interface" i'd prefer
jens 2017/10/10 08:09:10 I did not introduce URL_TO_RES_ID_MAP but only cha
anton 2017/10/10 08:15:06 okay, then it's fine for now
diegocarloslima 2017/10/10 13:08:28 URL_TO_RES_ID_MAP is now only used here, isn't it?
jens 2017/10/10 13:56:40 As I have to make changes anyways, I'll change tha
jens 2017/10/10 13:56:41 Acknowledged.
63 64
64 static 65 static
65 { 66 {
66 for (int i = 0; i < WHITELISTED_LIST_TITLES.length; i++) 67 for (int i = 0; i < WHITELISTED_LIST_TITLES.length; i++)
67 { 68 {
68 URL_TO_RES_ID_MAP.put(WHITELISTED_LIST_URLS[i], WHITELISTED_LIST_TITLES[i] ); 69 URL_TO_RES_ID_MAP.put(WHITELISTED_LIST_URLS[i], WHITELISTED_LIST_TITLES[i] );
69 } 70 }
70 } 71 }
71 72
72 public MoreBlockingPreferenceCategory(final Context context) 73 public MoreBlockingPreferenceCategory(final Context context)
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 { 202 {
202 List<SubscriptionInfo> moreBlockingPreferenceSubscriptions = new ArrayList<> (5); 203 List<SubscriptionInfo> moreBlockingPreferenceSubscriptions = new ArrayList<> (5);
203 for (SubscriptionInfo sub : engine.getListedSubscriptions()) 204 for (SubscriptionInfo sub : engine.getListedSubscriptions())
204 { 205 {
205 final DefaultSubscriptionInfo info = engine.getDefaultSubscriptionInfoForU rl(sub.getUrl()); 206 final DefaultSubscriptionInfo info = engine.getDefaultSubscriptionInfoForU rl(sub.getUrl());
206 Integer resInt = URL_TO_RES_ID_MAP.get(sub.getUrl()); 207 Integer resInt = URL_TO_RES_ID_MAP.get(sub.getUrl());
207 208
208 if (sub.getType() == SubscriptionInfo.Type.CUSTOM) 209 if (sub.getType() == SubscriptionInfo.Type.CUSTOM)
209 { 210 {
210 moreBlockingPreferenceSubscriptions.add(sub); 211 moreBlockingPreferenceSubscriptions.add(sub);
212 continue;
211 } 213 }
212 214
213 if (info != null && !info.isComplete() && sub.isEnabled()) 215 if (info != null && !info.isComplete() && sub.isEnabled())
214 { 216 {
215 moreBlockingPreferenceSubscriptions.add(sub); 217 moreBlockingPreferenceSubscriptions.add(sub);
218 continue;
216 } 219 }
217 220
218 if ((!(engine.isAcceptableAdsUrl(sub)) || sub.getTitle().startsWith("__")) 221 if ((!(engine.isAcceptableAdsUrl(sub)) || sub.getTitle().startsWith("__"))
219 && resInt != null 222 && resInt != null
220 && (info == null || info.getPrefixes().isEmpty() || sub.getType() != S ubscriptionInfo.Type.ADS)) 223 && (info == null || info.getPrefixes().isEmpty() || sub.getType() != S ubscriptionInfo.Type.ADS))
221 { 224 {
222 moreBlockingPreferenceSubscriptions.add(sub); 225 moreBlockingPreferenceSubscriptions.add(sub);
226 continue;
223 } 227 }
224 } 228 }
225 229
226 return moreBlockingPreferenceSubscriptions; 230 return moreBlockingPreferenceSubscriptions;
227 } 231 }
228 232
229 @Override 233 @Override
230 public boolean onPreferenceChange(final Preference preference, final Object ne wValue) 234 public boolean onPreferenceChange(final Preference preference, final Object ne wValue)
231 { 235 {
232 final String id = preference.getKey(); 236 final String id = preference.getKey();
233 final boolean enabled = (Boolean) newValue; 237 final boolean enabled = (Boolean) newValue;
234 238
235 this.engine.changeSubscriptionState(id, enabled); 239 this.engine.changeSubscriptionState(id, enabled);
236 240
237 return true; 241 return true;
238 } 242 }
239 243
240 @Override 244 @Override
241 public void subscriptionAdded() 245 public void subscriptionAdded()
242 { 246 {
243 refreshEntries(); 247 refreshEntries();
244 } 248 }
245 } 249 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld