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

Side by Side Diff: mobile/android/thirdparty/org/adblockplus/browser/SubscriptionPreferenceCategory.java

Issue 29322610: Issue 2720 - [Adblocking settings] Add the other filter lists category (Closed)
Patch Set: Changed screen title Created July 20, 2015, 5 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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 15 matching lines...) Expand all
26 import java.util.concurrent.Semaphore; 26 import java.util.concurrent.Semaphore;
27 27
28 import org.mozilla.gecko.R; 28 import org.mozilla.gecko.R;
29 import org.mozilla.gecko.util.NativeJSObject; 29 import org.mozilla.gecko.util.NativeJSObject;
30 import org.mozilla.gecko.util.ThreadUtils; 30 import org.mozilla.gecko.util.ThreadUtils;
31 import org.xmlpull.v1.XmlPullParser; 31 import org.xmlpull.v1.XmlPullParser;
32 import org.xmlpull.v1.XmlPullParserException; 32 import org.xmlpull.v1.XmlPullParserException;
33 33
34 import android.app.ProgressDialog; 34 import android.app.ProgressDialog;
35 import android.content.Context; 35 import android.content.Context;
36 import android.os.Handler;
37 import android.os.HandlerThread;
38 import android.preference.CheckBoxPreference; 36 import android.preference.CheckBoxPreference;
39 import android.preference.Preference; 37 import android.preference.Preference;
40 import android.preference.PreferenceCategory; 38 import android.preference.PreferenceCategory;
41 import android.util.AttributeSet; 39 import android.util.AttributeSet;
42 import android.util.Log; 40 import android.util.Log;
43 import android.util.Xml; 41 import android.util.Xml;
44 42
45 public class SubscriptionPreferenceCategory extends PreferenceCategory 43 public class SubscriptionPreferenceCategory extends PreferenceCategory
46 { 44 {
47 private static final HandlerThread HANDLER_THREAD;
48 private static final Handler HANDLER;
49
50 private volatile static SubscriptionContainer subscriptionContainer = null; 45 private volatile static SubscriptionContainer subscriptionContainer = null;
51 private final CheckBoxChangeListener checkBoxChangeListener = new CheckBoxChan geListener(); 46 private final CheckBoxChangeListener checkBoxChangeListener = new CheckBoxChan geListener();
52 private boolean isEnabledList = false; 47 private boolean isEnabledList = false;
53 private ProgressDialog progressDialog; 48 private ProgressDialog progressDialog;
54 49
55 static
56 {
57 HANDLER_THREAD = new HandlerThread("subscription-preference-background");
58 HANDLER_THREAD.setDaemon(true);
59 HANDLER_THREAD.start();
60 HANDLER = new Handler(HANDLER_THREAD.getLooper());
61 }
62
63 public SubscriptionPreferenceCategory(Context context) 50 public SubscriptionPreferenceCategory(Context context)
64 { 51 {
65 super(context); 52 super(context);
66 } 53 }
67 54
68 public SubscriptionPreferenceCategory(Context context, AttributeSet attrs) 55 public SubscriptionPreferenceCategory(Context context, AttributeSet attrs)
69 { 56 {
70 super(context, attrs); 57 super(context, attrs);
71 } 58 }
72 59
(...skipping 23 matching lines...) Expand all
96 83
97 this.setEnabled(false); 84 this.setEnabled(false);
98 this.setShouldDisableView(true); 85 this.setShouldDisableView(true);
99 86
100 super.onAttachedToActivity(); 87 super.onAttachedToActivity();
101 88
102 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 89 this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
103 this.progressDialog.setMessage(this.getContext().getString(R.string.abb_adbl ocking_waiting)); 90 this.progressDialog.setMessage(this.getContext().getString(R.string.abb_adbl ocking_waiting));
104 this.progressDialog.show(); 91 this.progressDialog.show();
105 92
106 HANDLER.post(new Runnable() 93 AddOnBridge.handlerPost(new Runnable()
107 { 94 {
108 @Override 95 @Override
109 public void run() 96 public void run()
110 { 97 {
111 initSubscriptions(); 98 initSubscriptions();
112 ThreadUtils.postToUiThread(new Runnable() 99 ThreadUtils.postToUiThread(new Runnable()
113 { 100 {
114 @Override 101 @Override
115 public void run() 102 public void run()
116 { 103 {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 final CheckBoxPreference cbp = (CheckBoxPreference) preference; 181 final CheckBoxPreference cbp = (CheckBoxPreference) preference;
195 final boolean enable = ((Boolean) newValue).booleanValue(); 182 final boolean enable = ((Boolean) newValue).booleanValue();
196 SubscriptionPreferenceCategory.subscriptionContainer.changeSubscriptionS tate( 183 SubscriptionPreferenceCategory.subscriptionContainer.changeSubscriptionS tate(
197 cbp.getKey(), 184 cbp.getKey(),
198 enable); 185 enable);
199 } 186 }
200 return true; 187 return true;
201 } 188 }
202 } 189 }
203 190
204 private final static class SubscriptionContainer implements AdblockPlusApiCall back 191 final static class SubscriptionContainer implements AdblockPlusApiCallback
205 { 192 {
206 private static final String TAG = SubscriptionContainer.class.getName(); 193 private static final String TAG = SubscriptionContainer.class.getName();
207 private final ConcurrentHashMap<String, Boolean> enableState = new Concurren tHashMap<String, Boolean>(); 194 private final ConcurrentHashMap<String, Boolean> enableState = new Concurren tHashMap<String, Boolean>();
208 private final Semaphore entriesReady = new Semaphore(0); 195 private final Semaphore entriesReady = new Semaphore(0);
209 private final List<Subscription> entries = new ArrayList<Subscription>(); 196 private final List<Subscription> entries = new ArrayList<Subscription>();
210 private final HashMap<String, Subscription> urlMap = new HashMap<String, Sub scription>(); 197 private final HashMap<String, Subscription> urlMap = new HashMap<String, Sub scription>();
211 198
212 private SubscriptionContainer() 199 private SubscriptionContainer()
213 { 200 {
214 // prevent external instantiation 201 // prevent external instantiation
215 } 202 }
216 203
217 public final static SubscriptionContainer create() 204 public final static SubscriptionContainer create()
218 { 205 {
206 return create(true);
207 }
208
209 public final static SubscriptionContainer create(final boolean refresh)
210 {
219 final SubscriptionContainer sc = new SubscriptionContainer(); 211 final SubscriptionContainer sc = new SubscriptionContainer();
220 AddOnBridge.queryValue(sc, "subscriptionsXml"); 212 AddOnBridge.queryValue(sc, "subscriptionsXml");
221 sc.entriesReady.acquireUninterruptibly(); 213 sc.entriesReady.acquireUninterruptibly();
222 214
223 for (final Subscription e : sc.entries) 215 for (final Subscription e : sc.entries)
224 { 216 {
225 sc.urlMap.put(e.url, e); 217 sc.urlMap.put(e.url, e);
226 sc.enableState.put(e.url, Boolean.FALSE); 218 sc.enableState.put(e.url, Boolean.FALSE);
227 } 219 }
228 220
229 sc.refresh(); 221 if (refresh)
222 {
223 sc.refresh();
224 }
230 225
231 return sc; 226 return sc;
232 } 227 }
233 228
234 public void refresh() 229 public void refresh()
235 { 230 {
236 if (!this.entries.isEmpty()) 231 if (!this.entries.isEmpty())
237 { 232 {
238 for (int i = 0; i < this.entries.size(); i++) 233 for (int i = 0; i < this.entries.size(); i++)
239 { 234 {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 429
435 @Override 430 @Override
436 public String toString() 431 public String toString()
437 { 432 {
438 return this.specialization + " (" + this.title + ") @ " + this.url; 433 return this.specialization + " (" + this.title + ") @ " + this.url;
439 } 434 }
440 } 435 }
441 } 436 }
442 } 437 }
443 438
OLDNEW

Powered by Google App Engine
This is Rietveld