summaryrefslogtreecommitdiff
path: root/core/src/main/java
diff options
context:
space:
mode:
authorTom Hennen <tom.hennen@gmail.com>2015-07-19 22:28:20 -0400
committerTom Hennen <tom.hennen@gmail.com>2015-07-20 17:58:12 -0400
commit9fb4b790f37cc297a50130f5afda3e77a774ee4e (patch)
treeccc0a0a2dc619beb2da3830717147eca9304645d /core/src/main/java
parent71bd2a1d74a3ca4a16115674d3749af46688c973 (diff)
downloadAntennaPod-9fb4b790f37cc297a50130f5afda3e77a774ee4e.zip
* DB qeury only returns items with size <= 0
* We only check for size if download is allowed (maybe we don't need to do this) * If we check using the network and fail we don't check again * removed an unneeded conn.disconnect() (it's handled in the 'finally' block) fixes AntennaPod/AntennaPod#1026
Diffstat (limited to 'core/src/main/java')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java21
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/FeedMediaSizeService.java16
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java2
3 files changed, 33 insertions, 6 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java
index 33dd9d636..55ab46335 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java
@@ -28,6 +28,15 @@ public class FeedMedia extends FeedFile implements Playable {
public static final String PREF_MEDIA_ID = "FeedMedia.PrefMediaId";
public static final String PREF_FEED_ID = "FeedMedia.PrefFeedId";
+ /**
+ * Indicates we've checked on the size of the item via the network
+ * and got an invalid response. Using Integer.MIN_VALUE because
+ * 1) we'll still check on it in case it gets downloaded (it's <= 0)
+ * 2) By default all FeedMedia have a size of 0 if we don't know it,
+ * so this won't conflict with existing practice.
+ */
+ private static final int CHECKED_ON_SIZE = Integer.MIN_VALUE;
+
private int duration;
private int position; // Current position in file
private int played_duration; // How many ms of this file have been played (for autoflattring)
@@ -199,6 +208,18 @@ public class FeedMedia extends FeedFile implements Playable {
this.size = size;
}
+ /**
+ * Indicates we asked the service what the size was, but didn't
+ * get a valid answer and we shoudln't check using the network again.
+ */
+ public void setCheckedOnSize() {
+ this.size = CHECKED_ON_SIZE;
+ }
+
+ public boolean checkedOnSize() {
+ return (CHECKED_ON_SIZE == this.size);
+ }
+
public String getMime_type() {
return mime_type;
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/FeedMediaSizeService.java b/core/src/main/java/de/danoeh/antennapod/core/service/FeedMediaSizeService.java
index e64a38901..9a98093ba 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/FeedMediaSizeService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/FeedMediaSizeService.java
@@ -28,21 +28,23 @@ public class FeedMediaSizeService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
Log.d(TAG, "onHandleIntent()");
- if(false == NetworkUtils.networkAvailable(this)) {
+ if(false == NetworkUtils.isDownloadAllowed(this)) {
return;
}
List<FeedMedia> list = DBReader.getFeedMediaUnknownSize(this);
for (FeedMedia media : list) {
- if(false == NetworkUtils.networkAvailable(this)) {
+ Log.d(TAG, "Getting size currently " + media.getSize() + " for " + media.getDownload_url());
+ if(false == NetworkUtils.isDownloadAllowed(this)) {
return;
}
long size = Integer.MIN_VALUE;
- if(media.isDownloaded()) {
+ if (media.isDownloaded()) {
File mediaFile = new File(media.getLocalMediaUrl());
if(mediaFile.exists()) {
size = mediaFile.length();
}
- } else {
+ } else if (false == media.checkedOnSize()) {
+ // only query the network if we haven't already checked
HttpURLConnection conn = null;
try {
URL url = new URL(media.getDownload_url());
@@ -50,7 +52,6 @@ public class FeedMediaSizeService extends IntentService {
conn.setRequestProperty("Accept-Encoding", "");
conn.setRequestMethod("HEAD");
size = conn.getContentLength();
- conn.disconnect();
} catch (IOException e) {
Log.d(TAG, media.getDownload_url());
e.printStackTrace();
@@ -60,7 +61,12 @@ public class FeedMediaSizeService extends IntentService {
}
}
}
+ if (size <= 0) {
+ // they didn't tell us the size, but we don't want to keep querying on it
+ media.setCheckedOnSize();
+ }
media.setSize(size);
+ Log.d(TAG, "Size now: " + media.getSize());
DBWriter.setFeedMedia(this, media);
EventBus.getDefault().post(FeedMediaEvent.update(media));
}
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 15f35d644..0153cbc8c 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
@@ -1113,7 +1113,7 @@ public class PodDBAdapter {
public final Cursor getFeedMediaUnknownSizeCursor() {
final String query = "SELECT * "
+ " FROM " + TABLE_NAME_FEED_MEDIA
- + " WHERE " + KEY_SIZE + ">" + Integer.MIN_VALUE;
+ + " WHERE " + KEY_SIZE + "<= 0";
return db.rawQuery(query, null);
}