From 4bdf95bd455a0b32e370a063d69ad5613ba78ac0 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Sat, 30 Jan 2016 12:39:51 +0100 Subject: Change feed lastModified/lastUpdate to String --- .../antennapod/core/backup/OpmlBackupAgent.java | 3 +- .../java/de/danoeh/antennapod/core/feed/Feed.java | 37 ++++++++++------------ .../core/service/GpodnetSyncService.java | 2 +- .../core/service/download/DownloadRequest.java | 29 +++++++++-------- .../core/service/download/DownloadService.java | 2 +- .../de/danoeh/antennapod/core/storage/DBTasks.java | 6 ++-- .../antennapod/core/storage/DownloadRequester.java | 10 +++--- .../antennapod/core/storage/PodDBAdapter.java | 2 +- 8 files changed, 43 insertions(+), 48 deletions(-) (limited to 'core/src') 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 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 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 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()); -- cgit v1.2.3 From 8c3a9986f0ddc69c2d964fc6820b6971c09e1f29 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Sat, 30 Jan 2016 12:42:18 +0100 Subject: Feed view: Single feed refresh enforces actually refreshing --- .../de/danoeh/antennapod/core/storage/DBTasks.java | 42 +++++++++++++++++++--- .../antennapod/core/storage/DownloadRequester.java | 5 +-- 2 files changed, 41 insertions(+), 6 deletions(-) (limited to 'core/src') 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 62814524e..ed593bb82 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 @@ -224,7 +224,28 @@ public final class DBTasks { */ public static void refreshCompleteFeed(final Context context, final Feed feed) { try { - refreshFeed(context, feed, true); + refreshFeed(context, feed, true, false); + } catch (DownloadRequestException e) { + e.printStackTrace(); + DBWriter.addDownloadStatus( + new DownloadStatus(feed, feed + .getHumanReadableIdentifier(), + DownloadError.ERROR_REQUEST_ERROR, false, e + .getMessage() + ) + ); + } + } + + /** + * Downloads all pages of the given feed even if feed has not been modified since last refresh + * + * @param context Used for requesting the download. + * @param feed The Feed object. + */ + public static void forceRefreshCompleteFeed(final Context context, final Feed feed) { + try { + refreshFeed(context, feed, true, true); } catch (DownloadRequestException e) { e.printStackTrace(); DBWriter.addDownloadStatus( @@ -268,10 +289,23 @@ public final class DBTasks { public static void refreshFeed(Context context, Feed feed) throws DownloadRequestException { Log.d(TAG, "refreshFeed(feed.id: " + feed.getId() +")"); - refreshFeed(context, feed, false); + refreshFeed(context, feed, false, false); + } + + /** + * Refresh a specific feed even if feed has not been modified since last refresh + * + * @param context Used for requesting the download. + * @param feed The Feed object. + */ + public static void forceRefreshFeed(Context context, Feed feed) + throws DownloadRequestException { + Log.d(TAG, "refreshFeed(feed.id: " + feed.getId() +")"); + refreshFeed(context, feed, false, true); } - private static void refreshFeed(Context context, Feed feed, boolean loadAllPages) throws DownloadRequestException { + private static void refreshFeed(Context context, Feed feed, boolean loadAllPages, boolean force) + throws DownloadRequestException { Feed f; String lastUpdate = feed.hasLastUpdateFailed() ? null : feed.getLastUpdate(); if (feed.getPreferences() == null) { @@ -281,7 +315,7 @@ public final class DBTasks { feed.getPreferences().getUsername(), feed.getPreferences().getPassword()); } f.setId(feed.getId()); - DownloadRequester.getInstance().downloadFeed(context, f, loadAllPages); + DownloadRequester.getInstance().downloadFeed(context, f, loadAllPages, force); } /** 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 b934e2c95..22c9538ca 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 @@ -162,7 +162,8 @@ public class DownloadRequester { * @param feed Feed to download * @param loadAllPages Set to true to download all pages */ - public synchronized void downloadFeed(Context context, Feed feed, boolean loadAllPages) + public synchronized void downloadFeed(Context context, Feed feed, boolean loadAllPages, + boolean force) throws DownloadRequestException { if (feedFileValid(feed)) { String username = (feed.getPreferences() != null) ? feed.getPreferences().getUsername() : null; @@ -179,7 +180,7 @@ public class DownloadRequester { } public synchronized void downloadFeed(Context context, Feed feed) throws DownloadRequestException { - downloadFeed(context, feed, false); + downloadFeed(context, feed, false, false); } public synchronized void downloadMedia(Context context, FeedMedia feedmedia) -- cgit v1.2.3 From 20ccfbb809cef53628bb6d05925e8e2d54c4cc36 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Sat, 30 Jan 2016 12:42:58 +0100 Subject: Use headers for lastUpdate/lastModified --- .../de/danoeh/antennapod/core/service/download/HttpDownloader.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'core/src') diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java index 0b9fba6f7..d0bd019f6 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java @@ -235,6 +235,12 @@ public class HttpDownloader extends Downloader { onFail(DownloadError.ERROR_IO_ERROR, "Download completed, but nothing was read"); return; } + String lastModified = response.header("Last-Modified"); + if(lastModified != null) { + request.setLastModified(lastModified); + } else { + request.setLastModified(response.header("ETag")); + } onSuccess(); } -- cgit v1.2.3 From 8b486e22d2483c0b6957dcc7302aab53ac1a0541 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Sat, 30 Jan 2016 12:43:27 +0100 Subject: If lastModified is not a date, assume it is an ETAg --- .../core/service/download/HttpDownloader.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'core/src') diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java index d0bd019f6..0f083f659 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java @@ -8,7 +8,6 @@ import com.squareup.okhttp.Protocol; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; import com.squareup.okhttp.ResponseBody; -import com.squareup.okhttp.internal.http.HttpDate; import org.apache.commons.io.IOUtils; @@ -28,6 +27,7 @@ import java.util.Date; import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.feed.FeedImage; +import de.danoeh.antennapod.core.util.DateUtils; import de.danoeh.antennapod.core.util.DownloadError; import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.core.util.URIUtil; @@ -67,13 +67,19 @@ public class HttpDownloader extends Downloader { final URI uri = URIUtil.getURIFromRequestUrl(request.getSource()); Request.Builder httpReq = new Request.Builder().url(uri.toURL()) .header("User-Agent", ClientConfig.USER_AGENT); - if(request.getIfModifiedSince() > 0) { - long threeDaysAgo = System.currentTimeMillis() - 1000*60*60*24*3; - if(request.getIfModifiedSince() > threeDaysAgo) { - Date date = new Date(request.getIfModifiedSince()); - String httpDate = HttpDate.format(date); - Log.d(TAG, "addHeader(\"If-Modified-Since\", \"" + httpDate + "\")"); - httpReq.addHeader("If-Modified-Since", httpDate); + if(request.getLastModified() != null) { + String lastModified = request.getLastModified(); + Date lastModifiedDate = DateUtils.parse(lastModified); + if(lastModifiedDate != null) { + long threeDaysAgo = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 3; + if (lastModifiedDate.getTime() > threeDaysAgo) { + Log.d(TAG, "addHeader(\"If-Modified-Since\", \"" + lastModified + "\")"); + httpReq.addHeader("If-Modified-Since", lastModified); + } + } else { + String eTag = lastModified; + Log.d(TAG, "addHeader(\"If-None-Match\", \"" + eTag + "\")"); + httpReq.addHeader("If-None-Match", eTag); } } -- cgit v1.2.3 From 23b56542e0e151e3a624e8122c466f690823c7f1 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Sat, 30 Jan 2016 16:19:27 +0100 Subject: Migrate database --- .../danoeh/antennapod/core/service/download/HttpDownloader.java | 2 +- .../main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'core/src') diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java index 0f083f659..e3a195253 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java @@ -67,7 +67,7 @@ public class HttpDownloader extends Downloader { final URI uri = URIUtil.getURIFromRequestUrl(request.getSource()); Request.Builder httpReq = new Request.Builder().url(uri.toURL()) .header("User-Agent", ClientConfig.USER_AGENT); - if(request.getLastModified() != null) { + if(!TextUtils.isEmpty(request.getLastModified())) { String lastModified = request.getLastModified(); Date lastModifiedDate = DateUtils.parse(lastModified); if(lastModifiedDate != 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 9901bead0..0cceebd6f 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 @@ -1512,7 +1512,7 @@ public class PodDBAdapter { */ private static class PodDBHelper extends SQLiteOpenHelper { - private final static int VERSION = 1050003; + private final static int VERSION = 1050004; private Context context; @@ -1756,7 +1756,6 @@ public class PodDBAdapter { db.execSQL(PodDBAdapter.CREATE_INDEX_FEEDITEMS_PUBDATE); db.execSQL(PodDBAdapter.CREATE_INDEX_FEEDITEMS_READ); } - if (oldVersion < 1050003) { // Migrates feed list filter data @@ -1804,6 +1803,11 @@ public class PodDBAdapter { db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + " ADD COLUMN " + PodDBAdapter.KEY_KEEP_UPDATED + " INTEGER DEFAULT 1"); } + if (oldVersion < 1050004) { + // prevent old timestamps to be misinterpreted as ETags + db.execSQL("UPDATE " + PodDBAdapter.TABLE_NAME_FEEDS + +" SET " + PodDBAdapter.KEY_LASTUPDATE + "=NULL"); + } EventBus.getDefault().post(ProgressEvent.end()); } -- cgit v1.2.3 From b1212f8adb14c3afdbc8e6ec6a24f892805a740f Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Sat, 30 Jan 2016 17:51:25 +0100 Subject: Fix warning --- core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src') 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 0cceebd6f..5b7f5f720 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 @@ -1151,7 +1151,7 @@ public class PodDBAdapter { * The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection. */ public final Cursor getNewItemsCursor() { - String[] args = new String[] { + Object[] args = new String[] { SEL_FI_SMALL_STR, TABLE_NAME_FEED_ITEMS, TABLE_NAME_FEEDS, -- cgit v1.2.3