summaryrefslogtreecommitdiff
path: root/core/src/main/java/de/danoeh
diff options
context:
space:
mode:
authorMartin Fietz <Martin.Fietz@gmail.com>2016-01-30 12:39:51 +0100
committerMartin Fietz <Martin.Fietz@gmail.com>2016-01-30 18:30:48 +0100
commit4bdf95bd455a0b32e370a063d69ad5613ba78ac0 (patch)
tree468484cde6d0a2bf9ea0346e523dfdf77362826b /core/src/main/java/de/danoeh
parente00f08963b61589418eb823f579fd49567fdae34 (diff)
downloadAntennaPod-4bdf95bd455a0b32e370a063d69ad5613ba78ac0.zip
Change feed lastModified/lastUpdate to String
Diffstat (limited to 'core/src/main/java/de/danoeh')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java3
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java37
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java29
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java6
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java10
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java2
8 files changed, 43 insertions, 48 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java b/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java
index 5ea0ba904..690fbdfc6 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java
@@ -156,10 +156,9 @@ public class OpmlBackupAgent extends BackupAgentHelper {
ArrayList<OpmlElement> opmlElements = new OpmlReader().readDocument(reader);
mChecksum = digester == null ? null : digester.digest();
DownloadRequester downloader = DownloadRequester.getInstance();
- Date lastUpdated = new Date();
for (OpmlElement opmlElem : opmlElements) {
- Feed feed = new Feed(opmlElem.getXmlUrl(), lastUpdated, opmlElem.getText());
+ Feed feed = new Feed(opmlElem.getXmlUrl(), null, opmlElem.getText());
try {
downloader.downloadFeed(mContext, feed);
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java
index 4be788f33..d2d7cbc73 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java
@@ -44,10 +44,12 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
private String author;
private FeedImage image;
private List<FeedItem> items;
+
/**
- * Date of last refresh.
+ * String that identifies the last update (adopted from Last-Modified or ETag header)
*/
- private Date lastUpdate;
+ private String lastUpdate;
+
private FlattrStatus flattrStatus;
private String paymentLink;
/**
@@ -91,18 +93,14 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
/**
* This constructor is used for restoring a feed from the database.
*/
- public Feed(long id, Date lastUpdate, String title, String link, String description, String paymentLink,
+ public Feed(long id, String lastUpdate, String title, String link, String description, String paymentLink,
String author, String language, String type, String feedIdentifier, FeedImage image, String fileUrl,
String downloadUrl, boolean downloaded, FlattrStatus status, boolean paged, String nextPageLink,
String filter, boolean lastUpdateFailed) {
super(fileUrl, downloadUrl, downloaded);
this.id = id;
this.title = title;
- if (lastUpdate != null) {
- this.lastUpdate = (Date) lastUpdate.clone();
- } else {
- this.lastUpdate = null;
- }
+ this.lastUpdate = lastUpdate;
this.link = link;
this.description = description;
this.paymentLink = paymentLink;
@@ -126,7 +124,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
/**
* This constructor is used for test purposes and uses a default flattr status object.
*/
- public Feed(long id, Date lastUpdate, String title, String link, String description, String paymentLink,
+ public Feed(long id, String lastUpdate, String title, String link, String description, String paymentLink,
String author, String language, String type, String feedIdentifier, FeedImage image, String fileUrl,
String downloadUrl, boolean downloaded) {
this(id, lastUpdate, title, link, description, paymentLink, author, language, type, feedIdentifier, image,
@@ -138,7 +136,6 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
*/
public Feed() {
super();
- lastUpdate = new Date();
this.flattrStatus = new FlattrStatus();
}
@@ -146,9 +143,9 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
* This constructor is used for requesting a feed download (it must not be used for anything else!). It should NOT be
* used if the title of the feed is already known.
*/
- public Feed(String url, Date lastUpdate) {
+ public Feed(String url, String lastUpdate) {
super(null, url, false);
- this.lastUpdate = (lastUpdate != null) ? (Date) lastUpdate.clone() : null;
+ this.lastUpdate = lastUpdate;
this.flattrStatus = new FlattrStatus();
}
@@ -156,7 +153,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
* This constructor is used for requesting a feed download (it must not be used for anything else!). It should be
* used if the title of the feed is already known.
*/
- public Feed(String url, Date lastUpdate, String title) {
+ public Feed(String url, String lastUpdate, String title) {
this(url, lastUpdate);
this.title = title;
this.flattrStatus = new FlattrStatus();
@@ -166,7 +163,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
* This constructor is used for requesting a feed download (it must not be used for anything else!). It should be
* used if the title of the feed is already known.
*/
- public Feed(String url, Date lastUpdate, String title, String username, String password) {
+ public Feed(String url, String lastUpdate, String title, String username, String password) {
this(url, lastUpdate, title);
preferences = new FeedPreferences(0, true, FeedPreferences.AutoDeleteAction.GLOBAL, username, password);
}
@@ -191,11 +188,9 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
int indexHide = cursor.getColumnIndex(PodDBAdapter.KEY_HIDE);
int indexLastUpdateFailed = cursor.getColumnIndex(PodDBAdapter.KEY_LAST_UPDATE_FAILED);
- Date lastUpdate = new Date(cursor.getLong(indexLastUpdate));
-
Feed feed = new Feed(
cursor.getLong(indexId),
- lastUpdate,
+ cursor.getString(indexLastUpdate),
cursor.getString(indexTitle),
cursor.getString(indexLink),
cursor.getString(indexDescription),
@@ -430,12 +425,12 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
this.items = list;
}
- public Date getLastUpdate() {
- return (lastUpdate != null) ? (Date) lastUpdate.clone() : null;
+ public String getLastUpdate() {
+ return lastUpdate;
}
- public void setLastUpdate(Date lastUpdate) {
- this.lastUpdate = (lastUpdate != null) ? (Date) lastUpdate.clone() : null;
+ public void setLastUpdate(String lastModified) {
+ this.lastUpdate = lastModified;
}
public String getFeedIdentifier() {
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java b/core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java
index 0b90cef6c..e7ebff154 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java
@@ -175,7 +175,7 @@ public class GpodnetSyncService extends Service {
for (String downloadUrl : changes.getAdded()) {
if (false == localSubscriptions.contains(downloadUrl) &&
false == localRemoved.contains(downloadUrl)) {
- Feed feed = new Feed(downloadUrl, new Date(0));
+ Feed feed = new Feed(downloadUrl, null);
DownloadRequester.getInstance().downloadFeed(this, feed);
}
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java
index bc3006eea..7f40ea6e2 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java
@@ -4,6 +4,7 @@ import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import de.danoeh.antennapod.core.feed.FeedFile;
import de.danoeh.antennapod.core.util.URLChecker;
@@ -15,7 +16,7 @@ public class DownloadRequest implements Parcelable {
private final String title;
private String username;
private String password;
- private long ifModifiedSince;
+ private String lastModified;
private boolean deleteOnFailure;
private final long feedfileId;
private final int feedfileType;
@@ -60,7 +61,7 @@ public class DownloadRequest implements Parcelable {
this.feedfileType = builder.feedfileType;
this.username = builder.username;
this.password = builder.password;
- this.ifModifiedSince = builder.ifModifiedSince;
+ this.lastModified = builder.lastModified;
this.deleteOnFailure = builder.deleteOnFailure;
this.arguments = (builder.arguments != null) ? builder.arguments : new Bundle();
}
@@ -71,7 +72,7 @@ public class DownloadRequest implements Parcelable {
title = in.readString();
feedfileId = in.readLong();
feedfileType = in.readInt();
- ifModifiedSince = in.readLong();
+ lastModified = in.readString();
deleteOnFailure = (in.readByte() > 0);
arguments = in.readBundle();
if (in.dataAvail() > 0) {
@@ -98,7 +99,7 @@ public class DownloadRequest implements Parcelable {
dest.writeString(title);
dest.writeLong(feedfileId);
dest.writeInt(feedfileType);
- dest.writeLong(ifModifiedSince);
+ dest.writeString(lastModified);
dest.writeByte((deleteOnFailure) ? (byte) 1 : 0);
dest.writeBundle(arguments);
if (username != null) {
@@ -127,7 +128,7 @@ public class DownloadRequest implements Parcelable {
DownloadRequest that = (DownloadRequest) o;
- if (ifModifiedSince != that.ifModifiedSince) return false;
+ if (lastModified != that.lastModified) return false;
if (deleteOnFailure != that.deleteOnFailure) return false;
if (feedfileId != that.feedfileId) return false;
if (feedfileType != that.feedfileType) return false;
@@ -143,7 +144,6 @@ public class DownloadRequest implements Parcelable {
if (title != null ? !title.equals(that.title) : that.title != null) return false;
if (username != null ? !username.equals(that.username) : that.username != null)
return false;
-
return true;
}
@@ -154,7 +154,7 @@ public class DownloadRequest implements Parcelable {
result = 31 * result + (title != null ? title.hashCode() : 0);
result = 31 * result + (username != null ? username.hashCode() : 0);
result = 31 * result + (password != null ? password.hashCode() : 0);
- result = 31 * result + (int)ifModifiedSince;
+ result = 31 * result + (lastModified != null ? lastModified.hashCode() : 0);
result = 31 * result + (deleteOnFailure ? 1 : 0);
result = 31 * result + (int) (feedfileId ^ (feedfileId >>> 32));
result = 31 * result + feedfileType;
@@ -234,13 +234,14 @@ public class DownloadRequest implements Parcelable {
this.password = password;
}
- public DownloadRequest setIfModifiedSince(long time) {
- this.ifModifiedSince = time;
+ public DownloadRequest setLastModified(@Nullable String lastModified) {
+ this.lastModified = lastModified;
return this;
}
- public long getIfModifiedSince() {
- return this.ifModifiedSince;
+ @Nullable
+ public String getLastModified() {
+ return lastModified;
}
public boolean isDeleteOnFailure() {
@@ -257,7 +258,7 @@ public class DownloadRequest implements Parcelable {
private String title;
private String username;
private String password;
- private long ifModifiedSince;
+ private String lastModified;
private boolean deleteOnFailure = false;
private long feedfileId;
private int feedfileType;
@@ -276,8 +277,8 @@ public class DownloadRequest implements Parcelable {
return this;
}
- public Builder ifModifiedSince(long time) {
- this.ifModifiedSince = time;
+ public Builder lastModified(String lastModified) {
+ this.lastModified = lastModified;
return this;
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java
index d69228ceb..72fa1e1f8 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java
@@ -824,7 +824,7 @@ public class DownloadService extends Service {
}
private Pair<DownloadRequest, FeedHandlerResult> parseFeed(DownloadRequest request) {
- Feed feed = new Feed(request.getSource(), new Date());
+ Feed feed = new Feed(request.getSource(), request.getLastModified());
feed.setFile_url(request.getDestination());
feed.setId(request.getFeedfileId());
feed.setDownloaded(true);
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java
index efc60bfc2..62814524e 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java
@@ -248,11 +248,11 @@ public final class DBTasks {
public static void loadNextPageOfFeed(final Context context, Feed feed, boolean loadAllPages) throws DownloadRequestException {
if (feed.isPaged() && feed.getNextPageLink() != null) {
int pageNr = feed.getPageNr() + 1;
- Feed nextFeed = new Feed(feed.getNextPageLink(), new Date(), feed.getTitle() + "(" + pageNr + ")");
+ Feed nextFeed = new Feed(feed.getNextPageLink(), null, feed.getTitle() + "(" + pageNr + ")");
nextFeed.setPageNr(pageNr);
nextFeed.setPaged(true);
nextFeed.setId(feed.getId());
- DownloadRequester.getInstance().downloadFeed(context, nextFeed, loadAllPages);
+ DownloadRequester.getInstance().downloadFeed(context, nextFeed, loadAllPages, false);
} else {
Log.e(TAG, "loadNextPageOfFeed: Feed was either not paged or contained no nextPageLink");
}
@@ -273,7 +273,7 @@ public final class DBTasks {
private static void refreshFeed(Context context, Feed feed, boolean loadAllPages) throws DownloadRequestException {
Feed f;
- Date lastUpdate = feed.hasLastUpdateFailed() ? new Date(0) : feed.getLastUpdate();
+ String lastUpdate = feed.hasLastUpdateFailed() ? null : feed.getLastUpdate();
if (feed.getPreferences() == null) {
f = new Feed(feed.getDownload_url(), lastUpdate, feed.getTitle());
} else {
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java
index 0dc1dadeb..b934e2c95 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java
@@ -88,7 +88,7 @@ public class DownloadRequester {
private void download(Context context, FeedFile item, FeedFile container, File dest,
boolean overwriteIfExists, String username, String password,
- long ifModifiedSince, boolean deleteOnFailure, Bundle arguments) {
+ String lastModified, boolean deleteOnFailure, Bundle arguments) {
final boolean partiallyDownloadedFileExists = item.getFile_url() != null;
if (isDownloadingFile(item)) {
Log.e(TAG, "URL " + item.getDownload_url()
@@ -129,7 +129,7 @@ public class DownloadRequester {
DownloadRequest.Builder builder = new DownloadRequest.Builder(dest.toString(), item)
.withAuthentication(username, password)
- .ifModifiedSince(ifModifiedSince)
+ .lastModified(lastModified)
.deleteOnFailure(deleteOnFailure)
.withArguments(arguments);
DownloadRequest request = builder.build();
@@ -167,14 +167,14 @@ public class DownloadRequester {
if (feedFileValid(feed)) {
String username = (feed.getPreferences() != null) ? feed.getPreferences().getUsername() : null;
String password = (feed.getPreferences() != null) ? feed.getPreferences().getPassword() : null;
- long ifModifiedSince = feed.isPaged() ? 0 : feed.getLastUpdate().getTime();
+ String lastModified = feed.isPaged() || force ? null : feed.getLastUpdate();
Bundle args = new Bundle();
args.putInt(REQUEST_ARG_PAGE_NR, feed.getPageNr());
args.putBoolean(REQUEST_ARG_LOAD_ALL_PAGES, loadAllPages);
download(context, feed, null, new File(getFeedfilePath(context),
- getFeedfileName(feed)), true, username, password, ifModifiedSince, true, args);
+ getFeedfileName(feed)), true, username, password, lastModified, true, args);
}
}
@@ -204,7 +204,7 @@ public class DownloadRequester {
getMediafilename(feedmedia));
}
download(context, feedmedia, feed,
- dest, false, username, password, 0, false, null);
+ dest, false, username, password, null, false, null);
}
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
index 85ff8fc8c..9901bead0 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
@@ -368,7 +368,7 @@ public class PodDBAdapter {
values.put(KEY_FILE_URL, feed.getFile_url());
values.put(KEY_DOWNLOAD_URL, feed.getDownload_url());
values.put(KEY_DOWNLOADED, feed.isDownloaded());
- values.put(KEY_LASTUPDATE, feed.getLastUpdate().getTime());
+ values.put(KEY_LASTUPDATE, feed.getLastUpdate());
values.put(KEY_TYPE, feed.getType());
values.put(KEY_FEED_IDENTIFIER, feed.getFeedIdentifier());