summaryrefslogtreecommitdiff
path: root/storage/preferences/src
diff options
context:
space:
mode:
Diffstat (limited to 'storage/preferences/src')
-rw-r--r--storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java177
1 files changed, 69 insertions, 108 deletions
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);