Check if we are deleting an episode that is currently playing or paused

This commit is contained in:
Martin Fietz 2016-03-24 13:55:08 +01:00
parent 61e3d3b2a6
commit d9726d2543
1 changed files with 11 additions and 19 deletions

View File

@ -43,15 +43,13 @@ import de.danoeh.antennapod.core.event.ProgressEvent;
import de.danoeh.antennapod.core.event.QueueEvent; import de.danoeh.antennapod.core.event.QueueEvent;
import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.service.playback.PlayerStatus;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.core.util.StorageUtils;
import de.danoeh.antennapod.core.util.playback.Playable;
import de.danoeh.antennapod.core.util.playback.PlaybackController;
import de.danoeh.antennapod.dialog.RatingDialog; import de.danoeh.antennapod.dialog.RatingDialog;
import de.danoeh.antennapod.fragment.AddFeedFragment; import de.danoeh.antennapod.fragment.AddFeedFragment;
import de.danoeh.antennapod.fragment.DownloadsFragment; import de.danoeh.antennapod.fragment.DownloadsFragment;
@ -567,21 +565,15 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity
public void onConfirmButtonPressed( public void onConfirmButtonPressed(
DialogInterface dialog) { DialogInterface dialog) {
dialog.dismiss(); dialog.dismiss();
if (externalPlayerFragment != null) { long mediaId = PlaybackPreferences.getCurrentlyPlayingFeedMediaId();
PlaybackController controller = externalPlayerFragment.getPlaybackControllerTestingOnly(); if (mediaId > 0 &&
if (controller != null) { FeedItemUtil.indexOfItemWithMediaId(feed.getItems(), mediaId) >= 0) {
Playable playable = controller.getMedia(); Log.d(TAG, "Currently playing episode is about to be deleted, skipping");
if (playable != null && playable instanceof FeedMedia) { remover.skipOnCompletion = true;
FeedMedia media = (FeedMedia) playable; int playerStatus = PlaybackPreferences.getCurrentPlayerStatus();
if (media.getItem().getFeed().getId() == feed.getId()) { if(playerStatus == PlaybackPreferences.PLAYER_STATUS_PLAYING) {
Log.d(TAG, "Currently playing episode is about to be deleted, skipping"); sendBroadcast(new Intent(
remover.skipOnCompletion = true; PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
if(controller.getStatus() == PlayerStatus.PLAYING) {
sendBroadcast(new Intent(
PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
}
}
}
} }
} }
remover.executeAsync(); remover.executeAsync();