Use separate preference for currently playing media, reset after
playback has completed
This commit is contained in:
parent
c9fabb6e03
commit
8c541fb82d
@ -42,7 +42,7 @@ public class PodcastApp extends Application implements
|
|||||||
|
|
||||||
private boolean displayOnlyEpisodes;
|
private boolean displayOnlyEpisodes;
|
||||||
|
|
||||||
private static long lastPlayedMediaId;
|
private static long currentlyPlayingMediaId;
|
||||||
|
|
||||||
public static PodcastApp getInstance() {
|
public static PodcastApp getInstance() {
|
||||||
return singleton;
|
return singleton;
|
||||||
@ -55,8 +55,11 @@ public class PodcastApp extends Application implements
|
|||||||
LOGICAL_DENSITY = getResources().getDisplayMetrics().density;
|
LOGICAL_DENSITY = getResources().getDisplayMetrics().density;
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = PreferenceManager
|
||||||
.getDefaultSharedPreferences(this);
|
.getDefaultSharedPreferences(this);
|
||||||
displayOnlyEpisodes = prefs.getBoolean(PREF_DISPLAY_ONLY_EPISODES, false);
|
displayOnlyEpisodes = prefs.getBoolean(PREF_DISPLAY_ONLY_EPISODES,
|
||||||
lastPlayedMediaId = prefs.getLong(PlaybackService.PREF_LAST_PLAYED_ID, -1);
|
false);
|
||||||
|
currentlyPlayingMediaId = prefs.getLong(
|
||||||
|
PlaybackService.PREF_CURRENTLY_PLAYING_MEDIA,
|
||||||
|
PlaybackService.NO_MEDIA_PLAYING);
|
||||||
createImportDirectory();
|
createImportDirectory();
|
||||||
createNoMediaFile();
|
createNoMediaFile();
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
@ -74,7 +77,8 @@ public class PodcastApp extends Application implements
|
|||||||
Log.e(TAG, "Could not create .nomedia file");
|
Log.e(TAG, "Could not create .nomedia file");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (AppConfig.DEBUG) Log.d(TAG, ".nomedia file created");
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, ".nomedia file created");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,15 +137,15 @@ public class PodcastApp extends Application implements
|
|||||||
Log.d(TAG, "Automatic update was deactivated");
|
Log.d(TAG, "Automatic update was deactivated");
|
||||||
}
|
}
|
||||||
} else if (key.equals(PREF_DISPLAY_ONLY_EPISODES)) {
|
} else if (key.equals(PREF_DISPLAY_ONLY_EPISODES)) {
|
||||||
if (AppConfig.DEBUG) Log.d(TAG, "PREF_DISPLAY_ONLY_EPISODES changed");
|
if (AppConfig.DEBUG)
|
||||||
displayOnlyEpisodes = sharedPreferences.getBoolean(PREF_DISPLAY_ONLY_EPISODES, false);
|
Log.d(TAG, "PREF_DISPLAY_ONLY_EPISODES changed");
|
||||||
|
displayOnlyEpisodes = sharedPreferences.getBoolean(
|
||||||
|
PREF_DISPLAY_ONLY_EPISODES, false);
|
||||||
} else if (key.equals(PlaybackService.PREF_LAST_PLAYED_ID)) {
|
} else if (key.equals(PlaybackService.PREF_LAST_PLAYED_ID)) {
|
||||||
if (AppConfig.DEBUG) Log.d(TAG, "PREF_LAST_PLAYED_ID changed");
|
if (AppConfig.DEBUG)
|
||||||
long mediaId = sharedPreferences.getLong(PlaybackService.PREF_AUTODELETE_MEDIA_ID, -1);
|
Log.d(TAG, "PREF_LAST_PLAYED_ID changed");
|
||||||
long lastPlayedId = sharedPreferences.getLong(PlaybackService.PREF_LAST_PLAYED_ID, -1);
|
long mediaId = sharedPreferences.getLong(
|
||||||
if (lastPlayedId != lastPlayedMediaId) {
|
PlaybackService.PREF_AUTODELETE_MEDIA_ID, -1);
|
||||||
lastPlayedMediaId = lastPlayedId;
|
|
||||||
}
|
|
||||||
if (mediaId != -1) {
|
if (mediaId != -1) {
|
||||||
FeedManager manager = FeedManager.getInstance();
|
FeedManager manager = FeedManager.getInstance();
|
||||||
FeedMedia media = manager.getFeedMedia(mediaId);
|
FeedMedia media = manager.getFeedMedia(mediaId);
|
||||||
@ -149,6 +153,15 @@ public class PodcastApp extends Application implements
|
|||||||
manager.autoDeleteIfPossible(this, media);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,12 +173,13 @@ public class PodcastApp extends Application implements
|
|||||||
return displayOnlyEpisodes;
|
return displayOnlyEpisodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getLastPlayedMediaId() {
|
public static long getCurrentlyPlayingMediaId() {
|
||||||
return lastPlayedMediaId;
|
return currentlyPlayingMediaId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLargeScreen() {
|
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;
|
return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE
|
||||||
|
|| (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ public class FeedItem extends FeedComponent {
|
|||||||
|
|
||||||
public boolean isPlaying() {
|
public boolean isPlaying() {
|
||||||
if (media != null) {
|
if (media != null) {
|
||||||
if (PodcastApp.getLastPlayedMediaId() == media.getId()) {
|
if (PodcastApp.getCurrentlyPlayingMediaId() == media.getId()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,12 @@ public class PlaybackService extends Service {
|
|||||||
public static final String PREF_LAST_PLAYED_ID = "de.danoeh.antennapod.preferences.lastPlayedId";
|
public static final String PREF_LAST_PLAYED_ID = "de.danoeh.antennapod.preferences.lastPlayedId";
|
||||||
/** Contains the feed id of the last played item. */
|
/** Contains the feed id of the last played item. */
|
||||||
public static final String PREF_LAST_PLAYED_FEED_ID = "de.danoeh.antennapod.preferences.lastPlayedFeedId";
|
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. */
|
/** True if last played media was streamed. */
|
||||||
public static final String PREF_LAST_IS_STREAM = "de.danoeh.antennapod.preferences.lastIsStream";
|
public static final String PREF_LAST_IS_STREAM = "de.danoeh.antennapod.preferences.lastIsStream";
|
||||||
/** True if last played media was a video. */
|
/** True if last played media was a video. */
|
||||||
@ -159,6 +165,9 @@ public class PlaybackService extends Service {
|
|||||||
/** True if mediaplayer was paused because it lost audio focus temporarily */
|
/** True if mediaplayer was paused because it lost audio focus temporarily */
|
||||||
private boolean pausedBecauseOfTransientAudiofocusLoss;
|
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();
|
private final IBinder mBinder = new LocalBinder();
|
||||||
|
|
||||||
public class LocalBinder extends Binder {
|
public class LocalBinder extends Binder {
|
||||||
@ -657,6 +666,7 @@ public class PlaybackService extends Service {
|
|||||||
pause(true, true);
|
pause(true, true);
|
||||||
}
|
}
|
||||||
sendNotificationBroadcast(NOTIFICATION_TYPE_ERROR, what);
|
sendNotificationBroadcast(NOTIFICATION_TYPE_ERROR, what);
|
||||||
|
setCurrentlyPlayingMedia(NO_MEDIA_PLAYING);
|
||||||
stopSelf();
|
stopSelf();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -692,6 +702,7 @@ public class PlaybackService extends Service {
|
|||||||
autoDeleteMediaId = -1;
|
autoDeleteMediaId = -1;
|
||||||
}
|
}
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA, NO_MEDIA_PLAYING);
|
||||||
editor.putLong(PREF_AUTODELETE_MEDIA_ID, autoDeleteMediaId);
|
editor.putLong(PREF_AUTODELETE_MEDIA_ID, autoDeleteMediaId);
|
||||||
editor.putBoolean(PREF_AUTO_DELETE_MEDIA_PLAYBACK_COMPLETED, true);
|
editor.putBoolean(PREF_AUTO_DELETE_MEDIA_PLAYBACK_COMPLETED, true);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
@ -794,6 +805,7 @@ public class PlaybackService extends Service {
|
|||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Stopping playback");
|
Log.d(TAG, "Stopping playback");
|
||||||
player.stop();
|
player.stop();
|
||||||
|
setCurrentlyPlayingMedia(NO_MEDIA_PLAYING);
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -834,6 +846,7 @@ public class PlaybackService extends Service {
|
|||||||
SharedPreferences.Editor editor = PreferenceManager
|
SharedPreferences.Editor editor = PreferenceManager
|
||||||
.getDefaultSharedPreferences(getApplicationContext())
|
.getDefaultSharedPreferences(getApplicationContext())
|
||||||
.edit();
|
.edit();
|
||||||
|
editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA, media.getId());
|
||||||
editor.putLong(PREF_LAST_PLAYED_FEED_ID, feed.getId());
|
editor.putLong(PREF_LAST_PLAYED_FEED_ID, feed.getId());
|
||||||
editor.putBoolean(PREF_LAST_IS_STREAM, shouldStream);
|
editor.putBoolean(PREF_LAST_IS_STREAM, shouldStream);
|
||||||
editor.putBoolean(PREF_LAST_IS_VIDEO, playingVideo);
|
editor.putBoolean(PREF_LAST_IS_VIDEO, playingVideo);
|
||||||
@ -1262,4 +1275,9 @@ 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.commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user