Implemented PlaybackPreferences

This commit is contained in:
daniel oeh 2013-02-25 20:49:37 +01:00
parent 56db791e7d
commit 6a22ada87f
6 changed files with 230 additions and 138 deletions

View File

@ -1,20 +1,16 @@
package de.danoeh.antennapod;
import android.app.Application;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.preference.PreferenceManager;
import android.util.Log;
import de.danoeh.antennapod.asynctask.ImageLoader;
import de.danoeh.antennapod.feed.EventDistributor;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.feed.FeedMedia;
import de.danoeh.antennapod.preferences.PlaybackPreferences;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.service.PlaybackService;
/** Main application class. */
public class PodcastApp extends Application implements
SharedPreferences.OnSharedPreferenceChangeListener {
public class PodcastApp extends Application {
private static final String TAG = "PodcastApp";
public static final String EXPORT_DIR = "export/";
@ -23,8 +19,6 @@ public class PodcastApp extends Application implements
private static PodcastApp singleton;
private static long currentlyPlayingMediaId;
public static PodcastApp getInstance() {
return singleton;
}
@ -34,13 +28,9 @@ public class PodcastApp extends Application implements
super.onCreate();
singleton = this;
LOGICAL_DENSITY = getResources().getDisplayMetrics().density;
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
currentlyPlayingMediaId = prefs.getLong(
PlaybackService.PREF_CURRENTLY_PLAYING_MEDIA,
PlaybackService.NO_MEDIA_PLAYING);
prefs.registerOnSharedPreferenceChangeListener(this);
UserPreferences.createInstance(this);
PlaybackPreferences.createInstance(this);
EventDistributor.getInstance();
FeedManager manager = FeedManager.getInstance();
manager.loadDBData(getApplicationContext());
@ -53,48 +43,10 @@ public class PodcastApp extends Application implements
ImageLoader.getInstance().wipeImageCache();
}
/**
* Listens for changes in the 'update intervall'-preference and changes the
* alarm if necessary.
*/
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
if (AppConfig.DEBUG)
Log.d(TAG, "Registered change of application preferences");
if (key.equals(PlaybackService.PREF_LAST_PLAYED_ID)) {
if (AppConfig.DEBUG)
Log.d(TAG, "PREF_LAST_PLAYED_ID changed");
long mediaId = sharedPreferences.getLong(
PlaybackService.PREF_AUTODELETE_MEDIA_ID, -1);
if (mediaId != -1) {
FeedManager manager = FeedManager.getInstance();
FeedMedia media = manager.getFeedMedia(mediaId);
if (media != null) {
manager.autoDeleteIfPossible(this, media);
}
}
} else if (key.equals(PlaybackService.PREF_CURRENTLY_PLAYING_MEDIA)) {
long id = sharedPreferences.getLong(
PlaybackService.PREF_CURRENTLY_PLAYING_MEDIA,
PlaybackService.NO_MEDIA_PLAYING);
if (AppConfig.DEBUG)
Log.d(TAG, "Currently playing media set to " + id);
if (id != currentlyPlayingMediaId) {
currentlyPlayingMediaId = id;
}
}
}
public static float getLogicalDensity() {
return LOGICAL_DENSITY;
}
public static long getCurrentlyPlayingMediaId() {
return currentlyPlayingMediaId;
}
public boolean isLargeScreen() {
return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE
|| (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;

View File

@ -4,7 +4,7 @@ import java.lang.ref.SoftReference;
import java.util.Date;
import java.util.List;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.preferences.PlaybackPreferences;
/**
* Data Object for a XML message
@ -234,7 +234,7 @@ public class FeedItem extends FeedComponent {
private boolean isPlaying() {
if (media != null) {
if (PodcastApp.getCurrentlyPlayingMediaId() == media.getId()) {
if (PlaybackPreferences.getCurrentlyPlayingMedia() == media.getId()) {
return true;
}
}

View File

@ -20,6 +20,7 @@ import android.preference.PreferenceManager;
import android.util.Log;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.asynctask.DownloadStatus;
import de.danoeh.antennapod.preferences.PlaybackPreferences;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.service.PlaybackService;
import de.danoeh.antennapod.storage.DownloadRequestException;
@ -34,10 +35,10 @@ import de.danoeh.antennapod.util.comparator.PlaybackCompletionDateComparator;
import de.danoeh.antennapod.util.exception.MediaFileNotFoundException;
/**
* Singleton class that
* - provides access to all Feeds and FeedItems and to several lists of FeedItems.
* - provides methods for modifying the application's data
* - takes care of updating the information stored in the database when something is modified
* Singleton class that - provides access to all Feeds and FeedItems and to
* several lists of FeedItems. - provides methods for modifying the
* application's data - takes care of updating the information stored in the
* database when something is modified
*
* An instance of this class can be retrieved via getInstance().
* */
@ -153,11 +154,7 @@ public class FeedManager {
}
} catch (MediaFileNotFoundException e) {
e.printStackTrace();
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
final long lastPlayedId = prefs.getLong(
PlaybackService.PREF_LAST_PLAYED_ID, -1);
if (lastPlayedId == media.getId()) {
if (PlaybackPreferences.getLastPlayedId() == media.getId()) {
context.sendBroadcast(new Intent(
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
}
@ -179,14 +176,12 @@ public class FeedManager {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
final long lastPlayedId = prefs.getLong(
PlaybackService.PREF_LAST_PLAYED_ID, -1);
if (media.getId() == lastPlayedId) {
if (media.getId() == PlaybackPreferences.getLastPlayedId()) {
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(PlaybackService.PREF_LAST_IS_STREAM, true);
editor.putBoolean(PlaybackPreferences.PREF_LAST_IS_STREAM, true);
editor.commit();
}
if (lastPlayedId == media.getId()) {
if (PlaybackPreferences.getLastPlayedId() == media.getId()) {
context.sendBroadcast(new Intent(
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
}
@ -200,14 +195,12 @@ public class FeedManager {
public void deleteFeed(final Context context, final Feed feed) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context.getApplicationContext());
long lastPlayedFeed = prefs.getLong(
PlaybackService.PREF_LAST_PLAYED_FEED_ID, -1);
if (lastPlayedFeed == feed.getId()) {
if (PlaybackPreferences.getLastPlayedFeedId() == feed.getId()) {
context.sendBroadcast(new Intent(
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
SharedPreferences.Editor editor = prefs.edit();
editor.putLong(PlaybackService.PREF_LAST_PLAYED_ID, -1);
editor.putLong(PlaybackService.PREF_LAST_PLAYED_FEED_ID, -1);
editor.putLong(PlaybackPreferences.PREF_LAST_PLAYED_ID, -1);
editor.putLong(PlaybackPreferences.PREF_LAST_PLAYED_FEED_ID, -1);
editor.commit();
}
@ -717,22 +710,19 @@ public class FeedManager {
.getDefaultSharedPreferences(context
.getApplicationContext());
if (UserPreferences.isAutoDelete()) {
long lastPlayedId = prefs.getLong(
PlaybackService.PREF_LAST_PLAYED_ID, -1);
long autoDeleteId = prefs.getLong(
PlaybackService.PREF_AUTODELETE_MEDIA_ID, -1);
boolean playbackCompleted = prefs
.getBoolean(
PlaybackService.PREF_AUTO_DELETE_MEDIA_PLAYBACK_COMPLETED,
false);
if ((media.getId() != lastPlayedId)
&& ((media.getId() != autoDeleteId) || (media.getId() == autoDeleteId && playbackCompleted))) {
if ((media.getId() != PlaybackPreferences.getLastPlayedId())
&& ((media.getId() != PlaybackPreferences
.getAutoDeleteMediaId()) || (media.getId() == PlaybackPreferences
.getAutoDeleteMediaId() && PlaybackPreferences
.isAutoDeleteMediaPlaybackCompleted()))) {
if (AppConfig.DEBUG)
Log.d(TAG, "Performing auto-cleanup");
deleteFeedMedia(context, media);
SharedPreferences.Editor editor = prefs.edit();
editor.putLong(PlaybackService.PREF_AUTODELETE_MEDIA_ID, -1);
editor.putLong(
PlaybackPreferences.PREF_AUTODELETE_MEDIA_ID, -1);
editor.commit();
} else {
if (AppConfig.DEBUG)
@ -1456,8 +1446,8 @@ public class FeedManager {
}
/**
* Searches the 'contentEncoded' field of FeedItems of a specific feed for a given
* string.
* Searches the 'contentEncoded' field of FeedItems of a specific feed for a
* given string.
*
* @param feed
* The feed whose items should be searched.

View File

@ -0,0 +1,173 @@
package de.danoeh.antennapod.preferences;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.feed.FeedMedia;
/**
* Provides access to preferences set by the playback service. A private
* 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";
/** Contains the id of the media that was played last. */
public static final String PREF_LAST_PLAYED_ID = "de.danoeh.antennapod.preferences.lastPlayedId";
/** Contains the feed id of the last played item. */
public static final String PREF_LAST_PLAYED_FEED_ID = "de.danoeh.antennapod.preferences.lastPlayedFeedId";
/**
* ID 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 streamed. */
public static final String PREF_LAST_IS_STREAM = "de.danoeh.antennapod.preferences.lastIsStream";
/** True if last played media was a video. */
public static final String PREF_LAST_IS_VIDEO = "de.danoeh.antennapod.preferences.lastIsVideo";
/** True if playback of last played media has been completed. */
public static final String PREF_AUTO_DELETE_MEDIA_PLAYBACK_COMPLETED = "de.danoeh.antennapod.preferences.lastPlaybackCompleted";
/**
* ID of the last played media which should be auto-deleted as soon as
* PREF_LAST_PLAYED_ID changes.
*/
public static final String PREF_AUTODELETE_MEDIA_ID = "de.danoeh.antennapod.preferences.autoDeleteMediaId";
/** Value of PREF_CURRENTLY_PLAYING_MEDIA if no media is playing. */
public static final long NO_MEDIA_PLAYING = -1;
private long lastPlayedId;
private long lastPlayedFeedId;
private long currentlyPlayingMedia;
private boolean lastIsStream;
private boolean lastIsVideo;
private boolean autoDeleteMediaPlaybackCompleted;
private long autoDeleteMediaId;
private static PlaybackPreferences instance;
private Context context;
private PlaybackPreferences(Context context) {
this.context = context;
loadPreferences();
}
/**
* Sets up the UserPreferences class.
*
* @throws IllegalArgumentException
* if context is null
* */
public static void createInstance(Context context) {
if (AppConfig.DEBUG)
Log.d(TAG, "Creating new instance of UserPreferences");
if (context == null)
throw new IllegalArgumentException("Context must not be null");
instance = new PlaybackPreferences(context);
PreferenceManager.getDefaultSharedPreferences(context)
.registerOnSharedPreferenceChangeListener(instance);
}
private void loadPreferences() {
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(context);
lastPlayedId = sp.getLong(PREF_LAST_PLAYED_ID, -1);
lastPlayedFeedId = sp.getLong(PREF_LAST_PLAYED_FEED_ID, -1);
currentlyPlayingMedia = sp.getLong(PREF_CURRENTLY_PLAYING_MEDIA,
NO_MEDIA_PLAYING);
lastIsStream = sp.getBoolean(PREF_LAST_IS_STREAM, true);
lastIsVideo = sp.getBoolean(PREF_LAST_IS_VIDEO, false);
autoDeleteMediaPlaybackCompleted = sp.getBoolean(
PREF_AUTO_DELETE_MEDIA_PLAYBACK_COMPLETED, false);
autoDeleteMediaId = sp.getLong(PREF_AUTODELETE_MEDIA_ID, -1);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sp, String key) {
if (key.equals(PREF_LAST_PLAYED_ID)) {
lastPlayedId = sp.getLong(PREF_LAST_PLAYED_ID, -1);
long mediaId = sp.getLong(
PlaybackPreferences.PREF_AUTODELETE_MEDIA_ID, -1);
if (mediaId != -1) {
FeedManager manager = FeedManager.getInstance();
FeedMedia media = manager.getFeedMedia(mediaId);
if (media != null) {
manager.autoDeleteIfPossible(context, media);
}
}
} else if (key.equals(PREF_LAST_PLAYED_FEED_ID)) {
lastPlayedFeedId = sp.getLong(PREF_LAST_PLAYED_FEED_ID, -1);
} else if (key.equals(PREF_CURRENTLY_PLAYING_MEDIA)) {
currentlyPlayingMedia = sp
.getLong(PREF_CURRENTLY_PLAYING_MEDIA, -1);
} else if (key.equals(PREF_LAST_IS_STREAM)) {
lastIsStream = sp.getBoolean(PREF_LAST_IS_STREAM, true);
} else if (key.equals(PREF_LAST_IS_VIDEO)) {
lastIsVideo = sp.getBoolean(PREF_LAST_IS_VIDEO, false);
} else if (key.equals(PREF_AUTO_DELETE_MEDIA_PLAYBACK_COMPLETED)) {
autoDeleteMediaPlaybackCompleted = sp.getBoolean(
PREF_AUTODELETE_MEDIA_ID, false);
} else if (key.equals(PREF_AUTODELETE_MEDIA_ID)) {
autoDeleteMediaId = sp.getLong(PREF_AUTODELETE_MEDIA_ID, -1);
}
}
private static void instanceAvailable() {
if (instance == null) {
throw new IllegalStateException(
"UserPreferences was used before being set up");
}
}
public static long getLastPlayedId() {
instanceAvailable();
return instance.lastPlayedId;
}
public static long getAutoDeleteMediaId() {
return instance.autoDeleteMediaId;
}
public static long getLastPlayedFeedId() {
instanceAvailable();
return instance.lastPlayedFeedId;
}
public static long getCurrentlyPlayingMedia() {
instanceAvailable();
return instance.currentlyPlayingMedia;
}
public static boolean isLastIsStream() {
instanceAvailable();
return instance.lastIsStream;
}
public static boolean isLastIsVideo() {
instanceAvailable();
return instance.lastIsVideo;
}
public static boolean isAutoDeleteMediaPlaybackCompleted() {
instanceAvailable();
return instance.autoDeleteMediaPlaybackCompleted;
}
}

View File

@ -45,6 +45,7 @@ import de.danoeh.antennapod.feed.FeedItem;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.feed.FeedMedia;
import de.danoeh.antennapod.feed.MediaType;
import de.danoeh.antennapod.preferences.PlaybackPreferences;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.receiver.MediaButtonReceiver;
import de.danoeh.antennapod.receiver.PlayerWidget;
@ -56,28 +57,6 @@ public class PlaybackService extends Service {
/** Logging tag */
private static final String TAG = "PlaybackService";
/** Contains the id of the media that was played last. */
public static final String PREF_LAST_PLAYED_ID = "de.danoeh.antennapod.preferences.lastPlayedId";
/** Contains the feed id of the last played item. */
public static final String PREF_LAST_PLAYED_FEED_ID = "de.danoeh.antennapod.preferences.lastPlayedFeedId";
/**
* ID 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 streamed. */
public static final String PREF_LAST_IS_STREAM = "de.danoeh.antennapod.preferences.lastIsStream";
/** True if last played media was a video. */
public static final String PREF_LAST_IS_VIDEO = "de.danoeh.antennapod.preferences.lastIsVideo";
/** True if playback of last played media has been completed. */
public static final String PREF_AUTO_DELETE_MEDIA_PLAYBACK_COMPLETED = "de.danoeh.antennapod.preferences.lastPlaybackCompleted";
/**
* ID of the last played media which should be auto-deleted as soon as
* PREF_LAST_PLAYED_ID changes.
*/
public static final String PREF_AUTODELETE_MEDIA_ID = "de.danoeh.antennapod.preferences.autoDeleteMediaId";
/** Contains the id of the FeedMedia object. */
public static final String EXTRA_MEDIA_ID = "extra.de.danoeh.antennapod.service.mediaId";
/** Contains the id of the Feed object of the FeedMedia. */
@ -166,9 +145,6 @@ public class PlaybackService extends Service {
/** True if mediaplayer was paused because it lost audio focus temporarily */
private boolean pausedBecauseOfTransientAudiofocusLoss;
/** Value of PREF_CURRENTLY_PLAYING_MEDIA if no media is playing. */
public static final long NO_MEDIA_PLAYING = -1;
private final IBinder mBinder = new LocalBinder();
public class LocalBinder extends Binder {
@ -197,11 +173,7 @@ public class PlaybackService extends Service {
return new Intent(context, AudioplayerActivity.class);
}
} else {
SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(context
.getApplicationContext());
boolean isVideo = pref.getBoolean(PREF_LAST_IS_VIDEO, false);
if (isVideo) {
if (PlaybackPreferences.isLastIsVideo()) {
return new Intent(context, VideoplayerActivity.class);
} else {
return new Intent(context, AudioplayerActivity.class);
@ -227,9 +199,8 @@ public class PlaybackService extends Service {
public static FeedMedia getLastPlayedMediaFromPreferences(Context context) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context.getApplicationContext());
long mediaId = prefs.getLong(PlaybackService.PREF_LAST_PLAYED_ID, -1);
long feedId = prefs.getLong(PlaybackService.PREF_LAST_PLAYED_FEED_ID,
-1);
long mediaId = PlaybackPreferences.getLastPlayedId();
long feedId = PlaybackPreferences.getLastPlayedFeedId();
FeedManager manager = FeedManager.getInstance();
if (mediaId != -1 && feedId != -1) {
Feed feed = manager.getFeed(feedId);
@ -243,12 +214,14 @@ public class PlaybackService extends Service {
private void setLastPlayedMediaId(long mediaId) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
long autoDeleteId = prefs.getLong(PREF_AUTODELETE_MEDIA_ID, -1);
long autoDeleteId = PlaybackPreferences.getAutoDeleteMediaId();
SharedPreferences.Editor editor = prefs.edit();
if (mediaId == autoDeleteId) {
editor.putBoolean(PREF_AUTO_DELETE_MEDIA_PLAYBACK_COMPLETED, false);
editor.putBoolean(
PlaybackPreferences.PREF_AUTO_DELETE_MEDIA_PLAYBACK_COMPLETED,
false);
}
editor.putLong(PREF_LAST_PLAYED_ID, mediaId);
editor.putLong(PlaybackPreferences.PREF_LAST_PLAYED_ID, mediaId);
editor.commit();
}
@ -675,7 +648,7 @@ public class PlaybackService extends Service {
pause(true, true);
}
sendNotificationBroadcast(NOTIFICATION_TYPE_ERROR, what);
setCurrentlyPlayingMedia(NO_MEDIA_PLAYING);
setCurrentlyPlayingMedia(PlaybackPreferences.NO_MEDIA_PLAYING);
stopSelf();
return true;
}
@ -711,13 +684,18 @@ public class PlaybackService extends Service {
autoDeleteMediaId = -1;
}
SharedPreferences.Editor editor = prefs.edit();
editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA, NO_MEDIA_PLAYING);
editor.putLong(PREF_AUTODELETE_MEDIA_ID, autoDeleteMediaId);
editor.putBoolean(PREF_AUTO_DELETE_MEDIA_PLAYBACK_COMPLETED, true);
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_MEDIA,
PlaybackPreferences.NO_MEDIA_PLAYING);
editor.putLong(PlaybackPreferences.PREF_AUTODELETE_MEDIA_ID,
autoDeleteMediaId);
editor.putBoolean(
PlaybackPreferences.PREF_AUTO_DELETE_MEDIA_PLAYBACK_COMPLETED,
true);
editor.commit();
// Prepare for playing next item
boolean playNextItem = isInQueue && UserPreferences.isFollowQueue() && nextItem != null;
boolean playNextItem = isInQueue && UserPreferences.isFollowQueue()
&& nextItem != null;
if (playNextItem) {
if (AppConfig.DEBUG)
Log.d(TAG, "Loading next item in queue");
@ -813,7 +791,7 @@ public class PlaybackService extends Service {
if (AppConfig.DEBUG)
Log.d(TAG, "Stopping playback");
player.stop();
setCurrentlyPlayingMedia(NO_MEDIA_PLAYING);
setCurrentlyPlayingMedia(PlaybackPreferences.NO_MEDIA_PLAYING);
stopSelf();
}
@ -854,10 +832,10 @@ public class PlaybackService extends Service {
SharedPreferences.Editor editor = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext())
.edit();
editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA, media.getId());
editor.putLong(PREF_LAST_PLAYED_FEED_ID, feed.getId());
editor.putBoolean(PREF_LAST_IS_STREAM, shouldStream);
editor.putBoolean(PREF_LAST_IS_VIDEO, playingVideo);
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_MEDIA, media.getId());
editor.putLong(PlaybackPreferences.PREF_LAST_PLAYED_FEED_ID, feed.getId());
editor.putBoolean(PlaybackPreferences.PREF_LAST_IS_STREAM, shouldStream);
editor.putBoolean(PlaybackPreferences.PREF_LAST_IS_VIDEO, playingVideo);
editor.commit();
setLastPlayedMediaId(media.getId());
player.start();
@ -1340,7 +1318,7 @@ public class PlaybackService extends Service {
private void setCurrentlyPlayingMedia(long id) {
SharedPreferences.Editor editor = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext()).edit();
editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA, id);
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_MEDIA, id);
editor.commit();
}
}

View File

@ -30,6 +30,7 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.feed.Chapter;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.feed.FeedMedia;
import de.danoeh.antennapod.preferences.PlaybackPreferences;
import de.danoeh.antennapod.service.PlaybackService;
import de.danoeh.antennapod.service.PlayerStatus;
@ -185,9 +186,8 @@ public abstract class PlaybackController {
Log.d(TAG, "Trying to restore last played media");
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(activity.getApplicationContext());
long mediaId = prefs.getLong(PlaybackService.PREF_LAST_PLAYED_ID, -1);
long feedId = prefs.getLong(PlaybackService.PREF_LAST_PLAYED_FEED_ID,
-1);
long mediaId = PlaybackPreferences.getLastPlayedId();
long feedId = PlaybackPreferences.getLastPlayedFeedId();
if (mediaId != -1 && feedId != -1) {
FeedMedia media = FeedManager.getInstance().getFeedMedia(mediaId);
if (media != null) {
@ -200,8 +200,7 @@ public abstract class PlaybackController {
serviceIntent.putExtra(
PlaybackService.EXTRA_PREPARE_IMMEDIATELY, false);
boolean fileExists = media.fileExists();
boolean lastIsStream = prefs.getBoolean(
PlaybackService.PREF_LAST_IS_STREAM, true);
boolean lastIsStream = PlaybackPreferences.isLastIsStream();
if (!fileExists && !lastIsStream) {
FeedManager.getInstance().notifyMissingFeedMediaFile(
activity, media);