Refresh at least every 3 days

This commit is contained in:
Martin Fietz 2015-03-27 19:39:19 +01:00
parent ae138e2b1c
commit 95b0393a62
3 changed files with 20 additions and 12 deletions

View File

@ -22,7 +22,6 @@ import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
import de.danoeh.antennapod.core.BuildConfig;
@ -68,10 +67,13 @@ public class HttpDownloader extends Downloader {
Request.Builder httpReq = new Request.Builder().url(uri.toURL())
.header("User-Agent", ClientConfig.USER_AGENT);
if(request.getIfModifiedSince() > 0) {
Date date = new Date(request.getIfModifiedSince());
Log.d(TAG, "Header If-Modified-Since: "
+ new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z").format(date));
httpReq.addHeader("If-Modified-Since", HttpDate.format(date));
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);
}
}
// add authentication information
@ -106,7 +108,7 @@ public class HttpDownloader extends Downloader {
Log.d(TAG, "Response code is " + response.code());
if(!response.isSuccessful() && response.code() == HttpURLConnection.HTTP_NOT_MODIFIED) {
Log.d(TAG, "Feed not modified since last update, Download canceled");
Log.d(TAG, "Feed '" + request.getSource() + "' not modified since last update, Download canceled");
onCancelled();
return;
}

View File

@ -298,7 +298,8 @@ public final class DBTasks {
}
/**
* Updates a specific Feed.
* Refresh a specific Feed. The refresh may get canceled if the feed does not seem to be modified
* and the last update was only few days ago.
*
* @param context Used for requesting the download.
* @param feed The Feed object.
@ -311,9 +312,9 @@ public final class DBTasks {
private static void refreshFeed(Context context, Feed feed, boolean loadAllPages) throws DownloadRequestException {
Feed f;
if (feed.getPreferences() == null) {
f = new Feed(feed.getDownload_url(), new Date(), feed.getTitle());
f = new Feed(feed.getDownload_url(), feed.getLastUpdate(), feed.getTitle());
} else {
f = new Feed(feed.getDownload_url(), new Date(), feed.getTitle(),
f = new Feed(feed.getDownload_url(), feed.getLastUpdate(), feed.getTitle(),
feed.getPreferences().getUsername(), feed.getPreferences().getPassword());
}
f.setId(feed.getId());

View File

@ -11,7 +11,6 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import java.io.File;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -160,13 +159,19 @@ public class DownloadRequester {
return true;
}
/**
* Downloads a feed
*
* @param context The application's environment.
* @param feed Feed to download
* @param loadAllPages Set to true to download all pages
*/
public synchronized void downloadFeed(Context context, Feed feed, boolean loadAllPages)
throws DownloadRequestException {
if (feedFileValid(feed)) {
String username = (feed.getPreferences() != null) ? feed.getPreferences().getUsername() : null;
String password = (feed.getPreferences() != null) ? feed.getPreferences().getPassword() : null;
Date lastUpdate = feed.getLastUpdate();
long ifModifiedSince = lastUpdate.getTime() - 30; // account for some processing time
long ifModifiedSince = feed.getLastUpdate().getTime();
Bundle args = new Bundle();
args.putInt(REQUEST_ARG_PAGE_NR, feed.getPageNr());