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

Side by Side Diff: mobile/android/base/java/org/adblockplus/browser/MoreSubscriptionsPreferenceGroup.java

Issue 30046562: Issue 7458 - Duplicate entries for EasyPrivacy and Fanboy's Social Blocking List
Patch Set: Created April 16, 2019, 2:06 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
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.browser; 18 package org.adblockplus.browser;
19 19
20 import java.util.Arrays;
20 import java.util.HashMap; 21 import java.util.HashMap;
21 import java.util.HashSet; 22 import java.util.HashSet;
23 import java.util.List;
22 import java.util.Map.Entry; 24 import java.util.Map.Entry;
25 import java.util.Set;
23 import java.util.concurrent.Semaphore; 26 import java.util.concurrent.Semaphore;
24 27
25 import org.mozilla.gecko.R; 28 import org.mozilla.gecko.R;
26 import org.mozilla.gecko.preferences.CustomCheckBoxPreference; 29 import org.mozilla.gecko.preferences.CustomCheckBoxPreference;
27 import org.mozilla.gecko.util.GeckoBundle; 30 import org.mozilla.gecko.util.GeckoBundle;
28 import org.mozilla.gecko.util.ThreadUtils; 31 import org.mozilla.gecko.util.ThreadUtils;
29 32
30 import android.app.ProgressDialog; 33 import android.app.ProgressDialog;
31 import android.content.Context; 34 import android.content.Context;
32 import android.os.Build; 35 import android.os.Build;
33 import android.preference.CheckBoxPreference; 36 import android.preference.CheckBoxPreference;
34 import android.preference.Preference; 37 import android.preference.Preference;
35 import android.preference.PreferenceGroup; 38 import android.preference.PreferenceGroup;
36 import android.util.AttributeSet; 39 import android.util.AttributeSet;
37 import android.util.Log; 40 import android.util.Log;
38 import android.view.View; 41 import android.view.View;
39 import android.view.ViewGroup; 42 import android.view.ViewGroup;
40 43
41 public class MoreSubscriptionsPreferenceGroup extends PreferenceGroup implements 44 public class MoreSubscriptionsPreferenceGroup extends PreferenceGroup implements
42 InputValidatorDialogPreference.OnInputReadyListener 45 InputValidatorDialogPreference.OnInputReadyListener
43 { 46 {
44 private static final String TAG = "AdblockBrowser.OtherPreferenceGroup"; 47 private static final String TAG = "AdblockBrowser.OtherPreferenceGroup";
45 private static final HashMap<String, Integer> BUILTIN_URL_TO_INDEX = new HashM ap<String, Integer>(); 48
46 private static final HashSet<String> IGNORED_URLS = new HashSet<String>(); 49 public static final List<String> BUILTIN_URLS = Arrays.asList(
50 "https://easylist-downloads.adblockplus.org/easyprivacy.txt",
anton 2019/04/17 09:46:35 the order of `BUILTIN_URLS` should be consistent t
51 "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt",
52 "https://easylist-downloads.adblockplus.org/antiadblockfilters.txt",
53 "https://easylist-downloads.adblockplus.org/fanboy-social.txt"
54 );
55
56 private static final List<Integer> BUILTIN_TITLES = Arrays.asList(
57 R.string.abb_subscription_disable_tracking,
58 R.string.abb_subscription_disable_malware,
59 R.string.abb_subscription_disable_anti_adblock,
60 R.string.abb_subscription_disable_social_media
61 );
62
63 private static final Set<String> IGNORED_URLS = new HashSet<>(Arrays.asList(
64 "https://easylist-downloads.adblockplus.org/exceptionrules.txt"
65 ));
66
67 private static final String USER_SUBSCRIPTION_PREFIX = "~user~";
68
47 private static SubscriptionContainer recommendedSubscriptions = null; 69 private static SubscriptionContainer recommendedSubscriptions = null;
48 70
49 private final CheckBoxChangeListener checkBoxChangeListener = new CheckBoxChan geListener(); 71 private final CheckBoxChangeListener checkBoxChangeListener = new CheckBoxChan geListener();
50 private final ActiveSubscriptionContainer activeSubscriptions = new ActiveSubs criptionContainer(); 72 private final ActiveSubscriptionContainer activeSubscriptions = new ActiveSubs criptionContainer();
51 private ProgressDialog progressDialog; 73 private ProgressDialog progressDialog;
52 74
53 private static final int[] BUILTIN_TITLES =
54 {
55 R.string.abb_subscription_disable_tracking,
56 R.string.abb_subscription_disable_malware,
57 R.string.abb_subscription_disable_anti_adblock,
58 R.string.abb_subscription_disable_social_media
59 };
60
61 private static final String[] BUILTIN_LISTS =
62 {
63 "EasyPrivacy",
64 "https://easylist-downloads.adblockplus.org/easyprivacy.txt",
65 "Malware Domains",
66 "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt",
67 "Adblock Warning Removal List",
68 "https://easylist-downloads.adblockplus.org/antiadblockfilters.txt",
69 "Fanboy's Social Blocking List",
70 "https://easylist-downloads.adblockplus.org/fanboy-social.txt"
71 };
72
73 private static final String USER_SUBSCRIPTION_PREFIX = "~user~";
74
75 static
76 {
77 for (int i = 0; i < BUILTIN_TITLES.length; i++)
78 {
79 BUILTIN_URL_TO_INDEX.put(BUILTIN_LISTS[i * 2 + 1], Integer.valueOf(i));
80 }
81
82 IGNORED_URLS.add("https://easylist-downloads.adblockplus.org/exceptionrules. txt");
83 }
84
85 private synchronized static void initRecommendedSubscriptions(final Context co ntext) 75 private synchronized static void initRecommendedSubscriptions(final Context co ntext)
86 { 76 {
87 if (recommendedSubscriptions == null) 77 if (recommendedSubscriptions == null)
88 { 78 {
89 recommendedSubscriptions = SubscriptionContainer.create(context, false); 79 recommendedSubscriptions = SubscriptionContainer.create(context, false);
90 80
91 for (SubscriptionContainer.Subscription s : recommendedSubscriptions.getSu bscriptions(false)) 81 for (SubscriptionContainer.Subscription s : recommendedSubscriptions.getSu bscriptions(false))
92 { 82 {
93 IGNORED_URLS.add(s.url); 83 if(!BUILTIN_URLS.contains(s.url))
jens 2019/04/17 09:39:22 The white space after the if is missing
84 {
85 IGNORED_URLS.add(s.url);
86 }
94 } 87 }
95 } 88 }
96 } 89 }
97 90
98 public MoreSubscriptionsPreferenceGroup(final Context context, final Attribute Set attrs) 91 public MoreSubscriptionsPreferenceGroup(final Context context, final Attribute Set attrs)
99 { 92 {
100 this(context, attrs, 0); 93 this(context, attrs, 0);
101 } 94 }
102 95
103 public MoreSubscriptionsPreferenceGroup(final Context context, final Attribute Set attrs, 96 public MoreSubscriptionsPreferenceGroup(final Context context, final Attribute Set attrs,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 MoreSubscriptionsPreferenceGroup.this.initEntries(); 154 MoreSubscriptionsPreferenceGroup.this.initEntries();
162 } 155 }
163 }); 156 });
164 } 157 }
165 }); 158 });
166 } 159 }
167 160
168 private void initEntries() 161 private void initEntries()
169 { 162 {
170 this.removeAll(); 163 this.removeAll();
171 for (int i = 0; i < BUILTIN_TITLES.length; i++) 164 for (int i = 0; i < BUILTIN_TITLES.size(); i++)
172 { 165 {
173 final CheckBoxPreference cbp = new CustomCheckBoxPreference(this.getContex t()); 166 final CheckBoxPreference cbp = new CustomCheckBoxPreference(this.getContex t());
174 final String url = BUILTIN_LISTS[i * 2 + 1]; 167 final String url = BUILTIN_URLS.get(i);
175 cbp.setTitle(BUILTIN_TITLES[i]); 168 cbp.setTitle(BUILTIN_TITLES.get(i));
176 cbp.setKey(url); 169 cbp.setKey(url);
177 cbp.setChecked(this.activeSubscriptions.enabledSubscriptions.containsKey(u rl)); 170 cbp.setChecked(this.activeSubscriptions.enabledSubscriptions.containsKey(u rl));
178 cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener); 171 cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener);
179 cbp.setPersistent(false); 172 cbp.setPersistent(false);
180 this.addPreference(cbp); 173 this.addPreference(cbp);
181 } 174 }
182 175
183 for (Entry<String, String> e : this.activeSubscriptions.enabledSubscriptions .entrySet()) 176 for (Entry<String, String> e : this.activeSubscriptions.enabledSubscriptions .entrySet())
184 { 177 {
185 if (!BUILTIN_URL_TO_INDEX.containsKey(e.getKey())) 178 if (!BUILTIN_URLS.contains(e.getKey()))
186 { 179 {
187 final CheckBoxPreference cbp = new CustomCheckBoxPreference(this.getCont ext()); 180 final CheckBoxPreference cbp = new CustomCheckBoxPreference(this.getCont ext());
188 cbp.setTitle(e.getValue()); 181 cbp.setTitle(e.getValue());
189 cbp.setKey(e.getKey()); 182 cbp.setKey(e.getKey());
190 cbp.setChecked(true); 183 cbp.setChecked(true);
191 cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener); 184 cbp.setOnPreferenceChangeListener(this.checkBoxChangeListener);
192 cbp.setPersistent(false); 185 cbp.setPersistent(false);
193 this.addPreference(cbp); 186 this.addPreference(cbp);
194 } 187 }
195 } 188 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 // ignored 339 // ignored
347 } 340 }
348 341
349 @Override 342 @Override
350 public void onApiRequestFailed(String errorMessage) 343 public void onApiRequestFailed(String errorMessage)
351 { 344 {
352 // ignored 345 // ignored
353 } 346 }
354 } 347 }
355 } 348 }
OLDNEW

Powered by Google App Engine
This is Rietveld