| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 29 matching lines...) Expand all Loading... | |
| 40 final class SubscriptionContainer | 40 final class SubscriptionContainer |
| 41 { | 41 { |
| 42 private static final String TAG = SubscriptionContainer.class.getName(); | 42 private static final String TAG = SubscriptionContainer.class.getName(); |
| 43 private final ConcurrentHashMap<String, Boolean> enableState = new ConcurrentH ashMap<>(); | 43 private final ConcurrentHashMap<String, Boolean> enableState = new ConcurrentH ashMap<>(); |
| 44 private final Semaphore entriesReady = new Semaphore(0); | 44 private final Semaphore entriesReady = new Semaphore(0); |
| 45 private final List<SubscriptionContainer.Subscription> entries = new ArrayList <>(); | 45 private final List<SubscriptionContainer.Subscription> entries = new ArrayList <>(); |
| 46 private final HashMap<String, SubscriptionContainer.Subscription> urlMap = new HashMap<>(); | 46 private final HashMap<String, SubscriptionContainer.Subscription> urlMap = new HashMap<>(); |
| 47 private final List<WeakReference<SubscriptionListener>> subscriptionListeners = new ArrayList<>(); | 47 private final List<WeakReference<SubscriptionListener>> subscriptionListeners = new ArrayList<>(); |
| 48 | 48 |
| 49 // prevent external instantiation | 49 // prevent external instantiation |
| 50 private SubscriptionContainer(final Context context) | 50 private SubscriptionContainer(final Context context) |
|
jens
2019/01/10 14:10:59
To be consistent, Context should be final in all c
diegocarloslima
2019/01/16 13:44:21
Acknowledged.
| |
| 51 { | 51 { |
| 52 loadSubscriptions(context); | 52 loadSubscriptions(context); |
| 53 } | 53 } |
| 54 | 54 |
| 55 public final static SubscriptionContainer create(Context context) | 55 public final static SubscriptionContainer create(final Context context) |
| 56 { | 56 { |
| 57 return create(context, true); | 57 return create(context, true); |
| 58 } | 58 } |
| 59 | 59 |
| 60 public final static SubscriptionContainer create(Context context, final boolea n refresh) | 60 public final static SubscriptionContainer create(final Context context, final boolean refresh) |
| 61 { | 61 { |
| 62 final SubscriptionContainer sc = new SubscriptionContainer(context); | 62 final SubscriptionContainer sc = new SubscriptionContainer(context); |
| 63 | 63 |
| 64 for (final SubscriptionContainer.Subscription e : sc.entries) | 64 for (final SubscriptionContainer.Subscription e : sc.entries) |
| 65 { | 65 { |
| 66 sc.urlMap.put(e.url, e); | 66 sc.urlMap.put(e.url, e); |
| 67 sc.enableState.put(e.url, Boolean.FALSE); | 67 sc.enableState.put(e.url, Boolean.FALSE); |
| 68 } | 68 } |
| 69 | 69 |
| 70 if (refresh) | 70 if (refresh) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 iterator.remove(); | 146 iterator.remove(); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 if (shouldAddListener) | 150 if (shouldAddListener) |
| 151 { | 151 { |
| 152 this.subscriptionListeners.add(new WeakReference<>(listener)); | 152 this.subscriptionListeners.add(new WeakReference<>(listener)); |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 private void loadSubscriptions(Context context) | 156 private void loadSubscriptions(final Context context) |
| 157 { | 157 { |
| 158 | 158 |
| 159 final XmlPullParser parser = Xml.newPullParser(); | 159 final XmlPullParser parser = Xml.newPullParser(); |
| 160 try | 160 try |
| 161 { | 161 { |
| 162 final BufferedReader reader = new BufferedReader(new InputStreamReader( | 162 final BufferedReader reader = new BufferedReader(new InputStreamReader( |
| 163 context.getAssets().open("extensions/subscriptions.xml"))); | 163 context.getAssets().open("extensions/subscriptions.xml"))); |
| 164 | 164 |
| 165 parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); | 165 parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); |
| 166 parser.setInput(reader); | 166 parser.setInput(reader); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 { | 324 { |
| 325 return this.specialization + " (" + this.title + ") @ " + this.url; | 325 return this.specialization + " (" + this.title + ") @ " + this.url; |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 | 328 |
| 329 public interface SubscriptionListener | 329 public interface SubscriptionListener |
| 330 { | 330 { |
| 331 void onSubscriptionUpdated(); | 331 void onSubscriptionUpdated(); |
| 332 } | 332 } |
| 333 } | 333 } |
| LEFT | RIGHT |