summaryrefslogtreecommitdiff
path: root/storage
diff options
context:
space:
mode:
Diffstat (limited to 'storage')
-rw-r--r--storage/database/build.gradle4
-rw-r--r--storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBUpgrader.java4
-rw-r--r--storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java103
-rw-r--r--storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemSortQuery.java34
-rw-r--r--storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedPreferencesCursorMapper.java7
-rw-r--r--storage/preferences/build.gradle2
-rw-r--r--storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java177
7 files changed, 145 insertions, 186 deletions
diff --git a/storage/database/build.gradle b/storage/database/build.gradle
index 141cdb086..0dc5cef63 100644
--- a/storage/database/build.gradle
+++ b/storage/database/build.gradle
@@ -4,8 +4,8 @@ plugins {
apply from: "../../common.gradle"
android {
- lintOptions {
- disable "StaticFieldLeak"
+ lint {
+ disable "StaticFieldLeak", "StringFormatCount", "StringFormatMatches", "StringFormatInvalid", "PluralsCandidate", "StringFormatTrivial"
}
}
diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBUpgrader.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBUpgrader.java
index 78eaf6964..e4a1f5a3d 100644
--- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBUpgrader.java
+++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBUpgrader.java
@@ -330,6 +330,10 @@ class DBUpgrader {
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS
+ " ADD COLUMN " + PodDBAdapter.KEY_PODCASTINDEX_CHAPTER_URL + " TEXT");
}
+ if (oldVersion < 3010000) {
+ db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
+ + " ADD COLUMN " + PodDBAdapter.KEY_NEW_EPISODES_ACTION + " INTEGER DEFAULT 0");
+ }
}
}
diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java
index 35064b605..40933e8d1 100644
--- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java
+++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java
@@ -38,6 +38,8 @@ import de.danoeh.antennapod.model.feed.FeedPreferences;
import de.danoeh.antennapod.model.download.DownloadStatus;
import de.danoeh.antennapod.model.feed.SortOrder;
import de.danoeh.antennapod.storage.database.mapper.FeedItemFilterQuery;
+import de.danoeh.antennapod.storage.database.mapper.FeedItemSortQuery;
+
import org.apache.commons.io.FileUtils;
import static de.danoeh.antennapod.model.feed.FeedPreferences.SPEED_USE_GLOBAL;
@@ -50,7 +52,7 @@ public class PodDBAdapter {
private static final String TAG = "PodDBAdapter";
public static final String DATABASE_NAME = "Antennapod.db";
- public static final int VERSION = 2060000;
+ public static final int VERSION = 3010000;
/**
* Maximum number of arguments for IN-operator.
@@ -116,6 +118,7 @@ public class PodDBAdapter {
public static final String KEY_FEED_SKIP_ENDING = "feed_skip_ending";
public static final String KEY_FEED_TAGS = "tags";
public static final String KEY_EPISODE_NOTIFICATION = "episode_notification";
+ public static final String KEY_NEW_EPISODES_ACTION = "new_episodes_action";
public static final String KEY_PODCASTINDEX_CHAPTER_URL = "podcastindex_chapter_url";
// Table names
@@ -157,7 +160,8 @@ public class PodDBAdapter {
+ KEY_FEED_TAGS + " TEXT,"
+ KEY_FEED_SKIP_INTRO + " INTEGER DEFAULT 0,"
+ KEY_FEED_SKIP_ENDING + " INTEGER DEFAULT 0,"
- + KEY_EPISODE_NOTIFICATION + " INTEGER DEFAULT 0)";
+ + KEY_EPISODE_NOTIFICATION + " INTEGER DEFAULT 0,"
+ + KEY_NEW_EPISODES_ACTION + " INTEGER DEFAULT 0)";
private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
+ TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY
@@ -307,7 +311,8 @@ public class PodDBAdapter {
+ TABLE_NAME_FEEDS + "." + KEY_FEED_TAGS + ", "
+ TABLE_NAME_FEEDS + "." + KEY_FEED_SKIP_INTRO + ", "
+ TABLE_NAME_FEEDS + "." + KEY_FEED_SKIP_ENDING + ", "
- + TABLE_NAME_FEEDS + "." + KEY_EPISODE_NOTIFICATION;
+ + TABLE_NAME_FEEDS + "." + KEY_EPISODE_NOTIFICATION + ", "
+ + TABLE_NAME_FEEDS + "." + KEY_NEW_EPISODES_ACTION;
private static final String JOIN_FEED_ITEM_AND_MEDIA = " LEFT JOIN " + TABLE_NAME_FEED_MEDIA
+ " ON " + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + "=" + TABLE_NAME_FEED_MEDIA + "." + KEY_FEEDITEM + " ";
@@ -444,7 +449,7 @@ public class PodDBAdapter {
ContentValues values = new ContentValues();
values.put(KEY_AUTO_DOWNLOAD_ENABLED, prefs.getAutoDownload());
values.put(KEY_KEEP_UPDATED, prefs.getKeepUpdated());
- values.put(KEY_AUTO_DELETE_ACTION, prefs.getAutoDeleteAction().ordinal());
+ values.put(KEY_AUTO_DELETE_ACTION, prefs.getAutoDeleteAction().code);
values.put(KEY_FEED_VOLUME_ADAPTION, prefs.getVolumeAdaptionSetting().toInteger());
values.put(KEY_USERNAME, prefs.getUsername());
values.put(KEY_PASSWORD, prefs.getPassword());
@@ -456,6 +461,7 @@ public class PodDBAdapter {
values.put(KEY_FEED_SKIP_INTRO, prefs.getFeedSkipIntro());
values.put(KEY_FEED_SKIP_ENDING, prefs.getFeedSkipEnding());
values.put(KEY_EPISODE_NOTIFICATION, prefs.getShowEpisodeNotification());
+ values.put(KEY_NEW_EPISODES_ACTION, prefs.getNewEpisodesAction().code);
db.update(TABLE_NAME_FEEDS, values, KEY_ID + "=?", new String[]{String.valueOf(prefs.getFeedID())});
}
@@ -728,6 +734,13 @@ public class PodDBAdapter {
}
}
+ public void resetPagedFeedPage(Feed feed) {
+ final String sql = "UPDATE " + TABLE_NAME_FEEDS
+ + " SET " + KEY_NEXT_PAGE_LINK + "=" + KEY_DOWNLOAD_URL
+ + " WHERE " + KEY_ID + "=" + feed.getId();
+ db.execSQL(sql);
+ }
+
public void setFeedLastUpdateFailed(long feedId, boolean failed) {
final String sql = "UPDATE " + TABLE_NAME_FEEDS
+ " SET " + KEY_LAST_UPDATE_FAILED + "=" + (failed ? "1" : "0")
@@ -1041,27 +1054,20 @@ public class PodDBAdapter {
db.execSQL(sql);
}
- /**
- * Returns a cursor which contains all feed items that are considered new.
- * Excludes those feeds that do not have 'Keep Updated' enabled.
- * The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection.
- */
- public final Cursor getNewItemsCursor(int offset, int limit) {
- final String query = SELECT_FEED_ITEMS_AND_MEDIA
- + " INNER JOIN " + TABLE_NAME_FEEDS
- + " ON " + TABLE_NAME_FEED_ITEMS + "." + KEY_FEED + "=" + TABLE_NAME_FEEDS + "." + KEY_ID
- + " WHERE " + TABLE_NAME_FEED_ITEMS + "." + KEY_READ + "=" + FeedItem.NEW
- + " AND " + TABLE_NAME_FEEDS + "." + KEY_KEEP_UPDATED + " > 0"
- + " ORDER BY " + TABLE_NAME_FEED_ITEMS + "." + KEY_PUBDATE + " DESC"
- + " LIMIT " + offset + ", " + limit;
+ public final Cursor getEpisodesCursor(int offset, int limit, FeedItemFilter filter, SortOrder sortOrder) {
+ String orderByQuery = FeedItemSortQuery.generateFrom(sortOrder);
+ String filterQuery = FeedItemFilterQuery.generateFrom(filter);
+ String whereClause = "".equals(filterQuery) ? "" : " WHERE " + filterQuery;
+ final String query = SELECT_FEED_ITEMS_AND_MEDIA + whereClause
+ + "ORDER BY " + orderByQuery + " LIMIT " + offset + ", " + limit;
return db.rawQuery(query, null);
}
- public final Cursor getRecentlyPublishedItemsCursor(int offset, int limit, FeedItemFilter filter) {
+ public final Cursor getEpisodeCountCursor(FeedItemFilter filter) {
String filterQuery = FeedItemFilterQuery.generateFrom(filter);
String whereClause = "".equals(filterQuery) ? "" : " WHERE " + filterQuery;
- final String query = SELECT_FEED_ITEMS_AND_MEDIA + whereClause
- + " ORDER BY " + KEY_PUBDATE + " DESC LIMIT " + offset + ", " + limit;
+ final String query = "SELECT count(" + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + ") FROM " + TABLE_NAME_FEED_ITEMS
+ + JOIN_FEED_ITEM_AND_MEDIA + whereClause;
return db.rawQuery(query, null);
}
@@ -1087,26 +1093,6 @@ public class PodDBAdapter {
return "((" + SELECT_KEY_ITEM_ID + " * " + seed + ") % 46471)";
}
- public final Cursor getTotalEpisodeCountCursor(FeedItemFilter filter) {
- String filterQuery = FeedItemFilterQuery.generateFrom(filter);
- String whereClause = "".equals(filterQuery) ? "" : " WHERE " + filterQuery;
- final String query = "SELECT count(" + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + ") FROM " + TABLE_NAME_FEED_ITEMS
- + JOIN_FEED_ITEM_AND_MEDIA + whereClause;
- return db.rawQuery(query, null);
- }
-
- public Cursor getDownloadedItemsCursor() {
- final String query = SELECT_FEED_ITEMS_AND_MEDIA
- + "WHERE " + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOADED + " > 0";
- return db.rawQuery(query, null);
- }
-
- public Cursor getPlayedItemsCursor() {
- final String query = SELECT_FEED_ITEMS_AND_MEDIA
- + "WHERE " + TABLE_NAME_FEED_ITEMS + "." + KEY_READ + "=" + FeedItem.PLAYED;
- return db.rawQuery(query, null);
- }
-
/**
* Returns a cursor which contains feed media objects with a playback
* completion date in ascending order.
@@ -1214,7 +1200,7 @@ public class PodDBAdapter {
+ TABLE_NAME_FEED_MEDIA + "." + KEY_POSITION + "> 0";
}
final String timeFilter = lastPlayedTime + ">=" + timeFilterFrom
- + " AND " + lastPlayedTime + "<=" + timeFilterTo;
+ + " AND " + lastPlayedTime + "<" + timeFilterTo;
String playedTime = TABLE_NAME_FEED_MEDIA + "." + KEY_PLAYED_DURATION;
if (includeMarkedAsPlayed) {
playedTime = "(CASE WHEN " + playedTime + " != 0"
@@ -1255,25 +1241,6 @@ public class PodDBAdapter {
return result;
}
- public final int getNumberOfNewItems() {
- Object[] args = new String[]{
- TABLE_NAME_FEED_ITEMS + "." + KEY_ID,
- TABLE_NAME_FEED_ITEMS,
- TABLE_NAME_FEEDS,
- TABLE_NAME_FEED_ITEMS + "." + KEY_FEED + "=" + TABLE_NAME_FEEDS + "." + KEY_ID,
- TABLE_NAME_FEED_ITEMS + "." + KEY_READ + "=" + FeedItem.NEW
- + " AND " + TABLE_NAME_FEEDS + "." + KEY_KEEP_UPDATED + " > 0"
- };
- final String query = String.format("SELECT COUNT(%s) FROM %s INNER JOIN %s ON %s WHERE %s", args);
- Cursor c = db.rawQuery(query, null);
- int result = 0;
- if (c.moveToFirst()) {
- result = c.getInt(0);
- }
- c.close();
- return result;
- }
-
public final Map<Long, Integer> getFeedCounters(FeedCounter setting, long... feedIds) {
String whereRead;
switch (setting) {
@@ -1359,19 +1326,6 @@ public class PodDBAdapter {
return result;
}
- public final int getNumberOfDownloadedEpisodes() {
- final String query = "SELECT COUNT(DISTINCT " + KEY_ID + ") AS count FROM " + TABLE_NAME_FEED_MEDIA +
- " WHERE " + KEY_DOWNLOADED + " > 0";
-
- Cursor c = db.rawQuery(query, null);
- int result = 0;
- if (c.moveToFirst()) {
- result = c.getInt(0);
- }
- c.close();
- return result;
- }
-
/**
* Uses DatabaseUtils to escape a search query and removes ' at the
* beginning and the end of the string returned by the escape method.
@@ -1530,6 +1484,9 @@ public class PodDBAdapter {
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
Log.w("DBAdapter", "Upgrading from version " + oldVersion + " to " + newVersion + ".");
DBUpgrader.upgrade(db, oldVersion, newVersion);
+
+ db.execSQL("DELETE FROM " + PodDBAdapter.TABLE_NAME_DOWNLOAD_LOG + " WHERE "
+ + PodDBAdapter.KEY_COMPLETION_DATE + "<" + (System.currentTimeMillis() - 7L * 24L * 3600L * 1000L));
}
}
}
diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemSortQuery.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemSortQuery.java
new file mode 100644
index 000000000..aae5154d3
--- /dev/null
+++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemSortQuery.java
@@ -0,0 +1,34 @@
+package de.danoeh.antennapod.storage.database.mapper;
+
+import de.danoeh.antennapod.model.feed.SortOrder;
+import de.danoeh.antennapod.storage.database.PodDBAdapter;
+
+public class FeedItemSortQuery {
+ public static String generateFrom(SortOrder sortOrder) {
+ String sortQuery = "";
+ switch (sortOrder) {
+ case EPISODE_TITLE_A_Z:
+ sortQuery = PodDBAdapter.TABLE_NAME_FEED_ITEMS + "." + PodDBAdapter.KEY_TITLE + " " + "ASC";
+ break;
+ case EPISODE_TITLE_Z_A:
+ sortQuery = PodDBAdapter.TABLE_NAME_FEED_ITEMS + "." + PodDBAdapter.KEY_TITLE + " " + "DESC";
+ break;
+ case DATE_OLD_NEW:
+ sortQuery = PodDBAdapter.TABLE_NAME_FEED_ITEMS + "." + PodDBAdapter.KEY_PUBDATE + " " + "ASC";
+ break;
+ case DATE_NEW_OLD:
+ sortQuery = PodDBAdapter.TABLE_NAME_FEED_ITEMS + "." + PodDBAdapter.KEY_PUBDATE + " " + "DESC";
+ break;
+ case DURATION_SHORT_LONG:
+ sortQuery = PodDBAdapter.TABLE_NAME_FEED_MEDIA + "." + PodDBAdapter.KEY_DURATION + " " + "ASC";
+ break;
+ case DURATION_LONG_SHORT:
+ sortQuery = PodDBAdapter.TABLE_NAME_FEED_MEDIA + "." + PodDBAdapter.KEY_DURATION + " " + "DESC";
+ break;
+ default:
+ sortQuery = "";
+ break;
+ }
+ return sortQuery;
+ }
+} \ No newline at end of file
diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedPreferencesCursorMapper.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedPreferencesCursorMapper.java
index 289bcbab8..2de100dff 100644
--- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedPreferencesCursorMapper.java
+++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedPreferencesCursorMapper.java
@@ -34,14 +34,14 @@ public abstract class FeedPreferencesCursorMapper {
int indexAutoSkipIntro = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED_SKIP_INTRO);
int indexAutoSkipEnding = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED_SKIP_ENDING);
int indexEpisodeNotification = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_EPISODE_NOTIFICATION);
+ int indexNewEpisodesAction = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_NEW_EPISODES_ACTION);
int indexTags = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED_TAGS);
long feedId = cursor.getLong(indexId);
boolean autoDownload = cursor.getInt(indexAutoDownload) > 0;
boolean autoRefresh = cursor.getInt(indexAutoRefresh) > 0;
- int autoDeleteActionIndex = cursor.getInt(indexAutoDeleteAction);
FeedPreferences.AutoDeleteAction autoDeleteAction =
- FeedPreferences.AutoDeleteAction.values()[autoDeleteActionIndex];
+ FeedPreferences.AutoDeleteAction.fromCode(cursor.getInt(indexAutoDeleteAction));
int volumeAdaptionValue = cursor.getInt(indexVolumeAdaption);
VolumeAdaptionSetting volumeAdaptionSetting = VolumeAdaptionSetting.fromInteger(volumeAdaptionValue);
String username = cursor.getString(indexUsername);
@@ -52,6 +52,8 @@ public abstract class FeedPreferencesCursorMapper {
float feedPlaybackSpeed = cursor.getFloat(indexFeedPlaybackSpeed);
int feedAutoSkipIntro = cursor.getInt(indexAutoSkipIntro);
int feedAutoSkipEnding = cursor.getInt(indexAutoSkipEnding);
+ FeedPreferences.NewEpisodesAction feedNewEpisodesAction =
+ FeedPreferences.NewEpisodesAction.fromCode(cursor.getInt(indexNewEpisodesAction));
boolean showNotification = cursor.getInt(indexEpisodeNotification) > 0;
String tagsString = cursor.getString(indexTags);
if (TextUtils.isEmpty(tagsString)) {
@@ -69,6 +71,7 @@ public abstract class FeedPreferencesCursorMapper {
feedAutoSkipIntro,
feedAutoSkipEnding,
showNotification,
+ feedNewEpisodesAction,
new HashSet<>(Arrays.asList(tagsString.split(FeedPreferences.TAG_SEPARATOR))));
}
}
diff --git a/storage/preferences/build.gradle b/storage/preferences/build.gradle
index 0c852bf7a..0da810e28 100644
--- a/storage/preferences/build.gradle
+++ b/storage/preferences/build.gradle
@@ -4,7 +4,7 @@ plugins {
apply from: "../../common.gradle"
android {
- lintOptions {
+ lint {
disable "StaticFieldLeak"
}
}
diff --git a/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java b/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java
index 14fb94018..8a19300bb 100644
--- a/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java
+++ b/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java
@@ -6,13 +6,17 @@ import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
-
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.app.NotificationCompat;
import androidx.preference.PreferenceManager;
-
+import de.danoeh.antennapod.model.download.ProxyConfig;
+import de.danoeh.antennapod.model.feed.FeedCounter;
+import de.danoeh.antennapod.model.feed.FeedPreferences;
+import de.danoeh.antennapod.model.feed.SortOrder;
+import de.danoeh.antennapod.model.feed.SubscriptionsFilter;
+import de.danoeh.antennapod.model.playback.MediaType;
import org.json.JSONArray;
import org.json.JSONException;
@@ -27,13 +31,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-import de.danoeh.antennapod.model.feed.FeedCounter;
-import de.danoeh.antennapod.model.playback.MediaType;
-import de.danoeh.antennapod.model.feed.SubscriptionsFilter;
-import de.danoeh.antennapod.model.download.ProxyConfig;
-import de.danoeh.antennapod.model.feed.SortOrder;
/**
* Provides access to preferences set by the user in the settings screen. A
@@ -48,6 +45,7 @@ public class UserPreferences {
// User Interface
public static final String PREF_THEME = "prefTheme";
+ public static final String PREF_THEME_BLACK = "prefThemeBlack";
public static final String PREF_TINTED_COLORS = "prefTintedColors";
public static final String PREF_HIDDEN_DRAWER_ITEMS = "prefHiddenDrawerItems";
public static final String PREF_DRAWER_FEED_ORDER = "prefDrawerFeedOrder";
@@ -57,7 +55,6 @@ public class UserPreferences {
public static final String PREF_SHOW_TIME_LEFT = "showTimeLeft";
private static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify";
public static final String PREF_COMPACT_NOTIFICATION_BUTTONS = "prefCompactNotificationButtons";
- public static final String PREF_LOCKSCREEN_BACKGROUND = "prefLockscreenBackground";
private static final String PREF_SHOW_DOWNLOAD_REPORT = "prefShowDownloadReport";
private static final String PREF_SHOW_AUTO_DOWNLOAD_REPORT = "prefShowAutoDownloadReport";
public static final String PREF_DEFAULT_PAGE = "prefDefaultPage";
@@ -67,6 +64,9 @@ public class UserPreferences {
public static final String PREF_QUEUE_KEEP_SORTED = "prefQueueKeepSorted";
public static final String PREF_QUEUE_KEEP_SORTED_ORDER = "prefQueueKeepSortedOrder";
+ public static final String PREF_NEW_EPISODES_ACTION = "prefNewEpisodesAction";
+ private static final String PREF_DOWNLOADS_SORTED_ORDER = "prefDownloadSortedOrder";
+ private static final String PREF_INBOX_SORTED_ORDER = "prefInboxSortedOrder";
// Playback
public static final String PREF_PAUSE_ON_HEADSET_DISCONNECT = "prefPauseOnHeadsetDisconnect";
@@ -108,11 +108,8 @@ public class UserPreferences {
// Other
private static final String PREF_DATA_FOLDER = "prefDataFolder";
public static final String PREF_DELETE_REMOVES_FROM_QUEUE = "prefDeleteRemovesFromQueue";
- public static final String PREF_USAGE_COUNTING_DATE = "prefUsageCounting";
// Mediaplayer
- public static final String PREF_MEDIA_PLAYER = "prefMediaPlayer";
- public static final String PREF_MEDIA_PLAYER_EXOPLAYER = "exoplayer";
private static final String PREF_PLAYBACK_SPEED = "prefPlaybackSpeed";
private static final String PREF_VIDEO_PLAYBACK_SPEED = "prefVideoPlaybackSpeed";
public static final String PREF_PLAYBACK_SKIP_SILENCE = "prefSkipSilence";
@@ -121,7 +118,6 @@ public class UserPreferences {
private static final String PREF_QUEUE_LOCKED = "prefQueueLocked";
// Experimental
- private static final String PREF_STEREO_TO_MONO = "PrefStereoToMono";
public static final int EPISODE_CLEANUP_QUEUE = -1;
public static final int EPISODE_CLEANUP_NULL = -2;
public static final int EPISODE_CLEANUP_EXCEPT_FAVORITE = -3;
@@ -158,19 +154,35 @@ public class UserPreferences {
LIGHT, DARK, BLACK, SYSTEM
}
+ public static void setTheme(ThemePreference theme) {
+ switch (theme) {
+ case LIGHT:
+ prefs.edit().putString(PREF_THEME, "0").apply();
+ break;
+ case DARK:
+ prefs.edit().putString(PREF_THEME, "1").apply();
+ break;
+ default:
+ prefs.edit().putString(PREF_THEME, "system").apply();
+ break;
+ }
+ }
+
public static ThemePreference getTheme() {
switch (prefs.getString(PREF_THEME, "system")) {
case "0":
return ThemePreference.LIGHT;
case "1":
return ThemePreference.DARK;
- case "2":
- return ThemePreference.BLACK;
default:
return ThemePreference.SYSTEM;
}
}
+ public static boolean getIsBlackTheme() {
+ return prefs.getBoolean(PREF_THEME_BLACK, false);
+ }
+
public static boolean getIsThemeColorTinted() {
return Build.VERSION.SDK_INT >= 31 && prefs.getBoolean(PREF_TINTED_COLORS, false);
}
@@ -279,15 +291,6 @@ public class UserPreferences {
}
/**
- * Returns true if the lockscreen background should be set to the current episode's image
- *
- * @return {@code true} if the lockscreen background should be set, {@code false} otherwise
- */
- public static boolean setLockscreenBackground() {
- return prefs.getBoolean(PREF_LOCKSCREEN_BACKGROUND, true);
- }
-
- /**
* Returns true if download reports are shown
*
* @return {@code true} if download reports are shown, {@code false} otherwise
@@ -332,7 +335,7 @@ public class UserPreferences {
}
public enum EnqueueLocation {
- BACK, FRONT, AFTER_CURRENTLY_PLAYING
+ BACK, FRONT, AFTER_CURRENTLY_PLAYING, RANDOM
}
@NonNull
@@ -446,34 +449,12 @@ public class UserPreferences {
return prefs.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, true);
}
-
- /*
- * Returns update interval in milliseconds; value 0 means that auto update is disabled
- * or feeds are updated at a certain time of day
- */
public static long getUpdateInterval() {
- String updateInterval = prefs.getString(PREF_UPDATE_INTERVAL, "0");
- if(!updateInterval.contains(":")) {
- return readUpdateInterval(updateInterval);
- } else {
- return 0;
- }
- }
-
- public static int[] getUpdateTimeOfDay() {
- String datetime = prefs.getString(PREF_UPDATE_INTERVAL, "");
- if(datetime.length() >= 3 && datetime.contains(":")) {
- String[] parts = datetime.split(":");
- int hourOfDay = Integer.parseInt(parts[0]);
- int minute = Integer.parseInt(parts[1]);
- return new int[] { hourOfDay, minute };
- } else {
- return new int[0];
- }
+ return Integer.parseInt(prefs.getString(PREF_UPDATE_INTERVAL, "12"));
}
public static boolean isAutoUpdateDisabled() {
- return prefs.getString(PREF_UPDATE_INTERVAL, "").equals("0");
+ return getUpdateInterval() == 0;
}
private static boolean isAllowMobileFor(String type) {
@@ -487,6 +468,10 @@ public class UserPreferences {
return isAllowMobileFor("feed_refresh");
}
+ public static boolean isAllowMobileSync() {
+ return isAllowMobileFor("sync");
+ }
+
public static boolean isAllowMobileEpisodeDownload() {
return isAllowMobileFor("episode_download");
}
@@ -536,6 +521,10 @@ public class UserPreferences {
setAllowMobileFor("images", allow);
}
+ public static void setAllowMobileSync(boolean allow) {
+ setAllowMobileFor("sync", allow);
+ }
+
public static int getParallelDownloads() {
return Integer.parseInt(prefs.getString(PREF_PARALLEL_DOWNLOADS, "4"));
}
@@ -667,24 +656,6 @@ public class UserPreferences {
.apply();
}
- public static void setUpdateInterval(long hours) {
- prefs.edit()
- .putString(PREF_UPDATE_INTERVAL, String.valueOf(hours))
- .apply();
- }
-
- public static void setUpdateTimeOfDay(int hourOfDay, int minute) {
- prefs.edit()
- .putString(PREF_UPDATE_INTERVAL, hourOfDay + ":" + minute)
- .apply();
- }
-
- public static void disableAutoUpdate() {
- prefs.edit()
- .putString(PREF_UPDATE_INTERVAL, "0")
- .apply();
- }
-
public static boolean gpodnetNotificationsEnabled() {
if (Build.VERSION.SDK_INT >= 26) {
return true; // System handles notification preferences
@@ -725,11 +696,6 @@ public class UserPreferences {
.apply();
}
- private static long readUpdateInterval(String valueFromPrefs) {
- int hours = Integer.parseInt(valueFromPrefs);
- return TimeUnit.HOURS.toMillis(hours);
- }
-
private static List<Float> readPlaybackSpeedArray(String valueFromPrefs) {
if (valueFromPrefs != null) {
try {
@@ -748,32 +714,6 @@ public class UserPreferences {
return Arrays.asList(1.0f, 1.25f, 1.5f);
}
- public static String getMediaPlayer() {
- return prefs.getString(PREF_MEDIA_PLAYER, PREF_MEDIA_PLAYER_EXOPLAYER);
- }
-
- public static boolean useSonic() {
- return getMediaPlayer().equals("sonic");
- }
-
- public static boolean useExoplayer() {
- return getMediaPlayer().equals(PREF_MEDIA_PLAYER_EXOPLAYER);
- }
-
- public static void enableExoplayer() {
- prefs.edit().putString(PREF_MEDIA_PLAYER, PREF_MEDIA_PLAYER_EXOPLAYER).apply();
- }
-
- public static boolean stereoToMono() {
- return prefs.getBoolean(PREF_STEREO_TO_MONO, false);
- }
-
- public static void stereoToMono(boolean enable) {
- prefs.edit()
- .putBoolean(PREF_STEREO_TO_MONO, enable)
- .apply();
- }
-
public static int getEpisodeCleanupValue() {
return Integer.parseInt(prefs.getString(PREF_EPISODE_CLEANUP, "" + EPISODE_CLEANUP_NULL));
}
@@ -848,15 +788,6 @@ public class UserPreferences {
}
}
- /**
- *
- * @return true if auto update is set to a specific time
- * false if auto update is set to interval
- */
- public static boolean isAutoUpdateTimeOfDay() {
- return getUpdateTimeOfDay().length == 2;
- }
-
public static String getDefaultPage() {
return prefs.getString(PREF_DEFAULT_PAGE, "HomeFragment");
}
@@ -926,6 +857,36 @@ public class UserPreferences {
.apply();
}
+ public static FeedPreferences.NewEpisodesAction getNewEpisodesAction() {
+ String str = prefs.getString(PREF_NEW_EPISODES_ACTION,
+ "" + FeedPreferences.NewEpisodesAction.ADD_TO_INBOX.code);
+ return FeedPreferences.NewEpisodesAction.fromCode(Integer.parseInt(str));
+ }
+
+ /**
+ * Returns the sort order for the downloads.
+ */
+ public static SortOrder getDownloadsSortedOrder() {
+ String sortOrderStr = prefs.getString(PREF_DOWNLOADS_SORTED_ORDER, "" + SortOrder.DATE_NEW_OLD.code);
+ return SortOrder.fromCodeString(sortOrderStr);
+ }
+
+ /**
+ * Sets the sort order for the downloads.
+ */
+ public static void setDownloadsSortedOrder(SortOrder sortOrder) {
+ prefs.edit().putString(PREF_DOWNLOADS_SORTED_ORDER, "" + sortOrder.code).apply();
+ }
+
+ public static SortOrder getInboxSortedOrder() {
+ String sortOrderStr = prefs.getString(PREF_INBOX_SORTED_ORDER, "" + SortOrder.DATE_NEW_OLD.code);
+ return SortOrder.fromCodeString(sortOrderStr);
+ }
+
+ public static void setInboxSortedOrder(SortOrder sortOrder) {
+ prefs.edit().putString(PREF_INBOX_SORTED_ORDER, "" + sortOrder.code).apply();
+ }
+
public static SubscriptionsFilter getSubscriptionsFilter() {
String value = prefs.getString(PREF_FILTER_FEED, "");
return new SubscriptionsFilter(value);