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

Side by Side Diff: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/SubscriptionInfo.java

Issue 29603697: Issue 5931 - Create tests for util package (Closed)
Patch Set: Created Nov. 10, 2017, 2:23 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
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 package org.adblockplus.sbrowser.contentblocker.engine;
19
20 import android.support.annotation.NonNull;
21
22 /**
23 * Class for querying subscription information from the engine.
24 */
25 public class SubscriptionInfo implements Comparable<SubscriptionInfo>
26 {
27 public enum Type
28 {
29 ADS,
30 OTHER,
31 CUSTOM,
32 INITIALIZING,
33 USER_FILTERS,
34 USER_EXCEPTIONS,
35 ACCEPTABLE_ADS
36 }
37
38 private final Type type;
39 private final String id;
40 private final String url;
41 private String title;
42 private boolean enabled = false;
43 private long lastUpdate;
44
45 private SubscriptionInfo(final Type type, final String id, final String url, f inal String title, final boolean enabled, final long lastUpdate)
46 {
47 this.type = type;
48 this.id = id;
49 this.url = url;
50 this.title = title;
51 this.enabled = enabled;
52 this.lastUpdate = lastUpdate;
53 }
54
55 public Type getType()
56 {
57 return this.type;
58 }
59
60 public String getId()
61 {
62 return this.id;
63 }
64
65 public boolean isEnabled()
66 {
67 return this.enabled;
68 }
69
70 public String getTitle()
71 {
72 return this.title;
73 }
74
75 public String getUrl()
76 {
77 return this.url;
78 }
79
80 public long getLastUpdateTime()
81 {
82 return this.lastUpdate;
83 }
84
85 void updateWith(final Subscription subscription)
86 {
87 if (this.id.equals(subscription.getId()))
88 {
89 this.enabled = subscription.isEnabled();
90 this.title = subscription.getTitle();
91 this.lastUpdate = subscription.getLastUpdateTimestamp();
92 }
93 }
94
95 static SubscriptionInfo create(final Engine engine, final Subscription subscri ption)
96 {
97 final DefaultSubscriptionInfo defaultSubscription = engine
98 .getDefaultSubscriptionInfo(subscription);
99 final String title = subscription.getTitle();
100 final String acceptableAdsLink = engine.getPrefsDefault("subscriptions_excep tionsurl");
101 final String url = subscription.getURL() != null ? subscription.getURL().toS tring() : null;
102
103 Type type = null;
104 switch (subscription.getType())
105 {
106 case DOWNLOADABLE:
107 if (defaultSubscription != null)
108 {
109 if (acceptableAdsLink.equals(url))
110 {
111 type = Type.ACCEPTABLE_ADS;
112 }
113 else if ("ads".equalsIgnoreCase(defaultSubscription.getType()))
114 {
115 type = Type.ADS;
116 }
117 else if ("other".equalsIgnoreCase(defaultSubscription.getType()))
118 {
119 type = Type.OTHER;
120 }
121 }
122 break;
123 case USER:
124 if (Engine.USER_EXCEPTIONS_TITLE.equals(title))
125 {
126 type = Type.USER_EXCEPTIONS;
127 }
128 else if (Engine.USER_FILTERS_TITLE.equals(title))
129 {
130 type = Type.USER_FILTERS;
131 }
132 else
133 {
134 throw new IllegalStateException("Unknown user subscription with title '" + title + "'");
135 }
136 break;
137 }
138
139 if (type == null)
140 {
141 type = acceptableAdsLink.equals(url) ? Type.ACCEPTABLE_ADS : Type.CUSTOM;
142 }
143
144 return new SubscriptionInfo(type,
145 subscription.getId(),
146 url,
147 title,
148 subscription.isEnabled(),
149 subscription.getLastUpdateTimestamp());
150 }
151
152 @Override
153 public int compareTo(@NonNull final SubscriptionInfo another)
154 {
155 return this.getTitle().compareTo(another.getTitle());
156 }
157 }
OLDNEW

Powered by Google App Engine
This is Rietveld