Disable feed media file size service

This commit is contained in:
Martin Fietz 2015-08-16 00:04:03 +02:00
parent 3148b8835b
commit 04bfcacb12
3 changed files with 46 additions and 60 deletions

View File

@ -1,13 +1,11 @@
package de.danoeh.antennapod;
import android.app.Application;
import android.content.Intent;
import android.content.res.Configuration;
import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.FeedMediaSizeService;
import de.danoeh.antennapod.core.util.NetworkUtils;
import de.danoeh.antennapod.spa.SPAUtil;
@ -47,7 +45,7 @@ public class PodcastApp extends Application {
SPAUtil.sendSPAppsQueryFeedsIntent(this);
startService(new Intent(this, FeedMediaSizeService.class));
// startService(new Intent(this, FeedMediaSizeService.class));
}
public static float getLogicalDensity() {

View File

@ -4,19 +4,6 @@ import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import de.danoeh.antennapod.core.event.FeedMediaEvent;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.NetworkUtils;
import de.greenrobot.event.EventBus;
public class FeedMediaSizeService extends IntentService {
private final static String TAG = "FeedMediaSizeService";
@ -28,49 +15,50 @@ public class FeedMediaSizeService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
Log.d(TAG, "onHandleIntent()");
if(false == NetworkUtils.isDownloadAllowed()) {
return;
}
List<FeedMedia> list = DBReader.getFeedMediaUnknownSize(this);
for (FeedMedia media : list) {
Log.d(TAG, "Getting size currently " + media.getSize() + " for " + media.getDownload_url());
if(false == NetworkUtils.isDownloadAllowed()) {
return;
}
long size = Integer.MIN_VALUE;
if (media.isDownloaded()) {
File mediaFile = new File(media.getLocalMediaUrl());
if(mediaFile.exists()) {
size = mediaFile.length();
}
} else if (false == media.checkedOnSizeButUnknown()) {
// only query the network if we haven't already checked
HttpURLConnection conn = null;
try {
URL url = new URL(media.getDownload_url());
conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Accept-Encoding", "");
conn.setRequestMethod("HEAD");
size = conn.getContentLength();
} catch (IOException e) {
Log.d(TAG, media.getDownload_url());
e.printStackTrace();
} finally {
if (conn != null) {
conn.disconnect();
}
}
}
if (size <= 0) {
// they didn't tell us the size, but we don't want to keep querying on it
media.setCheckedOnSizeButUnknown();
} else {
media.setSize(size);
}
Log.d(TAG, "Size now: " + media.getSize());
DBWriter.setFeedMedia(this, media);
EventBus.getDefault().post(FeedMediaEvent.update(media));
}
return;
// if(false == NetworkUtils.isDownloadAllowed()) {
// return;
// }
// List<FeedMedia> list = DBReader.getFeedMediaUnknownSize(this);
// for (FeedMedia media : list) {
// Log.d(TAG, "Getting size currently " + media.getSize() + " for " + media.getDownload_url());
// if(false == NetworkUtils.isDownloadAllowed()) {
// return;
// }
// long size = Integer.MIN_VALUE;
// if (media.isDownloaded()) {
// File mediaFile = new File(media.getLocalMediaUrl());
// if(mediaFile.exists()) {
// size = mediaFile.length();
// }
// } else if (false == media.checkedOnSizeButUnknown()) {
// // only query the network if we haven't already checked
// HttpURLConnection conn = null;
// try {
// URL url = new URL(media.getDownload_url());
// conn = (HttpURLConnection) url.openConnection();
// conn.setRequestProperty("Accept-Encoding", "");
// conn.setRequestMethod("HEAD");
// size = conn.getContentLength();
// } catch (IOException e) {
// Log.d(TAG, media.getDownload_url());
// e.printStackTrace();
// } finally {
// if (conn != null) {
// conn.disconnect();
// }
// }
// }
// if (size <= 0) {
// // they didn't tell us the size, but we don't want to keep querying on it
// media.setCheckedOnSizeButUnknown();
// } else {
// media.setSize(size);
// }
// Log.d(TAG, "Size now: " + media.getSize());
// DBWriter.setFeedMedia(this, media);
// EventBus.getDefault().post(FeedMediaEvent.update(media));
// }
}
}

View File

@ -578,7 +578,7 @@ public final class DBTasks {
EventDistributor.getInstance().sendFeedUpdateBroadcast();
context.startService(new Intent(context, FeedMediaSizeService.class));
// context.startService(new Intent(context, FeedMediaSizeService.class));
return resultFeeds;
}