Merge pull request #941 from mfietz/issue/940-user-preferences

Stop UserPreference caching
This commit is contained in:
Tom Hennen 2015-06-25 18:19:35 -04:00
commit 91a8cab9ea
12 changed files with 366 additions and 688 deletions

View File

@ -43,7 +43,7 @@ public class HttpDownloaderTest extends InstrumentationTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
UserPreferences.createInstance(getInstrumentation().getTargetContext());
UserPreferences.init(getInstrumentation().getTargetContext());
destDir = getInstrumentation().getTargetContext().getExternalFilesDir(DOWNLOAD_DIR);
assertNotNull(destDir);
assertTrue(destDir.exists());

View File

@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedItem;
@ -298,9 +299,8 @@ public class DBTasksTest extends InstrumentationTestCase {
}
}
@FlakyTest(tolerance = 3)
private void expiredFeedListTestHelper(long lastUpdate, long expirationTime, boolean shouldReturn) {
UserPreferences.setUpdateInterval(context, expirationTime);
UserPreferences.setUpdateInterval(TimeUnit.MILLISECONDS.toHours(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, false);
feed.setItems(new ArrayList<FeedItem>());

View File

@ -39,7 +39,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
Timeout.setLargeTimeout(1000);
context = getInstrumentation().getTargetContext();
res = getActivity().getResources();
UserPreferences.createInstance(context);
UserPreferences.init(context);
}
@Override

View File

@ -38,8 +38,8 @@ public class PodcastApp extends Application {
LOGICAL_DENSITY = getResources().getDisplayMetrics().density;
PicassoProvider.setupPicassoInstance(this);
UserPreferences.createInstance(this);
PlaybackPreferences.createInstance(this);
UserPreferences.init(this);
PlaybackPreferences.init(this);
EventDistributor.getInstance();
SPAUtil.sendSPAppsQueryFeedsIntent(this);

View File

@ -8,7 +8,6 @@ import android.content.Intent;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.activity.StorageErrorActivity;
import de.danoeh.antennapod.core.ApplicationCallbacks;
import de.danoeh.antennapod.core.preferences.UserPreferences;
public class ApplicationCallbacksImpl implements ApplicationCallbacks {
@ -22,8 +21,4 @@ public class ApplicationCallbacksImpl implements ApplicationCallbacks {
return new Intent(context, StorageErrorActivity.class);
}
@Override
public void setUpdateInterval(long updateInterval) {
UserPreferences.restartUpdateAlarm(updateInterval, updateInterval);
}
}

View File

@ -24,6 +24,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
@ -200,6 +201,19 @@ public class PreferenceController {
}
});
ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL)
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue instanceof String) {
int hours = Integer.valueOf((String)newValue);
long millis = TimeUnit.HOURS.toMillis(hours);
UserPreferences.restartUpdateAlarm(millis, millis);
}
return true;
}
});
ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL)
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
@ -345,7 +359,7 @@ public class PreferenceController {
@Override
public void onConfirmed(boolean autoFlattrEnabled, float autoFlattrValue) {
UserPreferences.setAutoFlattrSettings(activity, autoFlattrEnabled, autoFlattrValue);
UserPreferences.setAutoFlattrSettings(autoFlattrEnabled, autoFlattrValue);
checkItemVisibility();
}
});
@ -389,8 +403,7 @@ public class PreferenceController {
final Resources res = ui.getActivity().getResources();
ListPreference pref = (ListPreference) ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL);
String[] values = res.getStringArray(
R.array.update_intervall_values);
String[] values = res.getStringArray(R.array.update_intervall_values);
String[] entries = new String[values.length];
for (int x = 0; x < values.length; x++) {
Integer v = Integer.parseInt(values[x]);
@ -529,9 +542,7 @@ public class PreferenceController {
}
UserPreferences.setAutodownloadSelectedNetworks(
activity, prefValuesList
.toArray(new String[prefValuesList
.size()])
prefValuesList.toArray(new String[prefValuesList.size()])
);
return true;
} else {

View File

@ -20,5 +20,4 @@ public interface ApplicationCallbacks {
*/
public Intent getStorageErrorActivity(Context context);
public void setUpdateInterval(long updateInterval);
}

View File

@ -3,11 +3,7 @@ package de.danoeh.antennapod.core.preferences;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import org.apache.commons.lang3.Validate;
import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.feed.EventDistributor;
/**
@ -15,159 +11,104 @@ import de.danoeh.antennapod.core.feed.EventDistributor;
* instance of this class must first be instantiated via createInstance() or
* otherwise every public method will throw an Exception when called.
*/
public class PlaybackPreferences implements
SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = "PlaybackPreferences";
public class PlaybackPreferences implements SharedPreferences.OnSharedPreferenceChangeListener {
/**
* Contains the feed id of the currently playing item if it is a FeedMedia
* object.
*/
public static final String PREF_CURRENTLY_PLAYING_FEED_ID = "de.danoeh.antennapod.preferences.lastPlayedFeedId";
private static final String TAG = "PlaybackPreferences";
/**
* Contains the id of the currently playing FeedMedia object or
* NO_MEDIA_PLAYING if the currently playing media is no FeedMedia object.
*/
public static final String PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID = "de.danoeh.antennapod.preferences.lastPlayedFeedMediaId";
/**
* Contains the feed id of the currently playing item if it is a FeedMedia
* object.
*/
public static final String PREF_CURRENTLY_PLAYING_FEED_ID = "de.danoeh.antennapod.preferences.lastPlayedFeedId";
/**
* Type of the media object that is currently being played. This preference
* is set to NO_MEDIA_PLAYING after playback has been completed and is set
* as soon as the 'play' button is pressed.
*/
public static final String PREF_CURRENTLY_PLAYING_MEDIA = "de.danoeh.antennapod.preferences.currentlyPlayingMedia";
/**
* Contains the id of the currently playing FeedMedia object or
* NO_MEDIA_PLAYING if the currently playing media is no FeedMedia object.
*/
public static final String PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID = "de.danoeh.antennapod.preferences.lastPlayedFeedMediaId";
/** True if last played media was streamed. */
public static final String PREF_CURRENT_EPISODE_IS_STREAM = "de.danoeh.antennapod.preferences.lastIsStream";
/**
* Type of the media object that is currently being played. This preference
* is set to NO_MEDIA_PLAYING after playback has been completed and is set
* as soon as the 'play' button is pressed.
*/
public static final String PREF_CURRENTLY_PLAYING_MEDIA = "de.danoeh.antennapod.preferences.currentlyPlayingMedia";
/** True if last played media was a video. */
public static final String PREF_CURRENT_EPISODE_IS_VIDEO = "de.danoeh.antennapod.preferences.lastIsVideo";
/**
* True if last played media was streamed.
*/
public static final String PREF_CURRENT_EPISODE_IS_STREAM = "de.danoeh.antennapod.preferences.lastIsStream";
/** The current player status as int. */
/**
* True if last played media was a video.
*/
public static final String PREF_CURRENT_EPISODE_IS_VIDEO = "de.danoeh.antennapod.preferences.lastIsVideo";
/**
* The current player status as int.
*/
public static final String PREF_CURRENT_PLAYER_STATUS = "de.danoeh.antennapod.preferences.currentPlayerStatus";
/** Value of PREF_CURRENTLY_PLAYING_MEDIA if no media is playing. */
public static final long NO_MEDIA_PLAYING = -1;
/**
* Value of PREF_CURRENTLY_PLAYING_MEDIA if no media is playing.
*/
public static final long NO_MEDIA_PLAYING = -1;
/** Value of PREF_CURRENT_PLAYER_STATUS if media player status is playing. */
/**
* Value of PREF_CURRENT_PLAYER_STATUS if media player status is playing.
*/
public static final int PLAYER_STATUS_PLAYING = 1;
/** Value of PREF_CURRENT_PLAYER_STATUS if media player status is paused. */
/**
* Value of PREF_CURRENT_PLAYER_STATUS if media player status is paused.
*/
public static final int PLAYER_STATUS_PAUSED = 2;
/** Value of PREF_CURRENT_PLAYER_STATUS if media player status is neither playing nor paused. */
/**
* Value of PREF_CURRENT_PLAYER_STATUS if media player status is neither playing nor paused.
*/
public static final int PLAYER_STATUS_OTHER = 3;
private long currentlyPlayingFeedId;
private long currentlyPlayingFeedMediaId;
private long currentlyPlayingMedia;
private boolean currentEpisodeIsStream;
private boolean currentEpisodeIsVideo;
private int currentPlayerStatus;
private static PlaybackPreferences instance;
private static SharedPreferences prefs;
private static PlaybackPreferences instance;
private Context context;
private PlaybackPreferences() {
}
private PlaybackPreferences(Context context) {
this.context = context;
loadPreferences();
}
public static void init(Context context) {
instance = new PlaybackPreferences();
prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.registerOnSharedPreferenceChangeListener(instance);
}
/**
* Sets up the UserPreferences class.
*
* @throws IllegalArgumentException
* if context is null
* */
public static void createInstance(Context context) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Creating new instance of UserPreferences");
Validate.notNull(context);
instance = new PlaybackPreferences(context);
PreferenceManager.getDefaultSharedPreferences(context)
.registerOnSharedPreferenceChangeListener(instance);
}
private void loadPreferences() {
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(context);
currentlyPlayingFeedId = sp.getLong(PREF_CURRENTLY_PLAYING_FEED_ID, -1);
currentlyPlayingFeedMediaId = sp.getLong(
PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
currentlyPlayingMedia = sp.getLong(PREF_CURRENTLY_PLAYING_MEDIA,
NO_MEDIA_PLAYING);
currentEpisodeIsStream = sp.getBoolean(PREF_CURRENT_EPISODE_IS_STREAM, true);
currentEpisodeIsVideo = sp.getBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, false);
currentPlayerStatus = sp.getInt(PREF_CURRENT_PLAYER_STATUS,
PLAYER_STATUS_OTHER);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sp, String key) {
if (key.equals(PREF_CURRENTLY_PLAYING_FEED_ID)) {
currentlyPlayingFeedId = sp.getLong(PREF_CURRENTLY_PLAYING_FEED_ID,
-1);
} else if (key.equals(PREF_CURRENTLY_PLAYING_MEDIA)) {
currentlyPlayingMedia = sp
.getLong(PREF_CURRENTLY_PLAYING_MEDIA, -1);
} else if (key.equals(PREF_CURRENT_EPISODE_IS_STREAM)) {
currentEpisodeIsStream = sp.getBoolean(PREF_CURRENT_EPISODE_IS_STREAM, true);
} else if (key.equals(PREF_CURRENT_EPISODE_IS_VIDEO)) {
currentEpisodeIsVideo = sp.getBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, false);
} else if (key.equals(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID)) {
currentlyPlayingFeedMediaId = sp.getLong(
PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
}
else if (key.equals(PREF_CURRENT_PLAYER_STATUS)) {
currentPlayerStatus = sp.getInt(PREF_CURRENT_PLAYER_STATUS,
PLAYER_STATUS_OTHER);
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(PREF_CURRENT_PLAYER_STATUS)) {
EventDistributor.getInstance().sendPlayerStatusUpdateBroadcast();
}
}
private static void instanceAvailable() {
if (instance == null) {
throw new IllegalStateException(
"UserPreferences was used before being set up");
}
}
}
public static long getLastPlayedFeedId() {
instanceAvailable();
return instance.currentlyPlayingFeedId;
return prefs.getLong(PREF_CURRENTLY_PLAYING_FEED_ID, -1);
}
public static long getCurrentlyPlayingMedia() {
instanceAvailable();
return instance.currentlyPlayingMedia;
return prefs.getLong(PREF_CURRENTLY_PLAYING_MEDIA, NO_MEDIA_PLAYING);
}
public static long getCurrentlyPlayingFeedMediaId() {
return instance.currentlyPlayingFeedMediaId;
return prefs.getLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
}
public static boolean getCurrentEpisodeIsStream() {
instanceAvailable();
return instance.currentEpisodeIsStream;
return prefs.getBoolean(PREF_CURRENT_EPISODE_IS_STREAM, true);
}
public static boolean getCurrentEpisodeIsVideo() {
instanceAvailable();
return instance.currentEpisodeIsVideo;
return prefs.getBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, false);
}
public static int getCurrentPlayerStatus() {
instanceAvailable();
return instance.currentPlayerStatus;
return prefs.getInt(PREF_CURRENT_PLAYER_STATUS, PLAYER_STATUS_OTHER);
}
}

View File

@ -5,6 +5,7 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
@ -29,17 +30,16 @@ import de.danoeh.antennapod.core.receiver.FeedUpdateReceiver;
/**
* Provides access to preferences set by the user in the settings screen. A
* private instance of this class must first be instantiated via
* createInstance() or otherwise every public method will throw an Exception
* init() or otherwise every public method will throw an Exception
* when called.
*/
public class UserPreferences implements
SharedPreferences.OnSharedPreferenceChangeListener {
public class UserPreferences {
public static final String IMPORT_DIR = "import/";
private static final String TAG = "UserPreferences";
// User Infercasce
// User Interface
public static final String PREF_THEME = "prefTheme";
public static final String PREF_HIDDEN_DRAWER_ITEMS = "prefHiddenDrawerItems";
public static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify";
@ -55,7 +55,7 @@ public class UserPreferences implements
public static final String PREF_FOLLOW_QUEUE = "prefFollowQueue";
public static final String PREF_AUTO_DELETE = "prefAutoDelete";
public static final String PREF_SMART_MARK_AS_PLAYED_SECS = "prefSmartMarkAsPlayedSecs";
private static final String PREF_PLAYBACK_SPEED_ARRAY = "prefPlaybackSpeedArray";
public 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";
@ -82,131 +82,269 @@ public class UserPreferences implements
private static final String PREF_REWIND_SECS = "prefRewindSecs";
public static final String PREF_QUEUE_LOCKED = "prefQueueLocked";
// TODO: Make this value configurable
private static final float PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT = 0.8f;
// Constants
private static int EPISODE_CACHE_SIZE_UNLIMITED = -1;
private static UserPreferences instance;
private final Context context;
// User Interface
private int theme;
private List<String> hiddenDrawerItems;
private int notifyPriority;
private boolean persistNotify;
private boolean showDownloadReport;
// Queue
private boolean enqueueAtFront;
// Playback
private boolean pauseOnHeadsetDisconnect;
private boolean unpauseOnHeadsetReconnect;
private boolean followQueue;
private boolean autoDelete;
private int smartMarkAsPlayedSecs;
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 enableAutodownloadOnBattery;
private boolean enableAutodownloadWifiFilter;
private String[] autodownloadSelectedNetworks;
// Services
private boolean autoFlattr;
private float autoFlattrPlayedDurationThreshold;
// Settings somewhere in the GUI
private String playbackSpeed;
private int fastForwardSecs;
private int rewindSecs;
private boolean queueLocked;
private UserPreferences(Context context) {
this.context = context;
loadPreferences();
}
private static Context context;
private static SharedPreferences prefs;
/**
* Sets up the UserPreferences class.
*
* @throws IllegalArgumentException if context is null
*/
public static void createInstance(Context context) {
public static void init(Context context) {
Log.d(TAG, "Creating new instance of UserPreferences");
Validate.notNull(context);
instance = new UserPreferences(context);
UserPreferences.context = context;
UserPreferences.prefs = PreferenceManager.getDefaultSharedPreferences(context);
createImportDirectory();
createNoMediaFile();
PreferenceManager.getDefaultSharedPreferences(context)
.registerOnSharedPreferenceChangeListener(instance);
}
private void loadPreferences() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
/**
* Returns theme as R.style value
*
* @return R.style.Theme_AntennaPod_Light or R.style.Theme_AntennaPod_Dark
*/
public static int getTheme() {
return readThemeValue(prefs.getString(PREF_THEME, "0"));
}
// User Interface
theme = readThemeValue(sp.getString(PREF_THEME, "0"));
if (sp.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) {
notifyPriority = NotificationCompat.PRIORITY_MAX;
public static int getNoTitleTheme() {
int theme = getTheme();
if (theme == R.style.Theme_AntennaPod_Dark) {
return R.style.Theme_AntennaPod_Dark_NoTitle;
} else {
notifyPriority = NotificationCompat.PRIORITY_DEFAULT;
return R.style.Theme_AntennaPod_Light_NoTitle;
}
hiddenDrawerItems = Arrays.asList(StringUtils.split(sp.getString(PREF_HIDDEN_DRAWER_ITEMS, ""), ','));
persistNotify = sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, false);
showDownloadReport = sp.getBoolean(PREF_SHOW_DOWNLOAD_REPORT, true);
// 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);
autoDelete = sp.getBoolean(PREF_AUTO_DELETE, false);
smartMarkAsPlayedSecs = Integer.valueOf(sp.getString(PREF_SMART_MARK_AS_PLAYED_SECS, "30"));
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"));
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");
fastForwardSecs = sp.getInt(PREF_FAST_FORWARD_SECS, 30);
rewindSecs = sp.getInt(PREF_REWIND_SECS, 30);
queueLocked = sp.getBoolean(PREF_QUEUE_LOCKED, false);
}
private int readThemeValue(String valueFromPrefs) {
public static List<String> getHiddenDrawerItems() {
String hiddenItems = prefs.getString(PREF_HIDDEN_DRAWER_ITEMS, "");
return new ArrayList<String>(Arrays.asList(StringUtils.split(hiddenItems, ',')));
}
/**
* Returns notification priority.
*
* @return NotificationCompat.PRIORITY_MAX or NotificationCompat.PRIORITY_DEFAULT
*/
public static int getNotifyPriority() {
if (prefs.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) {
return NotificationCompat.PRIORITY_MAX;
} else {
return NotificationCompat.PRIORITY_DEFAULT;
}
}
/**
* Returns true if notifications are persistent
*
* @return {@code true} if notifications are persistent, {@code false} otherwise
*/
public static boolean isPersistNotify() {
return prefs.getBoolean(PREF_PERSISTENT_NOTIFICATION, false);
}
/**
* Returns true if download reports are shown
*
* @return {@code true} if download reports are shown, {@code false} otherwise
*/
public static boolean showDownloadReport() {
return prefs.getBoolean(PREF_SHOW_DOWNLOAD_REPORT, true);
}
/**
* 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 boolean enqueueAtFront() {
return prefs.getBoolean(PREF_QUEUE_ADD_TO_FRONT, false);
}
public static boolean isPauseOnHeadsetDisconnect() {
return prefs.getBoolean(PREF_PAUSE_ON_HEADSET_DISCONNECT, true);
}
public static boolean isUnpauseOnHeadsetReconnect() {
return prefs.getBoolean(PREF_UNPAUSE_ON_HEADSET_RECONNECT, true);
}
public static boolean isFollowQueue() {
return prefs.getBoolean(PREF_FOLLOW_QUEUE, false);
}
public static boolean isAutoDelete() {
return prefs.getBoolean(PREF_AUTO_DELETE, false);
}
public static int getSmartMarkAsPlayedSecs() {
return Integer.valueOf(prefs.getString(PREF_SMART_MARK_AS_PLAYED_SECS, "30"));
}
public static boolean isAutoFlattr() {
return prefs.getBoolean(PREF_AUTO_FLATTR, false);
}
public static String getPlaybackSpeed() {
return prefs.getString(PREF_PLAYBACK_SPEED, "1.0");
}
public static String[] getPlaybackSpeedArray() {
return readPlaybackSpeedArray(prefs.getString(PREF_PLAYBACK_SPEED_ARRAY, null));
}
public static boolean shouldPauseForFocusLoss() {
return prefs.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false);
}
public static long getUpdateInterval() {
return readUpdateInterval(prefs.getString(PREF_UPDATE_INTERVAL, "0"));
}
public static boolean isAllowMobileUpdate() {
return prefs.getBoolean(PREF_MOBILE_UPDATE, false);
}
public static int getParallelDownloads() {
return Integer.valueOf(prefs.getString(PREF_PARALLEL_DOWNLOADS, "4"));
}
public static int getEpisodeCacheSizeUnlimited() {
return context.getResources().getInteger(R.integer.episode_cache_size_unlimited);
}
/**
* Returns the capacity of the episode cache. This method will return the
* negative integer EPISODE_CACHE_SIZE_UNLIMITED if the cache size is set to
* 'unlimited'.
*/
public static int getEpisodeCacheSize() {
return readEpisodeCacheSizeInternal(prefs.getString(PREF_EPISODE_CACHE_SIZE, "20"));
}
public static boolean isEnableAutodownload() {
return prefs.getBoolean(PREF_ENABLE_AUTODL, false);
}
public static boolean isEnableAutodownloadOnBattery() {
return prefs.getBoolean(PREF_ENABLE_AUTODL_ON_BATTERY, true);
}
public static boolean isEnableAutodownloadWifiFilter() {
return prefs.getBoolean(PREF_ENABLE_AUTODL_WIFI_FILTER, false);
}
public static int getFastFowardSecs() {
return prefs.getInt(PREF_FAST_FORWARD_SECS, 30);
}
public static int getRewindSecs() {
return prefs.getInt(PREF_REWIND_SECS, 30);
}
/**
* Returns the time after which an episode should be auto-flattr'd in percent of the episode's
* duration.
*/
public static float getAutoFlattrPlayedDurationThreshold() {
return prefs.getFloat(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD, 0.8f);
}
public static String[] getAutodownloadSelectedNetworks() {
String selectedNetWorks = prefs.getString(PREF_AUTODL_SELECTED_NETWORKS, "");
return StringUtils.split(selectedNetWorks, ',');
}
public static boolean shouldResumeAfterCall() {
return prefs.getBoolean(PREF_RESUME_AFTER_CALL, true);
}
public static boolean isQueueLocked() {
return prefs.getBoolean(PREF_QUEUE_LOCKED, false);
}
public static void setPrefFastForwardSecs(int secs) {
prefs.edit()
.putInt(PREF_FAST_FORWARD_SECS, secs)
.apply();
}
public static void setPrefRewindSecs(int secs) {
prefs.edit()
.putInt(PREF_REWIND_SECS, secs)
.apply();
}
public static void setPlaybackSpeed(String speed) {
prefs.edit()
.putString(PREF_PLAYBACK_SPEED, speed)
.apply();
}
public static void setPlaybackSpeedArray(String[] speeds) {
JSONArray jsonArray = new JSONArray();
for (String speed : speeds) {
jsonArray.put(speed);
}
prefs.edit()
.putString(PREF_PLAYBACK_SPEED_ARRAY, jsonArray.toString())
.apply();
}
public static void setAutodownloadSelectedNetworks(String[] value) {
prefs.edit()
.putString(PREF_AUTODL_SELECTED_NETWORKS, StringUtils.join(value, ','))
.apply();
}
/**
* Sets the update interval value. Should only be used for testing purposes!
*/
public static void setUpdateInterval(long hours) {
prefs.edit()
.putString(PREF_UPDATE_INTERVAL, String.valueOf(hours))
.apply();
restartUpdateAlarm();
}
/**
* Change the auto-flattr settings
*
* @param enabled Whether automatic flattring should be enabled at all
* @param autoFlattrThreshold The percentage of playback time after which an episode should be
* flattrd. Must be a value between 0 and 1 (inclusive)
* */
public static void setAutoFlattrSettings( boolean enabled, float autoFlattrThreshold) {
Validate.inclusiveBetween(0.0, 1.0, autoFlattrThreshold);
prefs.edit()
.putBoolean(PREF_AUTO_FLATTR, enabled)
.putFloat(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD, autoFlattrThreshold)
.apply();
}
public static void setHiddenDrawerItems(Context context, List<String> items) {
String str = StringUtils.join(items, ',');
prefs.edit()
.putString(PREF_HIDDEN_DRAWER_ITEMS, str)
.apply();
}
public static void setQueueLocked(boolean locked) {
prefs.edit()
.putBoolean(PREF_QUEUE_LOCKED, locked)
.apply();
}
private static int readThemeValue(String valueFromPrefs) {
switch (Integer.parseInt(valueFromPrefs)) {
case 0:
return R.style.Theme_AntennaPod_Light;
@ -217,26 +355,24 @@ public class UserPreferences implements
}
}
private long readUpdateInterval(String valueFromPrefs) {
private static long readUpdateInterval(String valueFromPrefs) {
int hours = Integer.parseInt(valueFromPrefs);
return TimeUnit.HOURS.toMillis(hours);
}
private int readEpisodeCacheSizeInternal(String valueFromPrefs) {
if (valueFromPrefs.equals(context
.getString(R.string.pref_episode_cache_unlimited))) {
private static int readEpisodeCacheSizeInternal(String valueFromPrefs) {
if (valueFromPrefs.equals(context.getString(R.string.pref_episode_cache_unlimited))) {
return EPISODE_CACHE_SIZE_UNLIMITED;
} else {
return Integer.valueOf(valueFromPrefs);
}
}
private String[] readPlaybackSpeedArray(String valueFromPrefs) {
private static String[] readPlaybackSpeedArray(String valueFromPrefs) {
String[] selectedSpeeds = null;
// If this preference hasn't been set yet, return the default options
if (valueFromPrefs == null) {
String[] allSpeeds = context.getResources().getStringArray(
R.array.playback_speed_values);
String[] allSpeeds = context.getResources().getStringArray(R.array.playback_speed_values);
List<String> speedList = new LinkedList<String>();
for (String speedStr : allSpeeds) {
float speed = Float.parseFloat(speedStr);
@ -260,399 +396,6 @@ public class UserPreferences implements
return selectedSpeeds;
}
private static void instanceAvailable() {
if (instance == null) {
throw new IllegalStateException("UserPreferences was used before being set up");
}
}
/**
* 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.theme;
}
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 List<String> getHiddenDrawerItems() {
instanceAvailable();
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 true if download reports are shown
*
* @return {@code true} if download reports are shown, {@code false} otherwise
*/
public static boolean showDownloadReport() {
instanceAvailable();
return instance.showDownloadReport;
}
/**
* 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 boolean enqueueAtFront() {
instanceAvailable();
return instance.enqueueAtFront;
}
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 isAutoDelete() {
instanceAvailable();
return instance.autoDelete;
}
public static int getSmartMarkAsPlayedSecs() {
instanceAvailable();
return instance.smartMarkAsPlayedSecs;
}
public static boolean isAutoFlattr() {
instanceAvailable();
return instance.autoFlattr;
}
public static String getPlaybackSpeed() {
instanceAvailable();
return instance.playbackSpeed;
}
public static String[] getPlaybackSpeedArray() {
instanceAvailable();
return instance.playbackSpeedArray;
}
public static boolean shouldPauseForFocusLoss() {
instanceAvailable();
return instance.pauseForFocusLoss;
}
public static long getUpdateInterval() {
instanceAvailable();
return instance.updateInterval;
}
public static boolean isAllowMobileUpdate() {
instanceAvailable();
return instance.allowMobileUpdate;
}
public static int getParallelDownloads() {
instanceAvailable();
return instance.parallelDownloads;
}
public static int getEpisodeCacheSizeUnlimited() {
return EPISODE_CACHE_SIZE_UNLIMITED;
}
/**
* Returns the capacity of the episode cache. This method will return the
* negative integer EPISODE_CACHE_SIZE_UNLIMITED if the cache size is set to
* 'unlimited'.
*/
public static int getEpisodeCacheSize() {
instanceAvailable();
return instance.episodeCacheSize;
}
public static boolean isEnableAutodownload() {
instanceAvailable();
return instance.enableAutodownload;
}
public static boolean isEnableAutodownloadOnBattery() {
instanceAvailable();
return instance.enableAutodownloadOnBattery;
}
public static boolean isEnableAutodownloadWifiFilter() {
instanceAvailable();
return instance.enableAutodownloadWifiFilter;
}
public static int getFastFowardSecs() {
instanceAvailable();
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 shouldResumeAfterCall() {
instanceAvailable();
return instance.resumeAfterCall;
}
public static boolean isQueueLocked() {
instanceAvailable();
return instance.queueLocked;
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sp, String key) {
Log.d(TAG, "Registered change of user preferences. Key: " + key);
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;
case PREF_SHOW_DOWNLOAD_REPORT:
showDownloadReport = sp.getBoolean(PREF_SHOW_DOWNLOAD_REPORT, true);
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);
}
}
public static void setPrefFastForwardSecs(int secs) {
Log.d(TAG, "setPrefFastForwardSecs(" + secs +")");
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(instance.context).edit();
editor.putInt(PREF_FAST_FORWARD_SECS, secs);
editor.commit();
}
public static void setPrefRewindSecs(int secs) {
Log.d(TAG, "setPrefRewindSecs(" + secs +")");
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(instance.context).edit();
editor.putInt(PREF_REWIND_SECS, secs);
editor.commit();
}
public static void setPlaybackSpeed(String speed) {
PreferenceManager.getDefaultSharedPreferences(instance.context).edit()
.putString(PREF_PLAYBACK_SPEED, speed).apply();
}
public static void setPlaybackSpeedArray(String[] speeds) {
JSONArray jsonArray = new JSONArray();
for (String speed : speeds) {
jsonArray.put(speed);
}
PreferenceManager.getDefaultSharedPreferences(instance.context).edit()
.putString(PREF_PLAYBACK_SPEED_ARRAY, jsonArray.toString())
.apply();
}
public static void setAutodownloadSelectedNetworks(Context context,
String[] value) {
SharedPreferences.Editor editor = PreferenceManager
.getDefaultSharedPreferences(context.getApplicationContext())
.edit();
editor.putString(PREF_AUTODL_SELECTED_NETWORKS,
StringUtils.join(value, ','));
editor.commit();
}
/**
* Sets the update interval value. Should only be used for testing purposes!
*/
public static void setUpdateInterval(Context context, long newValue) {
instanceAvailable();
SharedPreferences.Editor editor = PreferenceManager
.getDefaultSharedPreferences(context.getApplicationContext())
.edit();
editor.putString(PREF_UPDATE_INTERVAL,
String.valueOf(newValue));
editor.commit();
instance.updateInterval = newValue;
}
/**
* Change the auto-flattr settings
*
* @param context For accessing the shared preferences
* @param enabled Whether automatic flattring should be enabled at all
* @param autoFlattrThreshold The percentage of playback time after which an episode should be
* flattrd. Must be a value between 0 and 1 (inclusive)
* */
public static void setAutoFlattrSettings(Context context, boolean enabled, float autoFlattrThreshold) {
instanceAvailable();
Validate.inclusiveBetween(0.0, 1.0, autoFlattrThreshold);
PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext())
.edit()
.putBoolean(PREF_AUTO_FLATTR, enabled)
.putFloat(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD, autoFlattrThreshold)
.commit();
instance.autoFlattr = enabled;
instance.autoFlattrPlayedDurationThreshold = autoFlattrThreshold;
}
public static void setHiddenDrawerItems(Context context, List<String> items) {
instanceAvailable();
instance.hiddenDrawerItems = items;
String str = StringUtils.join(items, ',');
PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext())
.edit()
.putString(PREF_HIDDEN_DRAWER_ITEMS, str)
.commit();
}
public static void setQueueLocked(boolean locked) {
instanceAvailable();
instance.queueLocked = locked;
PreferenceManager.getDefaultSharedPreferences(instance.context)
.edit()
.putBoolean(PREF_QUEUE_LOCKED, locked)
.commit();
}
/**
* Return the folder where the app stores all of its data. This method will
@ -664,9 +407,6 @@ public class UserPreferences implements
* could not be created.
*/
public static File getDataFolder(Context context, String type) {
instanceAvailable();
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context.getApplicationContext());
String strDir = prefs.getString(PREF_DATA_FOLDER, null);
if (strDir == null) {
Log.d(TAG, "Using default data folder");
@ -712,12 +452,9 @@ public class UserPreferences implements
public static void setDataFolder(String dir) {
Log.d(TAG, "Result from DirectoryChooser: " + dir);
instanceAvailable();
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(instance.context);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(PREF_DATA_FOLDER, dir);
editor.commit();
prefs.edit()
.putString(PREF_DATA_FOLDER, dir)
.apply();
createImportDirectory();
}
@ -725,8 +462,7 @@ public class UserPreferences implements
* Create a .nomedia file to prevent scanning by the media scanner.
*/
private static void createNoMediaFile() {
File f = new File(instance.context.getExternalFilesDir(null),
".nomedia");
File f = new File(context.getExternalFilesDir(null), ".nomedia");
if (!f.exists()) {
try {
f.createNewFile();
@ -743,8 +479,7 @@ public class UserPreferences implements
* available
*/
private static void createImportDirectory() {
File importDir = getDataFolder(instance.context,
IMPORT_DIR);
File importDir = getDataFolder(context, IMPORT_DIR);
if (importDir != null) {
if (importDir.exists()) {
Log.d(TAG, "Import directory already exists");
@ -757,32 +492,36 @@ public class UserPreferences implements
}
}
public static void restartUpdateAlarm() {
long hours = getUpdateInterval();
restartUpdateAlarm(TimeUnit.SECONDS.toMillis(10), hours);
}
/**
* Updates alarm registered with the AlarmManager service or deactivates it.
*/
public static void restartUpdateAlarm(long triggerAtMillis, long intervalMillis) {
instanceAvailable();
Log.d(TAG, "Restarting update alarm.");
AlarmManager alarmManager = (AlarmManager) instance.context
.getSystemService(Context.ALARM_SERVICE);
PendingIntent updateIntent = PendingIntent.getBroadcast(
instance.context, 0, new Intent(ClientConfig.applicationCallbacks.getApplicationInstance(), FeedUpdateReceiver.class), 0);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent updateIntent = PendingIntent.getBroadcast(context, 0,
new Intent(ClientConfig.applicationCallbacks.getApplicationInstance(), FeedUpdateReceiver.class), 0);
alarmManager.cancel(updateIntent);
if (intervalMillis != 0) {
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, intervalMillis,
if (intervalMillis > 0) {
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + triggerAtMillis,
intervalMillis,
updateIntent);
Log.d(TAG, "Changed alarm to new interval");
Log.d(TAG, "Changed alarm to new interval " + TimeUnit.MILLISECONDS.toHours(intervalMillis) + " h");
} else {
Log.d(TAG, "Automatic update was deactivated");
}
}
/**
* Reads episode cache size as it is saved in the episode_cache_size_values array.
*/
public static int readEpisodeCacheSize(String valueFromPrefs) {
instanceAvailable();
return instance.readEpisodeCacheSizeInternal(valueFromPrefs);
return readEpisodeCacheSizeInternal(valueFromPrefs);
}
}

View File

@ -7,28 +7,25 @@ import android.util.Log;
import org.apache.commons.lang3.StringUtils;
import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences;
/** Listens for events that make it necessary to reset the update alarm. */
public class AlarmUpdateReceiver extends BroadcastReceiver {
private static final String TAG = "AlarmUpdateReceiver";
@Override
public void onReceive(Context context, Intent intent) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Received intent");
Log.d(TAG, "Received intent");
if (StringUtils.equals(intent.getAction(), Intent.ACTION_BOOT_COMPLETED)) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Resetting update alarm after reboot");
Log.d(TAG, "Resetting update alarm after reboot");
} else if (StringUtils.equals(intent.getAction(), Intent.ACTION_PACKAGE_REPLACED)) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Resetting update alarm after app upgrade");
Log.d(TAG, "Resetting update alarm after app upgrade");
}
ClientConfig.applicationCallbacks.setUpdateInterval(UserPreferences.getUpdateInterval());
PlaybackPreferences.init(context);
UserPreferences.init(context);
UserPreferences.restartUpdateAlarm();
}
}

View File

@ -124,8 +124,7 @@ public final class DBReader {
* can be loaded separately with {@link #getFeedItemList(android.content.Context, de.danoeh.antennapod.core.feed.Feed)}.
*/
public static List<Feed> getExpiredFeedsList(final Context context, final long expirationTime) {
if (BuildConfig.DEBUG)
Log.d(TAG, String.format("getExpiredFeedsList(%d)", expirationTime));
Log.d(TAG, String.format("getExpiredFeedsList(%d)", expirationTime));
PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();

View File

@ -199,11 +199,8 @@ public final class DBTasks {
*/
public static List<Feed> getExpiredFeeds(final Context context) {
long millis = UserPreferences.getUpdateInterval();
if (millis > 0) {
List<Feed> feedList = DBReader.getExpiredFeedsList(context,
millis);
List<Feed> feedList = DBReader.getExpiredFeedsList(context, millis);
if (feedList.size() > 0) {
refreshFeeds(context, feedList);
}