1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
package de.danoeh.antennapod.model.feed;
import androidx.annotation.NonNull;
import android.text.TextUtils;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
/**
* Contains preferences for a single feed.
*/
public class FeedPreferences implements Serializable {
public static final float SPEED_USE_GLOBAL = -1;
public static final String TAG_ROOT = "#root";
public static final String TAG_SEPARATOR = "\u001e";
public enum AutoDeleteAction {
GLOBAL(0),
ALWAYS(1),
NEVER(2);
public final int code;
AutoDeleteAction(int code) {
this.code = code;
}
public static AutoDeleteAction fromCode(int code) {
for (AutoDeleteAction action : values()) {
if (code == action.code) {
return action;
}
}
return NEVER;
}
}
public enum NewEpisodesAction {
GLOBAL(0),
ADD_TO_INBOX(1),
ADD_TO_QUEUE(3),
NOTHING(2);
public final int code;
NewEpisodesAction(int code) {
this.code = code;
}
public static NewEpisodesAction fromCode(int code) {
for (NewEpisodesAction action : values()) {
if (code == action.code) {
return action;
}
}
return ADD_TO_INBOX;
}
}
@NonNull
private FeedFilter filter;
private long feedID;
private boolean autoDownload;
private boolean keepUpdated;
private AutoDeleteAction autoDeleteAction;
private VolumeAdaptionSetting volumeAdaptionSetting;
private NewEpisodesAction newEpisodesAction;
private String username;
private String password;
private float feedPlaybackSpeed;
private int feedSkipIntro;
private int feedSkipEnding;
private boolean showEpisodeNotification;
private final Set<String> tags = new HashSet<>();
public FeedPreferences(long feedID, boolean autoDownload, AutoDeleteAction autoDeleteAction,
VolumeAdaptionSetting volumeAdaptionSetting, NewEpisodesAction newEpisodesAction,
String username, String password) {
this(feedID, autoDownload, true, autoDeleteAction, volumeAdaptionSetting, username, password,
new FeedFilter(), SPEED_USE_GLOBAL, 0, 0, false, newEpisodesAction, new HashSet<>());
}
public FeedPreferences(long feedID, boolean autoDownload, boolean keepUpdated,
AutoDeleteAction autoDeleteAction, VolumeAdaptionSetting volumeAdaptionSetting,
String username, String password, @NonNull FeedFilter filter,
float feedPlaybackSpeed, int feedSkipIntro, int feedSkipEnding,
boolean showEpisodeNotification, NewEpisodesAction newEpisodesAction,
Set<String> tags) {
this.feedID = feedID;
this.autoDownload = autoDownload;
this.keepUpdated = keepUpdated;
this.autoDeleteAction = autoDeleteAction;
this.volumeAdaptionSetting = volumeAdaptionSetting;
this.username = username;
this.password = password;
this.filter = filter;
this.feedPlaybackSpeed = feedPlaybackSpeed;
this.feedSkipIntro = feedSkipIntro;
this.feedSkipEnding = feedSkipEnding;
this.showEpisodeNotification = showEpisodeNotification;
this.newEpisodesAction = newEpisodesAction;
this.tags.addAll(tags);
}
/**
* @return the filter for this feed
*/
@NonNull public FeedFilter getFilter() {
return filter;
}
public void setFilter(@NonNull FeedFilter filter) {
this.filter = filter;
}
/**
* @return true if this feed should be refreshed when everything else is being refreshed
* if false the feed should only be refreshed if requested directly.
*/
public boolean getKeepUpdated() {
return keepUpdated;
}
public void setKeepUpdated(boolean keepUpdated) {
this.keepUpdated = keepUpdated;
}
/**
* Compare another FeedPreferences with this one. The feedID, autoDownload and AutoDeleteAction attribute are excluded from the
* comparison.
*
* @return True if the two objects are different.
*/
public boolean compareWithOther(FeedPreferences other) {
if (other == null) {
return true;
}
if (!TextUtils.equals(username, other.username)) {
return true;
}
if (!TextUtils.equals(password, other.password)) {
return true;
}
return false;
}
/**
* Update this FeedPreferences object from another one. The feedID, autoDownload and AutoDeleteAction attributes are excluded
* from the update.
*/
public void updateFromOther(FeedPreferences other) {
if (other == null)
return;
this.username = other.username;
this.password = other.password;
}
public long getFeedID() {
return feedID;
}
public void setFeedID(long feedID) {
this.feedID = feedID;
}
public boolean getAutoDownload() {
return autoDownload;
}
public void setAutoDownload(boolean autoDownload) {
this.autoDownload = autoDownload;
}
public AutoDeleteAction getAutoDeleteAction() {
return autoDeleteAction;
}
public VolumeAdaptionSetting getVolumeAdaptionSetting() {
return volumeAdaptionSetting;
}
public NewEpisodesAction getNewEpisodesAction() {
return newEpisodesAction;
}
public void setAutoDeleteAction(AutoDeleteAction autoDeleteAction) {
this.autoDeleteAction = autoDeleteAction;
}
public void setVolumeAdaptionSetting(VolumeAdaptionSetting volumeAdaptionSetting) {
this.volumeAdaptionSetting = volumeAdaptionSetting;
}
public void setNewEpisodesAction(NewEpisodesAction newEpisodesAction) {
this.newEpisodesAction = newEpisodesAction;
}
public AutoDeleteAction getCurrentAutoDelete() {
return autoDeleteAction;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public float getFeedPlaybackSpeed() {
return feedPlaybackSpeed;
}
public void setFeedPlaybackSpeed(float playbackSpeed) {
feedPlaybackSpeed = playbackSpeed;
}
public void setFeedSkipIntro(int skipIntro) {
feedSkipIntro = skipIntro;
}
public int getFeedSkipIntro() {
return feedSkipIntro;
}
public void setFeedSkipEnding(int skipEnding) {
feedSkipEnding = skipEnding;
}
public int getFeedSkipEnding() {
return feedSkipEnding;
}
public Set<String> getTags() {
return tags;
}
public String getTagsAsString() {
return TextUtils.join(TAG_SEPARATOR, tags);
}
/**
* getter for preference if notifications should be display for new episodes.
* @return true for displaying notifications
*/
public boolean getShowEpisodeNotification() {
return showEpisodeNotification;
}
public void setShowEpisodeNotification(boolean showEpisodeNotification) {
this.showEpisodeNotification = showEpisodeNotification;
}
}
|