summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hennen <TomHennen@users.noreply.github.com>2015-05-18 21:35:10 -0400
committerTom Hennen <TomHennen@users.noreply.github.com>2015-05-18 21:35:10 -0400
commit14435c1aee38ae4c5982d5ab8ef6f26d7f21fb99 (patch)
tree0a7df862e6bd8087223daccbe4dd52b93c4ca6ad
parent73c4dfc04db814e6f2b4b2234150a404c2ec6cfa (diff)
parent910d8f1f2c94fc9ea4796c336c8fff93ecead099 (diff)
downloadAntennaPod-14435c1aee38ae4c5982d5ab8ef6f26d7f21fb99.zip
Merge pull request #815 from mfietz/tests
Tests fixed
-rw-r--r--app/build.gradle3
-rw-r--r--app/src/androidTest/java/de/test/antennapod/storage/DBTasksTest.java41
-rw-r--r--app/src/androidTest/java/de/test/antennapod/ui/MainActivityTest.java3
-rw-r--r--app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java117
-rw-r--r--app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java453
-rw-r--r--app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java9
-rw-r--r--app/src/main/templates/about.html4
-rw-r--r--build.gradle2
-rw-r--r--core/src/androidTest/java/de/danoeh/antennapod/core/test/ApplicationTest.java (renamed from core/src/androidTest/java/de/danoeh/antennapod/core/ApplicationTest.java)2
-rw-r--r--core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java16
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java504
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java3
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java59
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrUtils.java31
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/gui/UndoBarController.java3
15 files changed, 901 insertions, 349 deletions
diff --git a/app/build.gradle b/app/build.gradle
index bb1fa26b7..40451e8ea 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -5,6 +5,7 @@ apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
+
dependencies {
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'
@@ -14,7 +15,6 @@ dependencies {
exclude group: 'org.json', module: 'json'
}
compile 'commons-io:commons-io:2.4'
- compile 'com.jayway.android.robotium:robotium-solo:5.2.1'
compile 'org.jsoup:jsoup:1.7.3'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.3.0'
@@ -22,6 +22,7 @@ dependencies {
compile 'com.squareup.okio:okio:1.2.0'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.joanzapata.android:android-iconify:1.0.9'
+
compile project(':core')
compile project(':library:drag-sort-listview')
}
diff --git a/app/src/androidTest/java/de/test/antennapod/storage/DBTasksTest.java b/app/src/androidTest/java/de/test/antennapod/storage/DBTasksTest.java
index 41d3805bd..770b50952 100644
--- a/app/src/androidTest/java/de/test/antennapod/storage/DBTasksTest.java
+++ b/app/src/androidTest/java/de/test/antennapod/storage/DBTasksTest.java
@@ -3,6 +3,7 @@ package de.test.antennapod.storage;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
+import android.test.FlakyTest;
import android.test.InstrumentationTestCase;
import java.io.File;
@@ -27,15 +28,17 @@ import static de.test.antennapod.storage.DBTestUtils.saveFeedlist;
* Test class for DBTasks
*/
public class DBTasksTest extends InstrumentationTestCase {
- private static final String TEST_FOLDER = "testDBTasks";
+
+ private static final String TAG = "DBTasksTest";
private static final int EPISODE_CACHE_SIZE = 5;
+ private Context context;
+
private File destFolder;
@Override
protected void tearDown() throws Exception {
super.tearDown();
- final Context context = getInstrumentation().getTargetContext();
assertTrue(PodDBAdapter.deleteDatabase(context));
for (File f : destFolder.listFiles()) {
@@ -48,23 +51,24 @@ public class DBTasksTest extends InstrumentationTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
+ context = getInstrumentation().getTargetContext();
+ destFolder = context.getExternalCacheDir();
assertNotNull(destFolder);
assertTrue(destFolder.exists());
assertTrue(destFolder.canWrite());
- final Context context = getInstrumentation().getTargetContext();
context.deleteDatabase(PodDBAdapter.DATABASE_NAME);
// make sure database is created
PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
adapter.close();
- SharedPreferences.Editor prefEdit = PreferenceManager.getDefaultSharedPreferences(getInstrumentation().getTargetContext().getApplicationContext()).edit();
+ SharedPreferences.Editor prefEdit = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()).edit();
prefEdit.putString(UserPreferences.PREF_EPISODE_CACHE_SIZE, Integer.toString(EPISODE_CACHE_SIZE));
prefEdit.commit();
}
+ @FlakyTest(tolerance = 3)
public void testPerformAutoCleanupShouldDelete() throws IOException {
final int NUM_ITEMS = EPISODE_CACHE_SIZE * 2;
@@ -82,7 +86,7 @@ public class DBTasksTest extends InstrumentationTestCase {
items.add(item);
}
- PodDBAdapter adapter = new PodDBAdapter(getInstrumentation().getTargetContext());
+ PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
adapter.setCompleteFeed(feed);
adapter.close();
@@ -92,7 +96,7 @@ public class DBTasksTest extends InstrumentationTestCase {
assertTrue(item.getId() != 0);
assertTrue(item.getMedia().getId() != 0);
}
- DBTasks.performAutoCleanup(getInstrumentation().getTargetContext());
+ DBTasks.performAutoCleanup(context);
for (int i = 0; i < files.size(); i++) {
if (i < EPISODE_CACHE_SIZE) {
assertTrue(files.get(i).exists());
@@ -102,6 +106,7 @@ public class DBTasksTest extends InstrumentationTestCase {
}
}
+ @FlakyTest(tolerance = 3)
public void testPerformAutoCleanupShouldNotDeleteBecauseUnread() throws IOException {
final int NUM_ITEMS = EPISODE_CACHE_SIZE * 2;
@@ -120,7 +125,7 @@ public class DBTasksTest extends InstrumentationTestCase {
items.add(item);
}
- PodDBAdapter adapter = new PodDBAdapter(getInstrumentation().getTargetContext());
+ PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
adapter.setCompleteFeed(feed);
adapter.close();
@@ -130,12 +135,13 @@ public class DBTasksTest extends InstrumentationTestCase {
assertTrue(item.getId() != 0);
assertTrue(item.getMedia().getId() != 0);
}
- DBTasks.performAutoCleanup(getInstrumentation().getTargetContext());
+ DBTasks.performAutoCleanup(context);
for (File file : files) {
assertTrue(file.exists());
}
}
+ @FlakyTest(tolerance = 3)
public void testPerformAutoCleanupShouldNotDeleteBecauseInQueue() throws IOException {
final int NUM_ITEMS = EPISODE_CACHE_SIZE * 2;
@@ -154,7 +160,7 @@ public class DBTasksTest extends InstrumentationTestCase {
items.add(item);
}
- PodDBAdapter adapter = new PodDBAdapter(getInstrumentation().getTargetContext());
+ PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
adapter.setCompleteFeed(feed);
adapter.setQueue(items);
@@ -165,7 +171,7 @@ public class DBTasksTest extends InstrumentationTestCase {
assertTrue(item.getId() != 0);
assertTrue(item.getMedia().getId() != 0);
}
- DBTasks.performAutoCleanup(getInstrumentation().getTargetContext());
+ DBTasks.performAutoCleanup(context);
for (File file : files) {
assertTrue(file.exists());
}
@@ -176,13 +182,13 @@ public class DBTasksTest extends InstrumentationTestCase {
* call to DBWriter.deleteFeedMediaOfItem instead of the ID of the FeedMedia. This would cause the wrong item to be deleted.
* @throws IOException
*/
+ @FlakyTest(tolerance = 3)
public void testPerformAutoCleanupShouldNotDeleteBecauseInQueue_withFeedsWithNoMedia() throws IOException {
- final Context context = getInstrumentation().getTargetContext();
// add feed with no enclosures so that item ID != media ID
saveFeedlist(context, 1, 10, false);
// add candidate for performAutoCleanup
- List<Feed> feeds = saveFeedlist(getInstrumentation().getTargetContext(), 1, 1, true);
+ List<Feed> feeds = saveFeedlist(context, 1, 1, true);
FeedMedia m = feeds.get(0).getItems().get(0).getMedia();
m.setDownloaded(true);
m.setFile_url("file");
@@ -194,8 +200,8 @@ public class DBTasksTest extends InstrumentationTestCase {
testPerformAutoCleanupShouldNotDeleteBecauseInQueue();
}
+ @FlakyTest(tolerance = 3)
public void testUpdateFeedNewFeed() {
- final Context context = getInstrumentation().getTargetContext();
final int NUM_ITEMS = 10;
Feed feed = new Feed("url", new Date(), "title");
@@ -215,7 +221,6 @@ public class DBTasksTest extends InstrumentationTestCase {
/** Two feeds with the same title, but different download URLs should be treated as different feeds. */
public void testUpdateFeedSameTitle() {
- final Context context = getInstrumentation().getTargetContext();
Feed feed1 = new Feed("url1", new Date(), "title");
Feed feed2 = new Feed("url2", new Date(), "title");
@@ -230,7 +235,6 @@ public class DBTasksTest extends InstrumentationTestCase {
}
public void testUpdateFeedUpdatedFeed() {
- final Context context = getInstrumentation().getTargetContext();
final int NUM_ITEMS_OLD = 10;
final int NUM_ITEMS_NEW = 10;
@@ -270,6 +274,7 @@ public class DBTasksTest extends InstrumentationTestCase {
updatedFeedTest(feedFromDB, feedID, itemIDs, NUM_ITEMS_OLD, NUM_ITEMS_NEW);
}
+ @FlakyTest(tolerance = 3)
private void updatedFeedTest(final Feed newFeed, long feedID, List<Long> itemIDs, final int NUM_ITEMS_OLD, final int NUM_ITEMS_NEW) {
assertTrue(newFeed.getId() == feedID);
assertTrue(newFeed.getItems().size() == NUM_ITEMS_NEW + NUM_ITEMS_OLD);
@@ -293,8 +298,8 @@ public class DBTasksTest extends InstrumentationTestCase {
}
}
+ @FlakyTest(tolerance = 3)
private void expiredFeedListTestHelper(long lastUpdate, long expirationTime, boolean shouldReturn) {
- final Context context = getInstrumentation().getTargetContext();
UserPreferences.setUpdateInterval(context, expirationTime);
Feed feed = new Feed(0, new Date(lastUpdate), "feed", "link", "descr", null,
null, null, null, "feed", null, null, "url", false, new FlattrStatus(), false, null, null);
@@ -315,11 +320,13 @@ public class DBTasksTest extends InstrumentationTestCase {
}
}
+ @FlakyTest(tolerance = 3)
public void testGetExpiredFeedsTestShouldReturn() {
final long expirationTime = 1000 * 60 * 60;
expiredFeedListTestHelper(System.currentTimeMillis() - expirationTime - 1, expirationTime, true);
}
+ @FlakyTest(tolerance = 3)
public void testGetExpiredFeedsTestShouldNotReturn() {
final long expirationTime = 1000 * 60 * 60;
expiredFeedListTestHelper(System.currentTimeMillis() - expirationTime / 2, expirationTime, false);
diff --git a/app/src/androidTest/java/de/test/antennapod/ui/MainActivityTest.java b/app/src/androidTest/java/de/test/antennapod/ui/MainActivityTest.java
index 470866c3c..0326174e3 100644
--- a/app/src/androidTest/java/de/test/antennapod/ui/MainActivityTest.java
+++ b/app/src/androidTest/java/de/test/antennapod/ui/MainActivityTest.java
@@ -3,6 +3,7 @@ package de.test.antennapod.ui;
import android.content.Context;
import android.content.SharedPreferences;
import android.test.ActivityInstrumentationTestCase2;
+import android.test.FlakyTest;
import android.widget.ListView;
import com.robotium.solo.Solo;
@@ -85,6 +86,7 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
solo.waitForText(solo.getString(R.string.subscribed_label));
}
+ @FlakyTest(tolerance = 3)
public void testClickNavDrawer() throws Exception {
uiTestUtils.addLocalFeedData(false);
@@ -142,6 +144,7 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
return ((MainActivity)solo.getCurrentActivity()).getMainActivtyActionBar().getTitle().toString();
}
+ @FlakyTest(tolerance = 3)
public void testGoToPreferences() {
openNavDrawer();
solo.clickOnText(solo.getString(R.string.settings_label));
diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java
index 8f1477192..775bc0ecd 100644
--- a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java
+++ b/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java
@@ -1,17 +1,18 @@
package de.test.antennapod.ui;
+import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.test.ActivityInstrumentationTestCase2;
-import android.widget.TextView;
+import com.robotium.solo.Condition;
import com.robotium.solo.Solo;
+import com.robotium.solo.Timeout;
import java.util.List;
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.activity.AudioplayerActivity;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.preferences.UserPreferences;
@@ -28,6 +29,8 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
private Solo solo;
private UITestUtils uiTestUtils;
+ private Context context;
+
public PlaybackTest() {
super(MainActivity.class);
}
@@ -36,28 +39,33 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
public void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
- uiTestUtils = new UITestUtils(getInstrumentation().getTargetContext());
+ context = getInstrumentation().getContext();
+
+ uiTestUtils = new UITestUtils(context);
uiTestUtils.setup();
+
// create database
- PodDBAdapter adapter = new PodDBAdapter(getInstrumentation().getTargetContext());
+ PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
adapter.close();
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getInstrumentation().getTargetContext());
- prefs.edit().putBoolean(UserPreferences.PREF_UNPAUSE_ON_HEADSET_RECONNECT, false).commit();
- prefs.edit().putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false).commit();
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ prefs.edit()
+ .putBoolean(UserPreferences.PREF_UNPAUSE_ON_HEADSET_RECONNECT, false)
+ .putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false)
+ .putString(UserPreferences.PREF_HIDDEN_DRAWER_ITEMS, "")
+ .commit();
}
@Override
public void tearDown() throws Exception {
uiTestUtils.tearDown();
solo.finishOpenedActivities();
- PodDBAdapter.deleteDatabase(getInstrumentation().getTargetContext());
+ PodDBAdapter.deleteDatabase(context);
// shut down playback service
skipEpisode();
- getInstrumentation().getTargetContext().sendBroadcast(
- new Intent(PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
+ context.sendBroadcast(new Intent(PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
super.tearDown();
}
@@ -67,70 +75,97 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
}
private void setContinuousPlaybackPreference(boolean value) {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getInstrumentation().getTargetContext());
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putBoolean(UserPreferences.PREF_FOLLOW_QUEUE, value).commit();
}
private void skipEpisode() {
Intent skipIntent = new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE);
- getInstrumentation().getTargetContext().sendBroadcast(skipIntent);
+ context.sendBroadcast(skipIntent);
}
private void startLocalPlayback() {
- assertTrue(solo.waitForActivity(MainActivity.class));
openNavDrawer();
+
solo.clickOnText(solo.getString(R.string.all_episodes_label));
- solo.waitForView(android.R.id.list);
+ final List<FeedItem> episodes = DBReader.getRecentlyPublishedEpisodes(context, 10);
+ assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction)));
+
solo.clickOnView(solo.getView(R.id.butSecondaryAction));
- assertTrue(solo.waitForActivity(AudioplayerActivity.class));
assertTrue(solo.waitForView(solo.getView(R.id.butPlay)));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return episodes.get(0).getMedia().isCurrentlyPlaying();
+ }
+ }, Timeout.getLargeTimeout());
}
private void startLocalPlaybackFromQueue() {
- assertTrue(solo.waitForActivity(MainActivity.class));
- openNavDrawer();
- solo.clickOnText(solo.getString(R.string.queue_label));
assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction)));
+ final List<FeedItem> queue = DBReader.getQueue(context);
solo.clickOnImageButton(1);
- assertTrue(solo.waitForActivity(AudioplayerActivity.class));
assertTrue(solo.waitForView(solo.getView(R.id.butPlay)));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return queue.get(0).getMedia().isCurrentlyPlaying();
+ }
+ }, Timeout.getLargeTimeout());
}
public void testStartLocal() throws Exception {
uiTestUtils.addLocalFeedData(true);
- DBWriter.clearQueue(getInstrumentation().getTargetContext()).get();
+ DBWriter.clearQueue(context).get();
startLocalPlayback();
-
- solo.clickOnView(solo.getView(R.id.butPlay));
}
public void testContinousPlaybackOffSingleEpisode() throws Exception {
setContinuousPlaybackPreference(false);
uiTestUtils.addLocalFeedData(true);
- DBWriter.clearQueue(getInstrumentation().getTargetContext()).get();
+ DBWriter.clearQueue(context).get();
startLocalPlayback();
- assertTrue(solo.waitForActivity(MainActivity.class));
}
public void testContinousPlaybackOffMultipleEpisodes() throws Exception {
setContinuousPlaybackPreference(false);
uiTestUtils.addLocalFeedData(true);
- List<FeedItem> queue = DBReader.getQueue(getInstrumentation().getTargetContext());
- FeedItem second = queue.get(0);
+ List<FeedItem> queue = DBReader.getQueue(context);
+ final FeedItem first = queue.get(0);
+ final FeedItem second = queue.get(1);
startLocalPlaybackFromQueue();
- assertTrue(solo.waitForText(second.getTitle()));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return first.getMedia().isCurrentlyPlaying() == false;
+ }
+ }, 10000);
+ Thread.sleep(1000);
+ assertTrue(second.getMedia().isCurrentlyPlaying() == false);
}
public void testContinuousPlaybackOnMultipleEpisodes() throws Exception {
setContinuousPlaybackPreference(true);
uiTestUtils.addLocalFeedData(true);
- List<FeedItem> queue = DBReader.getQueue(getInstrumentation().getTargetContext());
- FeedItem second = queue.get(1);
+ List<FeedItem> queue = DBReader.getQueue(context);
+ final FeedItem first = queue.get(0);
+ final FeedItem second = queue.get(1);
startLocalPlaybackFromQueue();
- assertTrue(solo.waitForText(second.getTitle()));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return first.getMedia().isCurrentlyPlaying() == false;
+ }
+ }, 10000);
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return second.getMedia().isCurrentlyPlaying() == true;
+ }
+ }, 10000);
}
/**
@@ -139,14 +174,24 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
private void replayEpisodeCheck(boolean followQueue) throws Exception {
setContinuousPlaybackPreference(followQueue);
uiTestUtils.addLocalFeedData(true);
- DBWriter.clearQueue(getInstrumentation().getTargetContext()).get();
- String title = ((TextView) solo.getView(R.id.txtvTitle)).getText().toString();
+ DBWriter.clearQueue(context).get();
+ final List<FeedItem> episodes = DBReader.getRecentlyPublishedEpisodes(context, 10);
+
startLocalPlayback();
- assertTrue(solo.waitForText(title));
- assertTrue(solo.waitForActivity(MainActivity.class));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return false == episodes.get(0).getMedia().isCurrentlyPlaying();
+ }
+ }, Timeout.getLargeTimeout());
+
startLocalPlayback();
- assertTrue(solo.waitForText(title));
- assertTrue(solo.waitForActivity(MainActivity.class));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return false == episodes.get(0).getMedia().isCurrentlyPlaying();
+ }
+ }, Timeout.getLargeTimeout());
}
public void testReplayEpisodeContinuousPlaybackOn() throws Exception {
diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java
new file mode 100644
index 000000000..eb1cb9c71
--- /dev/null
+++ b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java
@@ -0,0 +1,453 @@
+package de.test.antennapod.ui;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.FlakyTest;
+
+import com.robotium.solo.Condition;
+import com.robotium.solo.Solo;
+import com.robotium.solo.Timeout;
+
+import org.apache.commons.io.IOUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.activity.PreferenceActivity;
+import de.danoeh.antennapod.core.preferences.UserPreferences;
+
+public class PreferencesTest extends ActivityInstrumentationTestCase2<PreferenceActivity> {
+
+ private static final String TAG = "PreferencesTest";
+
+ private Solo solo;
+ private Context context;
+ private Resources res;
+
+ public PreferencesTest() {
+ super(PreferenceActivity.class);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ solo = new Solo(getInstrumentation(), getActivity());
+ Timeout.setSmallTimeout(500);
+ Timeout.setLargeTimeout(1000);
+ context = getInstrumentation().getTargetContext();
+ res = getActivity().getResources();
+ UserPreferences.createInstance(context);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ solo.finishOpenedActivities();
+ super.tearDown();
+ }
+
+ public void testSwitchTheme() {
+ final int theme = UserPreferences.getTheme();
+ int otherTheme;
+ if(theme == de.danoeh.antennapod.core.R.style.Theme_AntennaPod_Light) {
+ otherTheme = R.string.pref_theme_title_dark;
+ } else {
+ otherTheme = R.string.pref_theme_title_light;
+ }
+ solo.clickOnText(solo.getString(R.string.pref_set_theme_title));
+ solo.waitForDialogToOpen();
+ solo.clickOnText(solo.getString(otherTheme));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return UserPreferences.getTheme() != theme;
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testSwitchThemeBack() {
+ final int theme = UserPreferences.getTheme();
+ int otherTheme;
+ if(theme == de.danoeh.antennapod.core.R.style.Theme_AntennaPod_Light) {
+ otherTheme = R.string.pref_theme_title_dark;
+ } else {
+ otherTheme = R.string.pref_theme_title_light;
+ }
+ solo.clickOnText(solo.getString(R.string.pref_set_theme_title));
+ solo.waitForDialogToOpen(1000);
+ solo.clickOnText(solo.getString(otherTheme));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return UserPreferences.getTheme() != theme;
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testExpandNotification() {
+ final int priority = UserPreferences.getNotifyPriority();
+ solo.clickOnText(solo.getString(R.string.pref_expandNotify_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return priority != UserPreferences.getNotifyPriority();
+ }
+ }, Timeout.getLargeTimeout());
+ solo.clickOnText(solo.getString(R.string.pref_expandNotify_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return priority == UserPreferences.getNotifyPriority();
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testEnablePersistentPlaybackControls() {
+ final boolean persistNotify = UserPreferences.isPersistNotify();
+ solo.clickOnText(solo.getString(R.string.pref_persistNotify_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return persistNotify != UserPreferences.isPersistNotify();
+ }
+ }, Timeout.getLargeTimeout());
+ solo.clickOnText(solo.getString(R.string.pref_persistNotify_title));
+ solo.waitForCondition(new Condition() {
+ @Override public boolean isSatisfied() {
+ return persistNotify == UserPreferences.isPersistNotify();
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testEnqueueAtFront() {
+ final boolean enqueueAtFront = UserPreferences.enqueueAtFront();
+ solo.clickOnText(solo.getString(R.string.pref_queueAddToFront_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return enqueueAtFront != UserPreferences.enqueueAtFront();
+ }
+ }, Timeout.getLargeTimeout());
+ solo.clickOnText(solo.getString(R.string.pref_queueAddToFront_title));
+ solo.waitForCondition(new Condition() {
+ @Override public boolean isSatisfied() {
+ return enqueueAtFront == UserPreferences.enqueueAtFront();
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testHeadPhonesDisconnect() {
+ final boolean pauseOnHeadsetDisconnect = UserPreferences.isPauseOnHeadsetDisconnect();
+ solo.clickOnText(solo.getString(R.string.pref_pauseOnHeadsetDisconnect_title));
+ solo.waitForCondition(new Condition() {
+ @Override public boolean isSatisfied() {
+ return pauseOnHeadsetDisconnect != UserPreferences.isPauseOnHeadsetDisconnect();
+ }
+ }, Timeout.getLargeTimeout());
+ solo.clickOnText(solo.getString(R.string.pref_pauseOnHeadsetDisconnect_title));
+ solo.waitForCondition(new Condition() {
+ @Override public boolean isSatisfied() {
+ return pauseOnHeadsetDisconnect == UserPreferences.isPauseOnHeadsetDisconnect();
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testHeadPhonesReconnect() {
+ if(UserPreferences.isPauseOnHeadsetDisconnect() == false) {
+ solo.clickOnText(solo.getString(R.string.pref_pauseOnHeadsetDisconnect_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return UserPreferences.isPauseOnHeadsetDisconnect();
+ }
+ }, Timeout.getLargeTimeout());
+ }
+ final boolean unpauseOnHeadsetReconnect = UserPreferences.isUnpauseOnHeadsetReconnect();
+ solo.clickOnText(solo.getString(R.string.pref_unpauseOnHeadsetReconnect_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return unpauseOnHeadsetReconnect != UserPreferences.isUnpauseOnHeadsetReconnect();
+ }
+ }, Timeout.getLargeTimeout());
+ solo.clickOnText(solo.getString(R.string.pref_unpauseOnHeadsetReconnect_title));
+ solo.waitForCondition(new Condition() {
+ @Override public boolean isSatisfied() {
+ return unpauseOnHeadsetReconnect == UserPreferences.isUnpauseOnHeadsetReconnect();
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testContinuousPlayback() {
+ final boolean continuousPlayback = UserPreferences.isFollowQueue();
+ solo.clickOnText(solo.getString(R.string.pref_followQueue_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return continuousPlayback != UserPreferences.isFollowQueue();
+ }
+ }, Timeout.getLargeTimeout());
+ solo.clickOnText(solo.getString(R.string.pref_followQueue_title));
+ solo.waitForCondition(new Condition() {
+ @Override public boolean isSatisfied() {
+ return continuousPlayback == UserPreferences.isFollowQueue();
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testAutoDelete() {
+ final boolean autoDelete = UserPreferences.isAutoDelete();
+ solo.clickOnText(solo.getString(R.string.pref_auto_delete_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return autoDelete != UserPreferences.isAutoDelete();
+ }
+ }, Timeout.getLargeTimeout());
+ solo.clickOnText(solo.getString(R.string.pref_auto_delete_title));
+ solo.waitForCondition(new Condition() {
+ @Override public boolean isSatisfied() {
+ return autoDelete == UserPreferences.isAutoDelete();
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testPlaybackSpeeds() {
+ solo.clickOnText(solo.getString(R.string.pref_playback_speed_title));
+ solo.waitForDialogToOpen(1000);
+ assertTrue(solo.searchText(solo.getString(R.string.no_playback_plugin_title)));
+ solo.clickOnText(solo.getString(R.string.close_label));
+ solo.waitForDialogToClose(1000);
+ }
+
+ public void testPauseForInterruptions() {
+ final boolean pauseForFocusLoss = UserPreferences.shouldPauseForFocusLoss();
+ solo.clickOnText(solo.getString(R.string.pref_pausePlaybackForFocusLoss_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return pauseForFocusLoss != UserPreferences.shouldPauseForFocusLoss();
+ }
+ }, Timeout.getLargeTimeout());
+ solo.clickOnText(solo.getString(R.string.pref_auto_delete_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return pauseForFocusLoss == UserPreferences.shouldPauseForFocusLoss();
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testDisableUpdateInterval() {
+ solo.clickOnText(solo.getString(R.string.pref_autoUpdateIntervall_title));
+ solo.waitForDialogToOpen();
+ solo.clickOnText(solo.getString(R.string.pref_update_interval_hours_manual));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return UserPreferences.getUpdateInterval() == 0;
+ }
+ }, 1000);
+ }
+
+ public void testSetUpdateInterval() {
+ solo.clickOnText(solo.getString(R.string.pref_autoUpdateIntervall_title));
+ solo.waitForDialogToOpen();
+ String search = "12 " + solo.getString(R.string.pref_update_interval_hours_plural);
+ solo.clickOnText(search);
+ solo.waitForDialogToClose();
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return UserPreferences.getUpdateInterval() == 12;
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testMobileUpdates() {
+ final boolean mobileUpdates = UserPreferences.isAllowMobileUpdate();
+ solo.clickOnText(solo.getString(R.string.pref_mobileUpdate_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return mobileUpdates != UserPreferences.isAllowMobileUpdate();
+ }
+ }, Timeout.getLargeTimeout());
+ solo.clickOnText(solo.getString(R.string.pref_mobileUpdate_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return mobileUpdates == UserPreferences.isAllowMobileUpdate();
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testSetSequentialDownload() {
+ solo.clickOnText(solo.getString(R.string.pref_parallel_downloads_title));
+ solo.waitForDialogToOpen();
+ solo.clearEditText(0);
+ solo.enterText(0, "1");
+ solo.clickOnText(solo.getString(android.R.string.ok));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return UserPreferences.getParallelDownloads() == 1;
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testSetParallelDownloads() {
+ solo.clickOnText(solo.getString(R.string.pref_parallel_downloads_title));
+ solo.waitForDialogToOpen();
+ solo.clearEditText(0);
+ solo.enterText(0, "10");
+ solo.clickOnText(solo.getString(android.R.string.ok));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return UserPreferences.getParallelDownloads() == 10;
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testSetParallelDownloadsInvalidInput() {
+ solo.clickOnText(solo.getString(R.string.pref_parallel_downloads_title));
+ solo.waitForDialogToOpen();
+ solo.clearEditText(0);
+ solo.enterText(0, "0");
+ assertEquals("1", solo.getEditText(0).getText().toString());
+ solo.clearEditText(0);
+ solo.enterText(0, "100");
+ assertEquals("50", solo.getEditText(0).getText().toString());
+ }
+
+ public void testSetEpisodeCache() {
+ String[] entries = res.getStringArray(R.array.episode_cache_size_entries);
+ String[] values = res.getStringArray(R.array.episode_cache_size_values);
+ String entry = entries[entries.length/2];
+ final int value = Integer.valueOf(values[values.length/2]);
+ solo.clickOnText(solo.getString(R.string.pref_episode_cache_title));
+ solo.waitForDialogToOpen();
+ solo.clickOnText(entry);
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return UserPreferences.getEpisodeCacheSize() == value;
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testSetEpisodeCacheMin() {
+ String[] entries = res.getStringArray(R.array.episode_cache_size_entries);
+ String[] values = res.getStringArray(R.array.episode_cache_size_values);
+ String minEntry = entries[0];
+ final int minValue = Integer.valueOf(values[0]);
+ solo.clickOnText(solo.getString(R.string.pref_episode_cache_title));
+ solo.waitForDialogToOpen(1000);
+ solo.scrollUp();
+ solo.clickOnText(minEntry);
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return UserPreferences.getEpisodeCacheSize() == minValue;
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+
+ public void testSetEpisodeCacheMax() {
+ String[] entries = res.getStringArray(R.array.episode_cache_size_entries);
+ String[] values = res.getStringArray(R.array.episode_cache_size_values);
+ String maxEntry = entries[entries.length-1];
+ final int maxValue = Integer.valueOf(values[values.length-1]);
+ solo.clickOnText(solo.getString(R.string.pref_episode_cache_title));
+ solo.waitForDialogToOpen();
+ solo.clickOnText(maxEntry);
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return UserPreferences.getEpisodeCacheSize() == maxValue;
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ public void testAutomaticDownload() {
+ final boolean automaticDownload = UserPreferences.isEnableAutodownload();
+ solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
+ solo.waitForText(solo.getString(R.string.pref_automatic_download_title));
+ solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return automaticDownload != UserPreferences.isEnableAutodownload();
+ }
+ }, Timeout.getLargeTimeout());
+ if(UserPreferences.isEnableAutodownload() == false) {
+ solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
+ }
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return UserPreferences.isEnableAutodownload() == true;
+ }
+ }, Timeout.getLargeTimeout());
+ final boolean enableAutodownloadOnBattery = UserPreferences.isEnableAutodownloadOnBattery();
+ solo.clickOnText(solo.getString(R.string.pref_automatic_download_on_battery_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return enableAutodownloadOnBattery != UserPreferences.isEnableAutodownloadOnBattery();
+ }
+ }, Timeout.getLargeTimeout());
+ solo.clickOnText(solo.getString(R.string.pref_automatic_download_on_battery_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return enableAutodownloadOnBattery == UserPreferences.isEnableAutodownloadOnBattery();
+ }
+ }, Timeout.getLargeTimeout());
+ final boolean enableWifiFilter = UserPreferences.isEnableAutodownloadWifiFilter();
+ solo.clickOnText(solo.getString(R.string.pref_autodl_wifi_filter_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return enableWifiFilter != UserPreferences.isEnableAutodownloadWifiFilter();
+ }
+ }, Timeout.getLargeTimeout());
+ solo.clickOnText(solo.getString(R.string.pref_automatic_download_on_battery_title));
+ solo.waitForCondition(new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return enableWifiFilter == UserPreferences.isEnableAutodownloadWifiFilter();
+ }
+ }, Timeout.getLargeTimeout());
+ }
+
+ @FlakyTest(tolerance = 3)
+ public void testAbout() throws IOException {
+ int numViews = 0, numLinks = 0;
+ InputStream input = getActivity().getResources().getAssets().open("about.html");
+ List<String> lines = IOUtils.readLines(input);
+ input.close();
+ for(String line : lines) {
+ if(line.contains("(View)")) {
+ numViews++;
+ } else if(line.contains("(Link)")) {
+ numLinks++;
+ }
+ }
+ for(int i=0; i < numViews; i++) {
+ solo.clickOnText(solo.getString(R.string.about_pref));
+ solo.clickOnText("(View)", i);
+ solo.goBack();
+ }
+ for(int i=0; i < numLinks; i++) {
+ solo.clickOnText(solo.getString(R.string.about_pref));
+ solo.clickOnText("(Link)", i);
+ solo.goBack();
+ }
+ }
+
+}
diff --git a/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java b/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java
index 85923d40f..613826932 100644
--- a/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java
+++ b/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java
@@ -141,11 +141,12 @@ public class UITestUtils {
// create items
List<FeedItem> items = new ArrayList<FeedItem>();
for (int j = 0; j < NUM_ITEMS_PER_FEED; j++) {
- FeedItem item = new FeedItem(0, "item" + j, "item" + j, "http://example.com/feed" + i + "/item/" + j, new Date(), true, feed);
+ FeedItem item = new FeedItem(j, "Feed " + (i+1) + ": Item " + (j+1), "item" + j,
+ "http://example.com/feed" + i + "/item/" + j, new Date(), false, feed);
items.add(item);
File mediaFile = newMediaFile("feed-" + i + "-episode-" + j + ".mp3");
- item.setMedia(new FeedMedia(0, item, 0, 0, mediaFile.length(), "audio/mp3", null, hostFile(mediaFile), false, null, 0));
+ item.setMedia(new FeedMedia(j, item, 0, 0, mediaFile.length(), "audio/mp3", null, hostFile(mediaFile), false, null, 0));
}
feed.setItems(items);
@@ -169,7 +170,9 @@ public class UITestUtils {
* @param downloadEpisodes true if episodes should also be marked as downloaded.
*/
public void addLocalFeedData(boolean downloadEpisodes) throws Exception {
- if (localFeedDataAdded) throw new IllegalStateException("addLocalFeedData was called twice on the same instance");
+ if (localFeedDataAdded) {
+ throw new IllegalStateException("addLocalFeedData was called twice on the same instance");
+ }
if (!feedDataHosted) {
addHostedFeedData();
}
diff --git a/app/src/main/templates/about.html b/app/src/main/templates/about.html
index 3a48eeec1..3313fa12f 100644
--- a/app/src/main/templates/about.html
+++ b/app/src/main/templates/about.html
@@ -79,10 +79,10 @@ licensed under the Apache 2.0 license <a href="LICENSE_OKIO.txt">(View)</a>
<h2>Material Design Icons <a href="https://github.com/google/material-design-icons">(Link)</a></h2>
by Google, licensed under an Attribution-ShareAlike 4.0 International license <a href="LICENSE_MATERIAL_DESIGN_ICONS.txt">(View)</a>
-<h2>EventBus <a href="https://github.com/greenrobot/EventBus">(Link>)</a></h2>
+<h2>EventBus <a href="https://github.com/greenrobot/EventBus">(Link)</a></h2>
by greenrobot, licensed under the Apache 2.0 license <a href="LICENSE_EVENTBUS.txt">(View)</a>
-<h2>Iconify <a href="https://github.com/JoanZapata/android-iconify">(Link>)</a></h2>
+<h2>Iconify <a href="https://github.com/JoanZapata/android-iconify">(Link)</a></h2>
by Joan Zapata, licensed under the Apache 2.0 license <a href="LICENSE_ANDROID_ICONIFY.txt">(View)</a>
</body>
diff --git a/build.gradle b/build.gradle
index 9f1a2d6ab..8cfd58c04 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:1.0.0'
+ classpath 'com.android.tools.build:gradle:1.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/ApplicationTest.java b/core/src/androidTest/java/de/danoeh/antennapod/core/test/ApplicationTest.java
index 894bcfa63..ee9db0133 100644
--- a/core/src/androidTest/java/de/danoeh/antennapod/core/ApplicationTest.java
+++ b/core/src/androidTest/java/de/danoeh/antennapod/core/test/ApplicationTest.java
@@ -1,4 +1,4 @@
-package de.danoeh.antennapod.core;
+package de.danoeh.antennapod.core.test;
import android.app.Application;
import android.test.ApplicationTestCase;
diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java b/core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java
index cca753895..46140fbd1 100644
--- a/core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java
+++ b/core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java
@@ -56,4 +56,20 @@ public class DateUtilsTest extends AndroidTestCase {
assertEquals(900, actual.getTime()%1000);
}
+ public void testParseDateWithTimezoneName() throws Exception {
+ GregorianCalendar exp = new GregorianCalendar(2015, 2, 28, 6, 31, 4);
+ exp.setTimeZone(TimeZone.getTimeZone("UTC"));
+ Date expected = new Date(exp.getTimeInMillis());
+ Date actual = DateUtils.parse("Sat, 28 Mar 2015 01:31:04 EST");
+ assertEquals(expected, actual);
+ }
+
+ public void testParseDateWithTimeZoneOffset() throws Exception {
+ GregorianCalendar exp = new GregorianCalendar(2015, 2, 28, 12, 16, 12);
+ exp.setTimeZone(TimeZone.getTimeZone("UTC"));
+ Date expected = new Date(exp.getTimeInMillis());
+ Date actual = DateUtils.parse("Sat, 28 March 2015 08:16:12 -0400");
+ assertEquals(expected, actual);
+ }
+
}
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 d196a91b9..594241573 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
@@ -22,7 +22,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
-import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.receiver.FeedUpdateReceiver;
@@ -35,37 +34,51 @@ import de.danoeh.antennapod.core.receiver.FeedUpdateReceiver;
*/
public class UserPreferences implements
SharedPreferences.OnSharedPreferenceChangeListener {
+
public static final String IMPORT_DIR = "import/";
+
private static final String TAG = "UserPreferences";
+ // User Infercasce
+ public static final String PREF_THEME = "prefTheme";
+ public static final String PREF_HIDDEN_DRAWER_ITEMS = "prefHiddenDrawerItems";
+ public static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify";
+ public static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify";
+
+ // Queue
+ public static final String PREF_QUEUE_ADD_TO_FRONT = "prefQueueAddToFront";
+
+ // Playback
public static final String PREF_PAUSE_ON_HEADSET_DISCONNECT = "prefPauseOnHeadsetDisconnect";
public static final String PREF_UNPAUSE_ON_HEADSET_RECONNECT = "prefUnpauseOnHeadsetReconnect";
public static final String PREF_FOLLOW_QUEUE = "prefFollowQueue";
- public static final String PREF_DOWNLOAD_MEDIA_ON_WIFI_ONLY = "prefDownloadMediaOnWifiOnly";
- public static final String PREF_UPDATE_INTERVAL = "prefAutoUpdateIntervall";
- public static final String PREF_PARALLEL_DOWNLOADS = "prefParallelDownloads";
- public static final String PREF_MOBILE_UPDATE = "prefMobileUpdate";
public static final String PREF_AUTO_DELETE = "prefAutoDelete";
public static final String PREF_SMART_MARK_AS_PLAYED_SECS = "prefSmartMarkAsPlayedSecs";
- public static final String PREF_AUTO_FLATTR = "pref_auto_flattr";
- public static final String PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD = "prefAutoFlattrPlayedDurationThreshold";
- public static final String PREF_THEME = "prefTheme";
- public static final String PREF_DATA_FOLDER = "prefDataFolder";
- public static final String PREF_ENABLE_AUTODL = "prefEnableAutoDl";
- public static final String PREF_ENABLE_AUTODL_WIFI_FILTER = "prefEnableAutoDownloadWifiFilter";
- public static final String PREF_ENABLE_AUTODL_ON_BATTERY = "prefEnableAutoDownloadOnBattery";
- private static final String PREF_AUTODL_SELECTED_NETWORKS = "prefAutodownloadSelectedNetworks";
- public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize";
- private static final String PREF_PLAYBACK_SPEED = "prefPlaybackSpeed";
private static final String PREF_PLAYBACK_SPEED_ARRAY = "prefPlaybackSpeedArray";
public static final String PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS = "prefPauseForFocusLoss";
public static final String PREF_RESUME_AFTER_CALL = "prefResumeAfterCall";
+
+ // Network
+ public static final String PREF_UPDATE_INTERVAL = "prefAutoUpdateIntervall";
+ public static final String PREF_MOBILE_UPDATE = "prefMobileUpdate";
+ public static final String PREF_PARALLEL_DOWNLOADS = "prefParallelDownloads";
+ public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize";
+ public static final String PREF_ENABLE_AUTODL = "prefEnableAutoDl";
+ public static final String PREF_ENABLE_AUTODL_ON_BATTERY = "prefEnableAutoDownloadOnBattery";
+ public static final String PREF_ENABLE_AUTODL_WIFI_FILTER = "prefEnableAutoDownloadWifiFilter";
+ public static final String PREF_AUTODL_SELECTED_NETWORKS = "prefAutodownloadSelectedNetworks";
+
+ // Services
+ public static final String PREF_AUTO_FLATTR = "pref_auto_flattr";
+ public static final String PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD = "prefAutoFlattrPlayedDurationThreshold";
+
+ // Other
+ public static final String PREF_DATA_FOLDER = "prefDataFolder";
+
+ // Mediaplayer
+ public static final String PREF_PLAYBACK_SPEED = "prefPlaybackSpeed";
private static final String PREF_FAST_FORWARD_SECS = "prefFastForwardSecs";
private static final String PREF_REWIND_SECS = "prefRewindSecs";
- private static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify";
- private static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify";
- public static final String PREF_QUEUE_ADD_TO_FRONT = "prefQueueAddToFront";
- public static final String PREF_HIDDEN_DRAWER_ITEMS = "prefHiddenDrawerItems";
public static final String PREF_QUEUE_LOCKED = "prefQueueLocked";
// TODO: Make this value configurable
@@ -76,36 +89,46 @@ public class UserPreferences implements
private static UserPreferences instance;
private final Context context;
- // Preferences
+ // User Interface
+ private int theme;
+ private List<String> hiddenDrawerItems;
+ private int notifyPriority;
+ private boolean persistNotify;
+
+ // Queue
+ private boolean enqueueAtFront;
+
+ // Playback
private boolean pauseOnHeadsetDisconnect;
private boolean unpauseOnHeadsetReconnect;
private boolean followQueue;
- private boolean downloadMediaOnWifiOnly;
- private long updateInterval;
- private boolean allowMobileUpdate;
private boolean autoDelete;
private int smartMarkAsPlayedSecs;
- private boolean autoFlattr;
- private float autoFlattrPlayedDurationThreshold;
- private int theme;
+ private String[] playbackSpeedArray;
+ private boolean pauseForFocusLoss;
+ private boolean resumeAfterCall;
+
+ // Network
+ private long updateInterval;
+ private boolean allowMobileUpdate;
+ private int parallelDownloads;
+ private int episodeCacheSize;
private boolean enableAutodownload;
- private boolean enableAutodownloadWifiFilter;
private boolean enableAutodownloadOnBattery;
+ private boolean enableAutodownloadWifiFilter;
private String[] autodownloadSelectedNetworks;
- private int parallelDownloads;
- private int episodeCacheSize;
+
+ // Services
+ private boolean autoFlattr;
+ private float autoFlattrPlayedDurationThreshold;
+
+ // Settings somewhere in the GUI
private String playbackSpeed;
- private String[] playbackSpeedArray;
- private boolean pauseForFocusLoss;
- private boolean resumeAfterCall;
private int fastForwardSecs;
private int rewindSecs;
- private boolean isFreshInstall;
- private int notifyPriority;
- private boolean persistNotify;
- private List<String> hiddenDrawerItems;
private boolean queueLocked;
+
private UserPreferences(Context context) {
this.context = context;
loadPreferences();
@@ -130,50 +153,53 @@ public class UserPreferences implements
}
private void loadPreferences() {
- SharedPreferences sp = PreferenceManager
- .getDefaultSharedPreferences(context);
- EPISODE_CACHE_SIZE_UNLIMITED = context.getResources().getInteger(
- R.integer.episode_cache_size_unlimited);
- pauseOnHeadsetDisconnect = sp.getBoolean(
- PREF_PAUSE_ON_HEADSET_DISCONNECT, true);
- unpauseOnHeadsetReconnect = sp.getBoolean(
- PREF_UNPAUSE_ON_HEADSET_RECONNECT, true);
+ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
+
+ // User Interface
+ theme = readThemeValue(sp.getString(PREF_THEME, "0"));
+ if (sp.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) {
+ notifyPriority = NotificationCompat.PRIORITY_MAX;
+ } else {
+ notifyPriority = NotificationCompat.PRIORITY_DEFAULT;
+ }
+ hiddenDrawerItems = Arrays.asList(StringUtils.split(sp.getString(PREF_HIDDEN_DRAWER_ITEMS, ""), ','));
+ persistNotify = sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, false);
+
+ // Queue
+ enqueueAtFront = sp.getBoolean(PREF_QUEUE_ADD_TO_FRONT, false);
+
+ // Playback
+ pauseOnHeadsetDisconnect = sp.getBoolean(PREF_PAUSE_ON_HEADSET_DISCONNECT, true);
+ unpauseOnHeadsetReconnect = sp.getBoolean(PREF_UNPAUSE_ON_HEADSET_RECONNECT, true);
followQueue = sp.getBoolean(PREF_FOLLOW_QUEUE, false);
- downloadMediaOnWifiOnly = sp.getBoolean(
- PREF_DOWNLOAD_MEDIA_ON_WIFI_ONLY, true);
- updateInterval = readUpdateInterval(sp.getString(PREF_UPDATE_INTERVAL,
- "0"));
- allowMobileUpdate = sp.getBoolean(PREF_MOBILE_UPDATE, false);
autoDelete = sp.getBoolean(PREF_AUTO_DELETE, false);
smartMarkAsPlayedSecs = Integer.valueOf(sp.getString(PREF_SMART_MARK_AS_PLAYED_SECS, "30"));
- autoFlattr = sp.getBoolean(PREF_AUTO_FLATTR, false);
- autoFlattrPlayedDurationThreshold = sp.getFloat(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD,
- PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT);
- theme = readThemeValue(sp.getString(PREF_THEME, "0"));
- enableAutodownloadWifiFilter = sp.getBoolean(
- PREF_ENABLE_AUTODL_WIFI_FILTER, false);
- autodownloadSelectedNetworks = StringUtils.split(
- sp.getString(PREF_AUTODL_SELECTED_NETWORKS, ""), ',');
+ playbackSpeedArray = readPlaybackSpeedArray(sp.getString(
+ PREF_PLAYBACK_SPEED_ARRAY, null));
+ pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false);
+
+ // Network
+ updateInterval = readUpdateInterval(sp.getString(PREF_UPDATE_INTERVAL, "0"));
+ allowMobileUpdate = sp.getBoolean(PREF_MOBILE_UPDATE, false);
parallelDownloads = Integer.valueOf(sp.getString(PREF_PARALLEL_DOWNLOADS, "6"));
- episodeCacheSize = readEpisodeCacheSizeInternal(sp.getString(
- PREF_EPISODE_CACHE_SIZE, "20"));
+ EPISODE_CACHE_SIZE_UNLIMITED = context.getResources().getInteger(
+ R.integer.episode_cache_size_unlimited);
+ episodeCacheSize = readEpisodeCacheSizeInternal(sp.getString(PREF_EPISODE_CACHE_SIZE, "20"));
enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false);
enableAutodownloadOnBattery = sp.getBoolean(PREF_ENABLE_AUTODL_ON_BATTERY, true);
+ enableAutodownloadWifiFilter = sp.getBoolean(PREF_ENABLE_AUTODL_WIFI_FILTER, false);
+ autodownloadSelectedNetworks = StringUtils.split(
+ sp.getString(PREF_AUTODL_SELECTED_NETWORKS, ""), ',');
+
+ // Services
+ autoFlattr = sp.getBoolean(PREF_AUTO_FLATTR, false);
+ autoFlattrPlayedDurationThreshold = sp.getFloat(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD,
+ PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT);
+
+ // MediaPlayer
playbackSpeed = sp.getString(PREF_PLAYBACK_SPEED, "1.0");
- playbackSpeedArray = readPlaybackSpeedArray(sp.getString(
- PREF_PLAYBACK_SPEED_ARRAY, null));
- pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false);
- resumeAfterCall = sp.getBoolean(PREF_RESUME_AFTER_CALL, true);
fastForwardSecs = sp.getInt(PREF_FAST_FORWARD_SECS, 30);
rewindSecs = sp.getInt(PREF_REWIND_SECS, 30);
- if (sp.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) {
- notifyPriority = NotificationCompat.PRIORITY_MAX;
- }
- else {
- notifyPriority = NotificationCompat.PRIORITY_DEFAULT;
- }
- persistNotify = sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, false);
- hiddenDrawerItems = Arrays.asList(StringUtils.split(sp.getString(PREF_HIDDEN_DRAWER_ITEMS, ""), ','));
queueLocked = sp.getBoolean(PREF_QUEUE_LOCKED, false);
}
@@ -224,8 +250,7 @@ public class UserPreferences implements
selectedSpeeds[i] = jsonArray.getString(i);
}
} catch (JSONException e) {
- Log.e(TAG,
- "Got JSON error when trying to get speeds from JSONArray");
+ Log.e(TAG, "Got JSON error when trying to get speeds from JSONArray");
e.printStackTrace();
}
}
@@ -234,107 +259,93 @@ public class UserPreferences implements
private static void instanceAvailable() {
if (instance == null) {
- throw new IllegalStateException(
- "UserPreferences was used before being set up");
+ throw new IllegalStateException("UserPreferences was used before being set up");
}
}
- public static boolean isPauseOnHeadsetDisconnect() {
- instanceAvailable();
- return instance.pauseOnHeadsetDisconnect;
- }
-
- public static boolean isUnpauseOnHeadsetReconnect() {
- instanceAvailable();
- return instance.unpauseOnHeadsetReconnect;
- }
-
- public static boolean isFollowQueue() {
- instanceAvailable();
- return instance.followQueue;
- }
-
- public static boolean isDownloadMediaOnWifiOnly() {
- instanceAvailable();
- return instance.downloadMediaOnWifiOnly;
- }
-
- public static long getUpdateInterval() {
- instanceAvailable();
- return instance.updateInterval;
- }
-
- public static boolean isAllowMobileUpdate() {
- instanceAvailable();
- return instance.allowMobileUpdate;
- }
-
- public static boolean isAutoDelete() {
+ /**
+ * Returns theme as R.style value
+ *
+ * @return R.style.Theme_AntennaPod_Light or R.style.Theme_AntennaPod_Dark
+ */
+ public static int getTheme() {
instanceAvailable();
- return instance.autoDelete;
+ return instance.theme;
}
- public static int getSmartMarkAsPlayedSecs() {
- instanceAvailable();;
- return instance.smartMarkAsPlayedSecs;
+ public static int getNoTitleTheme() {
+ int theme = getTheme();
+ if (theme == R.style.Theme_AntennaPod_Dark) {
+ return R.style.Theme_AntennaPod_Dark_NoTitle;
+ } else {
+ return R.style.Theme_AntennaPod_Light_NoTitle;
+ }
}
- public static boolean isAutoFlattr() {
+ public static List<String> getHiddenDrawerItems() {
instanceAvailable();
- return instance.autoFlattr;
+ return new ArrayList<String>(instance.hiddenDrawerItems);
}
+ /**
+ * Returns notification priority.
+ *
+ * @return NotificationCompat.PRIORITY_MAX or NotificationCompat.PRIORITY_DEFAULT
+ */
public static int getNotifyPriority() {
instanceAvailable();
return instance.notifyPriority;
}
+ /**
+ * Returns true if notifications are persistent
+ *
+ * @return {@code true} if notifications are persistent, {@code false} otherwise
+ */
public static boolean isPersistNotify() {
instanceAvailable();
return instance.persistNotify;
}
-
/**
- * Returns the time after which an episode should be auto-flattr'd in percent of the episode's
- * duration.
+ * Returns {@code true} if new queue elements are added to the front
+ *
+ * @return {@code true} if new queue elements are added to the front; {@code false} otherwise
*/
- public static float getAutoFlattrPlayedDurationThreshold() {
+ public static boolean enqueueAtFront() {
instanceAvailable();
- return instance.autoFlattrPlayedDurationThreshold;
+ return instance.enqueueAtFront;
}
- public static int getTheme() {
+ public static boolean isPauseOnHeadsetDisconnect() {
instanceAvailable();
- return instance.theme;
+ return instance.pauseOnHeadsetDisconnect;
}
- public static int getNoTitleTheme() {
- int theme = getTheme();
- if (theme == R.style.Theme_AntennaPod_Dark) {
- return R.style.Theme_AntennaPod_Dark_NoTitle;
- } else {
- return R.style.Theme_AntennaPod_Light_NoTitle;
- }
+ public static boolean isUnpauseOnHeadsetReconnect() {
+ instanceAvailable();
+ return instance.unpauseOnHeadsetReconnect;
}
- public static boolean isEnableAutodownloadWifiFilter() {
+
+ public static boolean isFollowQueue() {
instanceAvailable();
- return instance.enableAutodownloadWifiFilter;
+ return instance.followQueue;
}
- public static String[] getAutodownloadSelectedNetworks() {
+ public static boolean isAutoDelete() {
instanceAvailable();
- return instance.autodownloadSelectedNetworks;
+ return instance.autoDelete;
}
- public static int getParallelDownloads() {
+ public static int getSmartMarkAsPlayedSecs() {
instanceAvailable();
- return instance.parallelDownloads;
+ return instance.smartMarkAsPlayedSecs;
}
- public static int getEpisodeCacheSizeUnlimited() {
- return EPISODE_CACHE_SIZE_UNLIMITED;
+ public static boolean isAutoFlattr() {
+ instanceAvailable();
+ return instance.autoFlattr;
}
public static String getPlaybackSpeed() {
@@ -347,19 +358,28 @@ public class UserPreferences implements
return instance.playbackSpeedArray;
}
- public static int getFastFowardSecs() {
+ public static boolean shouldPauseForFocusLoss() {
instanceAvailable();
- return instance.fastForwardSecs;
+ return instance.pauseForFocusLoss;
}
- public static int getRewindSecs() {
+ public static long getUpdateInterval() {
instanceAvailable();
- return instance.rewindSecs;
+ return instance.updateInterval;
}
- public static List<String> getHiddenDrawerItems() {
+ public static boolean isAllowMobileUpdate() {
instanceAvailable();
- return new ArrayList<String>(instance.hiddenDrawerItems);
+ return instance.allowMobileUpdate;
+ }
+
+ public static int getParallelDownloads() {
+ instanceAvailable();
+ return instance.parallelDownloads;
+ }
+
+ public static int getEpisodeCacheSizeUnlimited() {
+ return EPISODE_CACHE_SIZE_UNLIMITED;
}
/**
@@ -382,19 +402,39 @@ public class UserPreferences implements
return instance.enableAutodownloadOnBattery;
}
- public static boolean shouldPauseForFocusLoss() {
+ public static boolean isEnableAutodownloadWifiFilter() {
instanceAvailable();
- return instance.pauseForFocusLoss;
+ return instance.enableAutodownloadWifiFilter;
}
- public static boolean shouldResumeAfterCall() {
+ public static int getFastFowardSecs() {
instanceAvailable();
- return instance.resumeAfterCall;
+ return instance.fastForwardSecs;
+ }
+
+ public static int getRewindSecs() {
+ instanceAvailable();
+ return instance.rewindSecs;
+ }
+
+
+ /**
+ * Returns the time after which an episode should be auto-flattr'd in percent of the episode's
+ * duration.
+ */
+ public static float getAutoFlattrPlayedDurationThreshold() {
+ instanceAvailable();
+ return instance.autoFlattrPlayedDurationThreshold;
+ }
+
+ public static String[] getAutodownloadSelectedNetworks() {
+ instanceAvailable();
+ return instance.autodownloadSelectedNetworks;
}
- public static boolean isFreshInstall() {
+ public static boolean shouldResumeAfterCall() {
instanceAvailable();
- return instance.isFreshInstall;
+ return instance.resumeAfterCall;
}
public static boolean isQueueLocked() {
@@ -405,77 +445,103 @@ public class UserPreferences implements
@Override
public void onSharedPreferenceChanged(SharedPreferences sp, String key) {
Log.d(TAG, "Registered change of user preferences. Key: " + key);
-
- if (key.equals(PREF_DOWNLOAD_MEDIA_ON_WIFI_ONLY)) {
- downloadMediaOnWifiOnly = sp.getBoolean(
- PREF_DOWNLOAD_MEDIA_ON_WIFI_ONLY, true);
-
- } else if (key.equals(PREF_MOBILE_UPDATE)) {
- allowMobileUpdate = sp.getBoolean(PREF_MOBILE_UPDATE, false);
-
- } else if (key.equals(PREF_FOLLOW_QUEUE)) {
- followQueue = sp.getBoolean(PREF_FOLLOW_QUEUE, false);
-
- } else if (key.equals(PREF_UPDATE_INTERVAL)) {
- updateInterval = readUpdateInterval(sp.getString(
- PREF_UPDATE_INTERVAL, "0"));
- ClientConfig.applicationCallbacks.setUpdateInterval(updateInterval);
- } else if (key.equals(PREF_AUTO_DELETE)) {
- autoDelete = sp.getBoolean(PREF_AUTO_DELETE, false);
- } else if (key.equals(PREF_SMART_MARK_AS_PLAYED_SECS)) {
- smartMarkAsPlayedSecs = Integer.valueOf(sp.getString(PREF_SMART_MARK_AS_PLAYED_SECS, "30"));
- } else if (key.equals(PREF_AUTO_FLATTR)) {
- autoFlattr = sp.getBoolean(PREF_AUTO_FLATTR, false);
- } else if (key.equals(PREF_THEME)) {
- theme = readThemeValue(sp.getString(PREF_THEME, ""));
- } else if (key.equals(PREF_ENABLE_AUTODL_WIFI_FILTER)) {
- enableAutodownloadWifiFilter = sp.getBoolean(
- PREF_ENABLE_AUTODL_WIFI_FILTER, false);
- } else if (key.equals(PREF_AUTODL_SELECTED_NETWORKS)) {
- autodownloadSelectedNetworks = StringUtils.split(
- sp.getString(PREF_AUTODL_SELECTED_NETWORKS, ""), ',');
- } else if(key.equals(PREF_PARALLEL_DOWNLOADS)) {
- parallelDownloads = Integer.valueOf(sp.getString(PREF_PARALLEL_DOWNLOADS, "6"));
- } else if (key.equals(PREF_EPISODE_CACHE_SIZE)) {
- episodeCacheSize = readEpisodeCacheSizeInternal(sp.getString(
- PREF_EPISODE_CACHE_SIZE, "20"));
- } else if (key.equals(PREF_ENABLE_AUTODL)) {
- enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false);
- } else if (key.equals(PREF_ENABLE_AUTODL_ON_BATTERY)) {
- enableAutodownloadOnBattery = sp.getBoolean(PREF_ENABLE_AUTODL_ON_BATTERY, true);
- } else if (key.equals(PREF_PLAYBACK_SPEED)) {
- playbackSpeed = sp.getString(PREF_PLAYBACK_SPEED, "1.0");
- } else if (key.equals(PREF_PLAYBACK_SPEED_ARRAY)) {
- playbackSpeedArray = readPlaybackSpeedArray(sp.getString(
- PREF_PLAYBACK_SPEED_ARRAY, null));
- } else if (key.equals(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS)) {
- pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false);
- } else if (key.equals(PREF_RESUME_AFTER_CALL)) {
- resumeAfterCall = sp.getBoolean(PREF_RESUME_AFTER_CALL, true);
- } else if (key.equals(PREF_FAST_FORWARD_SECS)) {
- fastForwardSecs = sp.getInt(PREF_FAST_FORWARD_SECS, 30);
- } else if (key.equals(PREF_REWIND_SECS)) {
- rewindSecs = sp.getInt(PREF_REWIND_SECS, 30);
- } else if (key.equals(PREF_PAUSE_ON_HEADSET_DISCONNECT)) {
- pauseOnHeadsetDisconnect = sp.getBoolean(PREF_PAUSE_ON_HEADSET_DISCONNECT, true);
- } else if (key.equals(PREF_UNPAUSE_ON_HEADSET_RECONNECT)) {
- unpauseOnHeadsetReconnect = sp.getBoolean(PREF_UNPAUSE_ON_HEADSET_RECONNECT, true);
- } else if (key.equals(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD)) {
- autoFlattrPlayedDurationThreshold = sp.getFloat(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD,
- PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT);
- } else if (key.equals(PREF_EXPANDED_NOTIFICATION)) {
- if (sp.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) {
- notifyPriority = NotificationCompat.PRIORITY_MAX;
- }
- else {
- notifyPriority = NotificationCompat.PRIORITY_DEFAULT;
- }
- } else if (key.equals(PREF_PERSISTENT_NOTIFICATION)) {
- persistNotify = sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, false);
- } else if (key.equals(PREF_HIDDEN_DRAWER_ITEMS)) {
- hiddenDrawerItems = Arrays.asList(StringUtils.split(sp.getString(PREF_HIDDEN_DRAWER_ITEMS, ""), ','));
- } else if(key.equals(PREF_QUEUE_LOCKED)) {
- queueLocked = sp.getBoolean(PREF_QUEUE_LOCKED, false);
+ switch(key) {
+ // User Interface
+ case PREF_THEME:
+ theme = readThemeValue(sp.getString(PREF_THEME, ""));
+ break;
+ case PREF_HIDDEN_DRAWER_ITEMS:
+ hiddenDrawerItems = Arrays.asList(StringUtils.split(sp.getString(PREF_HIDDEN_DRAWER_ITEMS, ""), ','));
+ break;
+ case PREF_EXPANDED_NOTIFICATION:
+ if (sp.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) {
+ notifyPriority = NotificationCompat.PRIORITY_MAX;
+ } else {
+ notifyPriority = NotificationCompat.PRIORITY_DEFAULT;
+ }
+ break;
+ case PREF_PERSISTENT_NOTIFICATION:
+ persistNotify = sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, false);
+ break;
+ // Queue
+ case PREF_QUEUE_ADD_TO_FRONT:
+ enqueueAtFront = sp.getBoolean(PREF_QUEUE_ADD_TO_FRONT, false);
+ break;
+ // Playback
+ case PREF_PAUSE_ON_HEADSET_DISCONNECT:
+ pauseOnHeadsetDisconnect = sp.getBoolean(PREF_PAUSE_ON_HEADSET_DISCONNECT, true);
+ break;
+ case PREF_UNPAUSE_ON_HEADSET_RECONNECT:
+ unpauseOnHeadsetReconnect = sp.getBoolean(PREF_UNPAUSE_ON_HEADSET_RECONNECT, true);
+ break;
+ case PREF_FOLLOW_QUEUE:
+ followQueue = sp.getBoolean(PREF_FOLLOW_QUEUE, false);
+ break;
+ case PREF_AUTO_DELETE:
+ autoDelete = sp.getBoolean(PREF_AUTO_DELETE, false);
+ break;
+ case PREF_SMART_MARK_AS_PLAYED_SECS:
+ smartMarkAsPlayedSecs = Integer.valueOf(sp.getString(PREF_SMART_MARK_AS_PLAYED_SECS, "30"));
+ break;
+ case PREF_PLAYBACK_SPEED_ARRAY:
+ playbackSpeedArray = readPlaybackSpeedArray(sp.getString(PREF_PLAYBACK_SPEED_ARRAY, null));
+ break;
+ case PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS:
+ pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false);
+ break;
+ case PREF_RESUME_AFTER_CALL:
+ resumeAfterCall = sp.getBoolean(PREF_RESUME_AFTER_CALL, true);
+ break;
+ // Network
+ case PREF_UPDATE_INTERVAL:
+ updateInterval = readUpdateInterval(sp.getString(PREF_UPDATE_INTERVAL, "0"));
+ ClientConfig.applicationCallbacks.setUpdateInterval(updateInterval);
+ break;
+ case PREF_MOBILE_UPDATE:
+ allowMobileUpdate = sp.getBoolean(PREF_MOBILE_UPDATE, false);
+ break;
+ case PREF_PARALLEL_DOWNLOADS:
+ parallelDownloads = Integer.valueOf(sp.getString(PREF_PARALLEL_DOWNLOADS, "6"));
+ break;
+ case PREF_EPISODE_CACHE_SIZE:
+ episodeCacheSize = readEpisodeCacheSizeInternal(sp.getString(PREF_EPISODE_CACHE_SIZE, "20"));
+ break;
+ case PREF_ENABLE_AUTODL:
+ enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false);
+ break;
+ case PREF_ENABLE_AUTODL_ON_BATTERY:
+ enableAutodownloadOnBattery = sp.getBoolean(PREF_ENABLE_AUTODL_ON_BATTERY, true);
+ break;
+ case PREF_ENABLE_AUTODL_WIFI_FILTER:
+ enableAutodownloadWifiFilter = sp.getBoolean(PREF_ENABLE_AUTODL_WIFI_FILTER, false);
+ break;
+ case PREF_AUTODL_SELECTED_NETWORKS:
+ autodownloadSelectedNetworks = StringUtils.split(
+ sp.getString(PREF_AUTODL_SELECTED_NETWORKS, ""), ',');
+ break;
+ // Services
+ case PREF_AUTO_FLATTR:
+ autoFlattr = sp.getBoolean(PREF_AUTO_FLATTR, false);
+ break;
+ case PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD:
+ autoFlattrPlayedDurationThreshold = sp.getFloat(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD,
+ PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT);
+ break;
+ // Mediaplayer
+ case PREF_PLAYBACK_SPEED:
+ playbackSpeed = sp.getString(PREF_PLAYBACK_SPEED, "1.0");
+ break;
+ case PREF_FAST_FORWARD_SECS:
+ fastForwardSecs = sp.getInt(PREF_FAST_FORWARD_SECS, 30);
+ break;
+ case PREF_REWIND_SECS:
+ rewindSecs = sp.getInt(PREF_REWIND_SECS, 30);
+ break;
+ case PREF_QUEUE_LOCKED:
+ queueLocked = sp.getBoolean(PREF_QUEUE_LOCKED, false);
+ break;
+ default:
+ Log.w(TAG, "Unhandled key: " + key);
}
}
@@ -625,7 +691,6 @@ public class UserPreferences implements
}
return typeDir;
}
-
}
}
@@ -653,8 +718,7 @@ public class UserPreferences implements
Log.e(TAG, "Could not create .nomedia file");
e.printStackTrace();
}
- if (BuildConfig.DEBUG)
- Log.d(TAG, ".nomedia file created");
+ Log.d(TAG, ".nomedia file created");
}
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
index 7a631a62b..b9a61e62b 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
@@ -418,8 +418,7 @@ public class DBWriter {
if (item != null) {
// add item to either front ot back of queue
- boolean addToFront = PreferenceManager.getDefaultSharedPreferences(context)
- .getBoolean(UserPreferences.PREF_QUEUE_ADD_TO_FRONT, false);
+ boolean addToFront = UserPreferences.enqueueAtFront();
if(addToFront){
queue.add(0, item);
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java
index fa41fb664..b6df2dc85 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java
@@ -13,45 +13,14 @@ import java.util.Locale;
* Parses several date formats.
*/
public class DateUtils {
- private static final String TAG = "DateUtils";
+
+ private static final String TAG = "DateUtils";
- private static final String[] RFC822DATES = {"dd MMM yy HH:mm:ss Z",
- "dd MMM yy HH:mm Z"};
-
- /**
- * RFC 3339 date format for UTC dates.
- */
- public static final String RFC3339UTC = "yyyy-MM-dd'T'HH:mm:ss'Z'";
-
- /**
- * RFC 3339 date format for localtime dates with offset.
- */
- public static final String RFC3339LOCAL = "yyyy-MM-dd'T'HH:mm:ssZ";
-
- public static final String ISO8601_SHORT = "yyyy-MM-dd";
-
- private static ThreadLocal<SimpleDateFormat> RFC822Formatter = new ThreadLocal<SimpleDateFormat>() {
- @Override
- protected SimpleDateFormat initialValue() {
- return new SimpleDateFormat("dd MMM yy HH:mm:ss Z", Locale.US);
- }
-
- };
-
- private static ThreadLocal<SimpleDateFormat> RFC3339Formatter = new ThreadLocal<SimpleDateFormat>() {
- @Override
- protected SimpleDateFormat initialValue() {
- return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
- }
-
- };
-
- public static Date parse(String date) {
- if(date == null) {
+ public static Date parse(final String input) {
+ if(input == null) {
throw new IllegalArgumentException("Date most not be null");
}
- date = date.replace('/', ' ');
- date = date.replace('-', ' ');
+ String date = input.replace('/', '-');
if(date.contains(".")) {
int start = date.indexOf('.');
int current = start+1;
@@ -77,15 +46,16 @@ public class DateUtils {
"dd MMM yy HH:mm:ss Z",
"dd MMM yy HH:mm Z",
"EEE, dd MMM yyyy HH:mm:ss Z",
+ "EEE, dd MMMM yyyy HH:mm:ss Z",
"EEEE, dd MMM yy HH:mm:ss Z",
"EEE MMM d HH:mm:ss yyyy",
- "yyyy MM dd'T'HH:mm:ss",
- "yyyy MM dd'T'HH:mm:ss.SSS",
- "yyyy MM dd'T'HH:mm:ss.SSS Z",
- "yyyy MM dd'T'HH:mm:ssZ",
- "yyyy MM dd'T'HH:mm:ss'Z'",
- "yyyy MM ddZ",
- "yyyy MM dd"
+ "yyyy-MM-dd'T'HH:mm:ss",
+ "yyyy-MM-dd'T'HH:mm:ss.SSS",
+ "yyyy-MM-dd'T'HH:mm:ss.SSS Z",
+ "yyyy-MM-dd'T'HH:mm:ssZ",
+ "yyyy-MM-dd'T'HH:mm:ss'Z'",
+ "yyyy-MM-ddZ",
+ "yyyy-MM-dd"
};
SimpleDateFormat parser = new SimpleDateFormat("", Locale.US);
parser.setLenient(false);
@@ -98,7 +68,8 @@ public class DateUtils {
return result;
}
}
- Log.d(TAG, "Could not parse '" + date + "'");
+
+ Log.d(TAG, "Could not parse date string \"" + input + "\"");
return null;
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrUtils.java
index 90caad946..50792ae26 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrUtils.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrUtils.java
@@ -26,7 +26,6 @@ import java.util.EnumSet;
import java.util.List;
import java.util.TimeZone;
-import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.asynctask.FlattrTokenFetcher;
@@ -65,18 +64,15 @@ public class FlattrUtils {
private static AccessToken retrieveToken() {
if (cachedToken == null) {
- if (BuildConfig.DEBUG)
- Log.d(TAG, "Retrieving access token");
+ Log.d(TAG, "Retrieving access token");
String token = PreferenceManager.getDefaultSharedPreferences(
ClientConfig.applicationCallbacks.getApplicationInstance())
.getString(PREF_ACCESS_TOKEN, null);
if (token != null) {
- if (BuildConfig.DEBUG)
- Log.d(TAG, "Found access token. Caching.");
+ Log.d(TAG, "Found access token. Caching.");
cachedToken = new AccessToken(token);
} else {
- if (BuildConfig.DEBUG)
- Log.d(TAG, "No access token found");
+ Log.d(TAG, "No access token found");
return null;
}
}
@@ -97,8 +93,7 @@ public class FlattrUtils {
}
public static void storeToken(AccessToken token) {
- if (BuildConfig.DEBUG)
- Log.d(TAG, "Storing token");
+ Log.d(TAG, "Storing token");
SharedPreferences.Editor editor = PreferenceManager
.getDefaultSharedPreferences(ClientConfig.applicationCallbacks.getApplicationInstance()).edit();
if (token != null) {
@@ -111,8 +106,7 @@ public class FlattrUtils {
}
public static void deleteToken() {
- if (BuildConfig.DEBUG)
- Log.d(TAG, "Deleting flattr token");
+ Log.d(TAG, "Deleting flattr token");
storeToken(null);
}
@@ -169,15 +163,11 @@ public class FlattrUtils {
}
}
- if (BuildConfig.DEBUG) {
- Log.d(TAG, "Got my flattrs list of length " + Integer.toString(myFlattrs.size()) + " comparison date" + firstOfMonthDate);
-
- for (Flattr fl : myFlattrs) {
- Thing thing = fl.getThing();
- Log.d(TAG, "Flattr thing: " + fl.getThingId() + " name: " + thing.getTitle() + " url: " + thing.getUrl() + " on: " + fl.getCreated());
- }
+ Log.d(TAG, "Got my flattrs list of length " + Integer.toString(myFlattrs.size()) + " comparison date" + firstOfMonthDate);
+ for (Flattr fl : myFlattrs) {
+ Thing thing = fl.getThing();
+ Log.d(TAG, "Flattr thing: " + fl.getThingId() + " name: " + thing.getTitle() + " url: " + thing.getUrl() + " on: " + fl.getCreated());
}
-
} else {
Log.e(TAG, "retrieveFlattrdThings was called with null access token");
}
@@ -191,8 +181,7 @@ public class FlattrUtils {
}
public static void revokeAccessToken(Context context) {
- if (BuildConfig.DEBUG)
- Log.d(TAG, "Revoking access token");
+ Log.d(TAG, "Revoking access token");
deleteToken();
FlattrServiceCreator.deleteFlattrService();
showRevokeDialog(context);
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/gui/UndoBarController.java b/core/src/main/java/de/danoeh/antennapod/core/util/gui/UndoBarController.java
index 23d8cf7c7..26c712af3 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/gui/UndoBarController.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/gui/UndoBarController.java
@@ -88,7 +88,8 @@ public class UndoBarController<T> {
}
public void close() {
- mHideHandler.post(mHideRunnable);
+ hideUndoBar(true);
+ mUndoListener.onHide(mUndoToken);
}
public void hideUndoBar(boolean immediate) {