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

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

Issue 29572644: Noissue - Lint adjustments
Patch Set: Created Oct. 10, 2017, 12:03 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 private final Semaphore entriesReady = new Semaphore(0); 42 private final Semaphore entriesReady = new Semaphore(0);
43 private final List<SubscriptionContainer.Subscription> entries = new ArrayList <>(); 43 private final List<SubscriptionContainer.Subscription> entries = new ArrayList <>();
44 private final HashMap<String, SubscriptionContainer.Subscription> urlMap = new HashMap<>(); 44 private final HashMap<String, SubscriptionContainer.Subscription> urlMap = new HashMap<>();
45 private final List<WeakReference<SubscriptionListener>> subscriptionListeners = new ArrayList<>(); 45 private final List<WeakReference<SubscriptionListener>> subscriptionListeners = new ArrayList<>();
46 46
47 private SubscriptionContainer() 47 private SubscriptionContainer()
48 { 48 {
49 // prevent external instantiation 49 // prevent external instantiation
50 } 50 }
51 51
52 public final static SubscriptionContainer create() 52 public static SubscriptionContainer create()
53 { 53 {
54 return create(true); 54 return create(true);
55 } 55 }
56 56
57 public final static SubscriptionContainer create(final boolean refresh) 57 public static SubscriptionContainer create(final boolean refresh)
58 { 58 {
59 final SubscriptionContainer sc = new SubscriptionContainer(); 59 final SubscriptionContainer sc = new SubscriptionContainer();
60 AddOnBridge.queryValue(sc, "subscriptionsXml"); 60 AddOnBridge.queryValue(sc, "subscriptionsXml");
61 sc.entriesReady.acquireUninterruptibly(); 61 sc.entriesReady.acquireUninterruptibly();
62 62
63 for (final SubscriptionContainer.Subscription e : sc.entries) 63 for (final SubscriptionContainer.Subscription e : sc.entries)
64 { 64 {
65 sc.urlMap.put(e.url, e); 65 sc.urlMap.put(e.url, e);
66 sc.enableState.put(e.url, Boolean.FALSE); 66 sc.enableState.put(e.url, Boolean.FALSE);
67 } 67 }
(...skipping 29 matching lines...) Expand all
97 if (this.isSubscriptionListed(e.url) == enabled) 97 if (this.isSubscriptionListed(e.url) == enabled)
98 { 98 {
99 ret.add(e); 99 ret.add(e);
100 } 100 }
101 } 101 }
102 return ret; 102 return ret;
103 } 103 }
104 104
105 public boolean isSubscriptionListed(final String url) 105 public boolean isSubscriptionListed(final String url)
106 { 106 {
107 return this.enableState.containsKey(url) && this.enableState.get(url).boolea nValue(); 107 return this.enableState.containsKey(url) && this.enableState.get(url);
108 } 108 }
109 109
110 public void changeSubscriptionState(final String url, final boolean enable) 110 public void changeSubscriptionState(final String url, final boolean enable)
111 { 111 {
112 final SubscriptionContainer.Subscription e = this.urlMap.get(url); 112 final SubscriptionContainer.Subscription e = this.urlMap.get(url);
113 if (e != null) 113 if (e != null)
114 { 114 {
115 if (enable) 115 if (enable)
116 { 116 {
117 SubscriptionChangeAction.post(e, SubscriptionPreferenceCategory.subscrip tionContainer, 117 SubscriptionChangeAction.post(e, SubscriptionPreferenceCategory.subscrip tionContainer,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 if ("subscription".equals(parser.getName())) 171 if ("subscription".equals(parser.getName()))
172 { 172 {
173 final String title = parser.getAttributeValue(null, "title"); 173 final String title = parser.getAttributeValue(null, "title");
174 final String specialization = parser.getAttributeValue(null, "speciali zation"); 174 final String specialization = parser.getAttributeValue(null, "speciali zation");
175 final String url = parser.getAttributeValue(null, "url"); 175 final String url = parser.getAttributeValue(null, "url");
176 this.entries.add(new Subscription(title, specialization, url)); 176 this.entries.add(new Subscription(title, specialization, url));
177 } 177 }
178 parser.next(); 178 parser.next();
179 } 179 }
180 } 180 }
181 catch (XmlPullParserException e) 181 catch (XmlPullParserException | IOException e)
182 {
183 Log.e(TAG, "Failed to parse subscriptions.xml: " + e.getMessage(), e);
184 }
185 catch (IOException e)
186 { 182 {
187 Log.e(TAG, "Failed to parse subscriptions.xml: " + e.getMessage(), e); 183 Log.e(TAG, "Failed to parse subscriptions.xml: " + e.getMessage(), e);
188 } 184 }
189 finally 185 finally
190 { 186 {
191 this.entriesReady.release(); 187 this.entriesReady.release();
192 } 188 }
193 } 189 }
194 190
195 @Override 191 @Override
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 247
252 @Override 248 @Override
253 public void onApiRequestSucceeded(NativeJSObject jsObject) 249 public void onApiRequestSucceeded(NativeJSObject jsObject)
254 { 250 {
255 switch (this.mode) 251 switch (this.mode)
256 { 252 {
257 case QUERY_SUBSCRIPTION_ENABLED: 253 case QUERY_SUBSCRIPTION_ENABLED:
258 try 254 try
259 { 255 {
260 this.parent.enableState.put(this.subscription.url, 256 this.parent.enableState.put(this.subscription.url,
261 Boolean.valueOf(AddOnBridge.getBooleanFromJsObject(jsObject, "va lue", false))); 257 AddOnBridge.getBooleanFromJsObject(jsObject, "value", false));
262 } 258 }
263 finally 259 finally
264 { 260 {
265 this.parent.entriesReady.release(); 261 this.parent.entriesReady.release();
266 } 262 }
267 break; 263 break;
268 case ENABLE_SUBSCRIPTION: 264 case ENABLE_SUBSCRIPTION:
269 case DISABLE_SUBSCRIPTION: 265 case DISABLE_SUBSCRIPTION:
270 this.parent.enableState.put(this.subscription.url, this.mode == Mode.E NABLE_SUBSCRIPTION); 266 this.parent.enableState.put(this.subscription.url, this.mode == Mode.E NABLE_SUBSCRIPTION);
271 final Iterator<WeakReference<SubscriptionListener>> iterator = this.pa rent.subscriptionListeners.iterator(); 267 final Iterator<WeakReference<SubscriptionListener>> iterator = this.pa rent.subscriptionListeners.iterator();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 { 328 {
333 return this.specialization + " (" + this.title + ") @ " + this.url; 329 return this.specialization + " (" + this.title + ") @ " + this.url;
334 } 330 }
335 } 331 }
336 332
337 public interface SubscriptionListener 333 public interface SubscriptionListener
338 { 334 {
339 void onSubscriptionUpdated(); 335 void onSubscriptionUpdated();
340 } 336 }
341 } 337 }
OLDNEW

Powered by Google App Engine
This is Rietveld