summaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/AndroidManifest.xml3
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java19
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java6
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/FeedMediaSizeService.java64
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java5
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java124
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java30
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java25
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java8
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java17
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java68
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/playback/Timeline.java16
13 files changed, 204 insertions, 183 deletions
diff --git a/core/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml
index 17dcb4ad8..3ec519844 100644
--- a/core/src/main/AndroidManifest.xml
+++ b/core/src/main/AndroidManifest.xml
@@ -23,9 +23,6 @@
<service
android:name=".service.GpodnetSyncService"
android:enabled="true" />
- <service
- android:name=".service.FeedMediaSizeService"
- android:enabled="true" />
<receiver
android:name=".receiver.MediaButtonReceiver"
diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java b/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java
index c7ac146b5..cf3af7d4c 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java
@@ -43,7 +43,7 @@ public class ApOkHttpUrlLoader implements ModelLoader<GlideUrl, InputStream> {
if (internalClient == null) {
synchronized (Factory.class) {
if (internalClient == null) {
- internalClient = AntennapodHttpClient.getHttpClient();
+ internalClient = AntennapodHttpClient.newHttpClient();
internalClient.interceptors().add(new NetworkAllowanceInterceptor());
internalClient.interceptors().add(new BasicAuthenticationInterceptor());
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java
index 1a40120e2..d8e07085d 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java
@@ -1,8 +1,5 @@
package de.danoeh.antennapod.core.gpoddernet;
-import android.os.Build;
-import android.util.Log;
-
import com.squareup.okhttp.Credentials;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
@@ -25,23 +22,10 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import java.security.KeyStore;
-import java.security.Principal;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocketFactory;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-import javax.net.ssl.X509TrustManager;
-import javax.security.auth.x500.X500Principal;
import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetDevice;
@@ -562,7 +546,8 @@ public class GpodnetService {
e.printStackTrace();
throw new GpodnetServiceException(e);
}
- Request.Builder request = new Request.Builder().url(url).post(null);
+ RequestBody body = RequestBody.create(TEXT, "");
+ Request.Builder request = new Request.Builder().url(url).post(body);
executeRequestWithAuthentication(request, username, password);
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
index d56829c70..08328536d 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
@@ -44,7 +44,7 @@ public class UserPreferences {
public static final String PREF_THEME = "prefTheme";
public static final String PREF_HIDDEN_DRAWER_ITEMS = "prefHiddenDrawerItems";
public static final String PREF_DRAWER_FEED_ORDER = "prefDrawerFeedOrder";
- public static final String PREF_DRAWER_FEED_COUNTER = "prefDrawerFeedCounter";
+ public static final String PREF_DRAWER_FEED_COUNTER = "prefDrawerFeedIndicator";
public static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify";
public static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify";
public static final String PREF_SHOW_DOWNLOAD_REPORT = "prefShowDownloadReport";
@@ -90,7 +90,7 @@ public class UserPreferences {
// Constants
private static int EPISODE_CACHE_SIZE_UNLIMITED = -1;
- public static int FEED_ORDER_UNPLAYED_EPISODES = 0;
+ public static int FEED_ORDER_COUNTER = 0;
public static int FEED_ORDER_ALPHABETICAL = 1;
public static int FEED_COUNTER_SHOW_NEW_UNPLAYED_SUM = 0;
public static int FEED_COUNTER_SHOW_NEW = 1;
@@ -144,7 +144,7 @@ public class UserPreferences {
return Integer.valueOf(value);
}
- public static int getFeedCounter() {
+ public static int getFeedCounterSetting() {
String value = prefs.getString(PREF_DRAWER_FEED_COUNTER, "0");
return Integer.valueOf(value);
}
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
deleted file mode 100644
index a8375bce3..000000000
--- a/core/src/main/java/de/danoeh/antennapod/core/service/FeedMediaSizeService.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package de.danoeh.antennapod.core.service;
-
-import android.app.IntentService;
-import android.content.Intent;
-import android.util.Log;
-
-public class FeedMediaSizeService extends IntentService {
-
- private final static String TAG = "FeedMediaSizeService";
-
- public FeedMediaSizeService() {
- super(TAG);
- }
-
- @Override
- protected void onHandleIntent(Intent intent) {
- Log.d(TAG, "onHandleIntent()");
- 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));
-// }
- }
-
-}
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 b80b4303f..7878d19a0 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
@@ -230,7 +230,7 @@ public class GpodnetSyncService extends Service {
for(GpodnetEpisodeAction action : localActions) {
Pair key = new Pair(action.getPodcast(), action.getEpisode());
GpodnetEpisodeAction mostRecent = localMostRecentPlayAction.get(key);
- if (mostRecent == null) {
+ if (mostRecent == null || mostRecent.getTimestamp() == null) {
localMostRecentPlayAction.put(key, action);
} else if (mostRecent.getTimestamp().before(action.getTimestamp())) {
localMostRecentPlayAction.put(key, action);
@@ -255,9 +255,10 @@ public class GpodnetSyncService extends Service {
Pair key = new Pair(action.getPodcast(), action.getEpisode());
GpodnetEpisodeAction localMostRecent = localMostRecentPlayAction.get(key);
if(localMostRecent == null ||
+ localMostRecent.getTimestamp() == null ||
localMostRecent.getTimestamp().before(action.getTimestamp())) {
GpodnetEpisodeAction mostRecent = mostRecentPlayAction.get(key);
- if (mostRecent == null) {
+ if (mostRecent == null || mostRecent.getTimestamp() == null) {
mostRecentPlayAction.put(key, action);
} else if (mostRecent.getTimestamp().before(action.getTimestamp())) {
mostRecentPlayAction.put(key, action);
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
index ec3d3e2fe..9aff7489b 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
@@ -1,13 +1,23 @@
package de.danoeh.antennapod.core.service.download;
+import android.support.annotation.NonNull;
+import android.os.Build;
import android.util.Log;
import com.squareup.okhttp.OkHttpClient;
+import java.io.IOException;
import java.net.CookieManager;
import java.net.CookiePolicy;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.security.GeneralSecurityException;
import java.util.concurrent.TimeUnit;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+
import de.danoeh.antennapod.core.BuildConfig;
/**
@@ -30,29 +40,44 @@ public class AntennapodHttpClient {
public static synchronized OkHttpClient getHttpClient() {
if (httpClient == null) {
- if (BuildConfig.DEBUG) Log.d(TAG, "Creating new instance of HTTP client");
+ httpClient = newHttpClient();
+ }
+ return httpClient;
+ }
- System.setProperty("http.maxConnections", String.valueOf(MAX_CONNECTIONS));
+ /**
+ * Creates a new HTTP client. Most users should just use
+ * getHttpClient() to get the standard AntennaPod client,
+ * but sometimes it's necessary for others to have their own
+ * copy so that the clients don't share state.
+ * @return http client
+ */
+ @NonNull
+ public static OkHttpClient newHttpClient() {
+ Log.d(TAG, "Creating new instance of HTTP client");
+
+ System.setProperty("http.maxConnections", String.valueOf(MAX_CONNECTIONS));
- OkHttpClient client = new OkHttpClient();
+ OkHttpClient client = new OkHttpClient();
- // set cookie handler
- CookieManager cm = new CookieManager();
- cm.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
- client.setCookieHandler(cm);
+ // set cookie handler
+ CookieManager cm = new CookieManager();
+ cm.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
+ client.setCookieHandler(cm);
- // set timeouts
- client.setConnectTimeout(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
- client.setReadTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
- client.setWriteTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
+ // set timeouts
+ client.setConnectTimeout(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
+ client.setReadTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
+ client.setWriteTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
- // configure redirects
- client.setFollowRedirects(true);
- client.setFollowSslRedirects(true);
+ // configure redirects
+ client.setFollowRedirects(true);
+ client.setFollowSslRedirects(true);
- httpClient = client;
+ if(16 <= Build.VERSION.SDK_INT && Build.VERSION.SDK_INT < 21) {
+ client.setSslSocketFactory(new CustomSslSocketFactory());
}
- return httpClient;
+ return client;
}
/**
@@ -64,4 +89,71 @@ public class AntennapodHttpClient {
// does nothing at the moment
}
}
+
+ private static class CustomSslSocketFactory extends SSLSocketFactory {
+
+ private SSLSocketFactory factory;
+
+ public CustomSslSocketFactory() {
+ try {
+ SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
+ sslContext.init(null, null, null);
+ factory= sslContext.getSocketFactory();
+ } catch(GeneralSecurityException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public String[] getDefaultCipherSuites() {
+ return factory.getDefaultCipherSuites();
+ }
+
+ @Override
+ public String[] getSupportedCipherSuites() {
+ return factory.getSupportedCipherSuites();
+ }
+
+ public Socket createSocket() throws IOException {
+ SSLSocket result = (SSLSocket) factory.createSocket();
+ configureSocket(result);
+ return result;
+ }
+
+ public Socket createSocket(String var1, int var2) throws IOException {
+ SSLSocket result = (SSLSocket) factory.createSocket(var1, var2);
+ configureSocket(result);
+ return result;
+ }
+
+ public Socket createSocket(Socket var1, String var2, int var3, boolean var4) throws IOException {
+ SSLSocket result = (SSLSocket) factory.createSocket(var1, var2, var3, var4);
+ configureSocket(result);
+ return result;
+ }
+
+ public Socket createSocket(InetAddress var1, int var2) throws IOException {
+ SSLSocket result = (SSLSocket) factory.createSocket(var1, var2);
+ configureSocket(result);
+ return result;
+ }
+
+ public Socket createSocket(String var1, int var2, InetAddress var3, int var4) throws IOException {
+ SSLSocket result = (SSLSocket) factory.createSocket(var1, var2, var3, var4);
+ configureSocket(result);
+ return result;
+ }
+
+ public Socket createSocket(InetAddress var1, int var2, InetAddress var3, int var4) throws IOException {
+ SSLSocket result = (SSLSocket) factory.createSocket(var1, var2, var3, var4);
+ configureSocket(result);
+ return result;
+ }
+
+ private void configureSocket(SSLSocket s) {
+ s.setEnabledProtocols(new String[] { "TLSv1.2", "TLSv1.1" } );
+ }
+
+ }
+
}
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 4fdaf6843..04ba77cda 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
@@ -114,11 +114,6 @@ public class DownloadService extends Service {
public static final String EXTRA_REQUEST = "request";
/**
- * Stores new media files that will be queued for auto-download if possible.
- */
- private List<Long> newMediaFiles;
-
- /**
* Contains all completed downloads that have not been included in the report yet.
*/
private List<DownloadStatus> reportQueue;
@@ -171,7 +166,7 @@ public class DownloadService extends Service {
}
private Thread downloadCompletionThread = new Thread() {
- private static final String TAG = "downloadCompletionThread";
+ private static final String TAG = "downloadCompletionThd";
@Override
public void run() {
@@ -241,7 +236,6 @@ public class DownloadService extends Service {
Log.d(TAG, "Service started");
isRunning = true;
handler = new Handler();
- newMediaFiles = Collections.synchronizedList(new ArrayList<Long>());
reportQueue = Collections.synchronizedList(new ArrayList<DownloadStatus>());
downloads = Collections.synchronizedList(new ArrayList<Downloader>());
numberOfDownloads = new AtomicInteger(0);
@@ -325,16 +319,8 @@ public class DownloadService extends Service {
cancelNotificationUpdater();
unregisterReceiver(cancelDownloadReceiver);
- // TODO: I'm not sure this is actually needed.
- // We could just invoke the autodownloadUndownloadeditems method
- // and it would get everything it's supposed to. By sending it the
- // items in newMediaFiles we're overriding the download algorithm,
- // which is not something we should probably do.
- if (!newMediaFiles.isEmpty()) {
- Log.d(TAG, "newMediaFiles exist, autodownload them");
- DBTasks.autodownloadUndownloadedItems(getApplicationContext(),
- ArrayUtils.toPrimitive(newMediaFiles.toArray(new Long[newMediaFiles.size()])));
- }
+ // start auto download in case anything new has shown up
+ DBTasks.autodownloadUndownloadedItems(getApplicationContext());
}
@SuppressLint("NewApi")
@@ -783,16 +769,6 @@ public class DownloadService extends Service {
for (int i = 0; i < savedFeeds.length; i++) {
Feed savedFeed = savedFeeds[i];
- // queue new media files for automatic download
- for (FeedItem item : savedFeed.getItems()) {
- if(item.getPubDate() == null) {
- Log.d(TAG, item.toString());
- }
- if (item.isNew() && item.hasMedia() && !item.getMedia().isDownloaded()) {
- newMediaFiles.add(item.getMedia().getId());
- }
- }
-
// If loadAllPages=true, check if another page is available and queue it for download
final boolean loadAllPages = results.get(i).first.getArguments().getBoolean(DownloadRequester.REQUEST_ARG_LOAD_ALL_PAGES);
final Feed feed = results.get(i).second.feed;
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java
index 5ed0a6ee3..3da3824a2 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java
@@ -522,29 +522,6 @@ public final class DBReader {
}
/**
- * Loads FeedMedia whose file size is unknown
- *
- * @param context A context that is used for opening a database connection.
- * @return A list of FeedMedia items whose size is 0 (unknown and never tried to
- * determine the correct size)
- */
- public static List<FeedMedia> getFeedMediaUnknownSize(Context context) {
- PodDBAdapter adapter = new PodDBAdapter(context);
- adapter.open();
- Cursor cursor = adapter.getFeedMediaUnknownSizeCursor();
- List<FeedMedia> result = new ArrayList<>(cursor.getCount());
- if (cursor.moveToFirst()) {
- do {
- FeedMedia media = extractFeedMediaFromCursorRow(cursor);
- result.add(media);
- } while (cursor.moveToNext());
- }
- cursor.close();
- return result;
- }
-
-
- /**
* Loads a list of FeedItems sorted by pubDate in descending order.
*
* @param context A context that is used for opening a database connection.
@@ -1141,7 +1118,7 @@ public final class DBReader {
Comparator<Feed> comparator;
int feedOrder = UserPreferences.getFeedOrder();
- if(feedOrder == UserPreferences.FEED_ORDER_UNPLAYED_EPISODES) {
+ if(feedOrder == UserPreferences.FEED_ORDER_COUNTER) {
comparator = new Comparator<Feed>() {
@Override
public int compare(Feed lhs, Feed rhs) {
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 6ced03c0e..5a3822a81 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
@@ -5,9 +5,6 @@ import android.content.Intent;
import android.database.Cursor;
import android.util.Log;
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -28,11 +25,8 @@ import de.danoeh.antennapod.core.asynctask.FlattrClickWorker;
import de.danoeh.antennapod.core.asynctask.FlattrStatusFetcher;
import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.feed.Feed;
-import de.danoeh.antennapod.core.feed.FeedImage;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
-import de.danoeh.antennapod.core.preferences.UserPreferences;
-import de.danoeh.antennapod.core.service.FeedMediaSizeService;
import de.danoeh.antennapod.core.service.GpodnetSyncService;
import de.danoeh.antennapod.core.service.download.DownloadStatus;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
@@ -578,8 +572,6 @@ public final class DBTasks {
EventDistributor.getInstance().sendFeedUpdateBroadcast();
- // context.startService(new Intent(context, FeedMediaSizeService.class));
-
return resultFeeds;
}
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 edb7598ab..b179c6f24 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
@@ -1110,13 +1110,6 @@ public class PodDBAdapter {
return db.rawQuery(query, null);
}
- public final Cursor getFeedMediaUnknownSizeCursor() {
- final String query = "SELECT * "
- + " FROM " + TABLE_NAME_FEED_MEDIA
- + " WHERE " + KEY_SIZE + "<= 0";
- return db.rawQuery(query, null);
- }
-
/**
* Returns a cursor which contains all items of a feed that are considered new.
* The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection.
@@ -1301,16 +1294,16 @@ public class PodDBAdapter {
}
public final LongIntMap getFeedCounters(long... feedIds) {
- int counter = UserPreferences.getFeedCounter();
+ int setting = UserPreferences.getFeedCounterSetting();
String whereRead;
- if(counter == UserPreferences.FEED_COUNTER_SHOW_NEW_UNPLAYED_SUM) {
+ if(setting == UserPreferences.FEED_COUNTER_SHOW_NEW_UNPLAYED_SUM) {
whereRead = "(" + KEY_READ + "=" + FeedItem.NEW
+ " OR " + KEY_READ + "=" + FeedItem.UNPLAYED + ")";
- } else if(counter == UserPreferences.FEED_COUNTER_SHOW_NEW) {
+ } else if(setting == UserPreferences.FEED_COUNTER_SHOW_NEW) {
whereRead = KEY_READ + "=" + FeedItem.NEW;
- } else if(counter == UserPreferences.FEED_COUNTER_SHOW_UNPLAYED) {
+ } else if(setting == UserPreferences.FEED_COUNTER_SHOW_UNPLAYED) {
whereRead = KEY_READ + "=" + FeedItem.UNPLAYED;
- } else {
+ } else { // NONE
return new LongIntMap(0);
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java
index 9296039f0..1b57baa11 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java
@@ -7,10 +7,23 @@ import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.util.Log;
+import com.squareup.okhttp.OkHttpClient;
+import com.squareup.okhttp.Request;
+import com.squareup.okhttp.Response;
+
+import java.io.File;
+import java.io.IOException;
import java.util.Arrays;
import java.util.List;
+import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UserPreferences;
+import de.danoeh.antennapod.core.service.download.AntennapodHttpClient;
+import de.danoeh.antennapod.core.storage.DBWriter;
+import rx.Observable;
+import rx.Subscriber;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.schedulers.Schedulers;
public class NetworkUtils {
@@ -78,4 +91,59 @@ public class NetworkUtils {
return mWifi.isConnected();
}
+ public static Observable<Long> getFeedMediaSizeObservable(FeedMedia media) {
+ return Observable.create(new Observable.OnSubscribe<Long>() {
+ @Override
+ public void call(Subscriber<? super Long> subscriber) {
+ if (false == NetworkUtils.isDownloadAllowed()) {
+ subscriber.onNext(0L);
+ subscriber.onCompleted();
+ 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
+ OkHttpClient client = AntennapodHttpClient.getHttpClient();
+ Request.Builder httpReq = new Request.Builder()
+ .url(media.getDownload_url())
+ .header("Accept-Encoding", "identity")
+ .head();
+ try {
+ Response response = client.newCall(httpReq.build()).execute();
+ if (response.isSuccessful()) {
+ String contentLength = response.header("Content-Length");
+ try {
+ size = Integer.parseInt(contentLength);
+ } catch (NumberFormatException e) {
+ Log.e(TAG, Log.getStackTraceString(e));
+ }
+ }
+ } catch (IOException e) {
+ subscriber.onNext(0L);
+ subscriber.onCompleted();
+ Log.e(TAG, Log.getStackTraceString(e));
+ return; // better luck next time
+ }
+ }
+ Log.d(TAG, "new size: " + size);
+ 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);
+ }
+ subscriber.onNext(size);
+ subscriber.onCompleted();
+ DBWriter.setFeedMedia(context, media);
+ }
+ })
+ .subscribeOn(Schedulers.newThread())
+ .observeOn(AndroidSchedulers.mainThread());
+ }
+
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/Timeline.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/Timeline.java
index f31297b41..0de9863e7 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/Timeline.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/Timeline.java
@@ -14,7 +14,6 @@ import org.jsoup.select.Elements;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.ShownotesProvider;
@@ -59,6 +58,8 @@ public class Timeline {
private static final Pattern TIMECODE_LINK_REGEX = Pattern.compile("antennapod://timecode/((\\d+))");
private static final String TIMECODE_LINK = "<a class=\"timecode\" href=\"antennapod://timecode/%d\">%s</a>";
private static final Pattern TIMECODE_REGEX = Pattern.compile("\\b(?:(?:(([0-9][0-9])):))?(([0-9][0-9])):(([0-9][0-9]))\\b");
+ private static final Pattern LINE_BREAK_REGEX = Pattern.compile("<br *\\/?>");
+
/**
* Applies an app-specific CSS stylesheet and adds timecode links (optional).
@@ -82,11 +83,15 @@ public class Timeline {
return null;
}
if (shownotes == null) {
- if (BuildConfig.DEBUG)
- Log.d(TAG, "shownotesProvider contained no shownotes. Returning empty string");
+ Log.d(TAG, "shownotesProvider contained no shownotes. Returning empty string");
return "";
}
+ // replace ASCII line breaks with HTML ones if shownotes don't contain HTML line breaks already
+ if(!LINE_BREAK_REGEX.matcher(shownotes).find()) {
+ shownotes = shownotes.replace("\n", "<br />");
+ }
+
Document document = Jsoup.parse(shownotes);
// apply style
@@ -97,10 +102,9 @@ public class Timeline {
// apply timecode links
if (addTimecodes) {
Elements elementsWithTimeCodes = document.body().getElementsMatchingOwnText(TIMECODE_REGEX);
- if (BuildConfig.DEBUG)
- Log.d(TAG, "Recognized " + elementsWithTimeCodes.size() + " timecodes");
+ Log.d(TAG, "Recognized " + elementsWithTimeCodes.size() + " timecodes");
for (Element element : elementsWithTimeCodes) {
- Matcher matcherLong = TIMECODE_REGEX.matcher(element.text());
+ Matcher matcherLong = TIMECODE_REGEX.matcher(element.html());
StringBuffer buffer = new StringBuffer();
while (matcherLong.find()) {
String h = matcherLong.group(1);