If removing currently playing episode, (pause and) skip the same
This commit is contained in:
parent
0aeb520f14
commit
2197e9b741
|
@ -45,11 +45,13 @@ import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
||||||
import de.danoeh.antennapod.core.feed.Chapter;
|
import de.danoeh.antennapod.core.feed.Chapter;
|
||||||
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.feed.MediaType;
|
import de.danoeh.antennapod.core.feed.MediaType;
|
||||||
import de.danoeh.antennapod.core.feed.SimpleChapter;
|
import de.danoeh.antennapod.core.feed.SimpleChapter;
|
||||||
import de.danoeh.antennapod.core.glide.ApGlideSettings;
|
import de.danoeh.antennapod.core.glide.ApGlideSettings;
|
||||||
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.playback.ExternalMedia;
|
import de.danoeh.antennapod.core.util.playback.ExternalMedia;
|
||||||
|
@ -742,6 +744,20 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
|
||||||
public void onConfirmButtonPressed(
|
public void onConfirmButtonPressed(
|
||||||
DialogInterface dialog) {
|
DialogInterface dialog) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
if (controller != null) {
|
||||||
|
Playable playable = controller.getMedia();
|
||||||
|
if (playable != null && playable instanceof FeedMedia) {
|
||||||
|
FeedMedia media = (FeedMedia) playable;
|
||||||
|
if (media.getItem().getFeed().getId() == feed.getId()) {
|
||||||
|
Log.d(TAG, "Currently playing episode is about to be deleted, skipping");
|
||||||
|
remover.skipOnCompletion = true;
|
||||||
|
if(controller.getStatus() == PlayerStatus.PLAYING) {
|
||||||
|
sendBroadcast(new Intent(
|
||||||
|
PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
remover.executeAsync();
|
remover.executeAsync();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,10 +44,16 @@ import de.danoeh.antennapod.core.event.ProgressEvent;
|
||||||
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.event.QueueEvent;
|
import de.danoeh.antennapod.core.event.QueueEvent;
|
||||||
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
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.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.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.fragment.AddFeedFragment;
|
import de.danoeh.antennapod.fragment.AddFeedFragment;
|
||||||
import de.danoeh.antennapod.fragment.DownloadsFragment;
|
import de.danoeh.antennapod.fragment.DownloadsFragment;
|
||||||
import de.danoeh.antennapod.fragment.EpisodesFragment;
|
import de.danoeh.antennapod.fragment.EpisodesFragment;
|
||||||
|
@ -558,6 +564,23 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
||||||
public void onConfirmButtonPressed(
|
public void onConfirmButtonPressed(
|
||||||
DialogInterface dialog) {
|
DialogInterface dialog) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
if (externalPlayerFragment != null) {
|
||||||
|
PlaybackController controller = externalPlayerFragment.getPlaybackControllerTestingOnly();
|
||||||
|
if (controller != null) {
|
||||||
|
Playable playable = controller.getMedia();
|
||||||
|
if (playable != null && playable instanceof FeedMedia) {
|
||||||
|
FeedMedia media = (FeedMedia) playable;
|
||||||
|
if (media.getItem().getFeed().getId() == feed.getId()) {
|
||||||
|
Log.d(TAG, "Currently playing episode is about to be deleted, skipping");
|
||||||
|
remover.skipOnCompletion = true;
|
||||||
|
if(controller.getStatus() == PlayerStatus.PLAYING) {
|
||||||
|
sendBroadcast(new Intent(
|
||||||
|
PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
remover.executeAsync();
|
remover.executeAsync();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -149,6 +149,7 @@ public class QueueFragment extends Fragment {
|
||||||
recyclerAdapter.notifyDataSetChanged();
|
recyclerAdapter.notifyDataSetChanged();
|
||||||
break;
|
break;
|
||||||
case REMOVED:
|
case REMOVED:
|
||||||
|
case IRREVERSIBLE_REMOVED:
|
||||||
int position = FeedItemUtil.indexOfItemWithId(queue, event.item.getId());
|
int position = FeedItemUtil.indexOfItemWithId(queue, event.item.getId());
|
||||||
queue.remove(position);
|
queue.remove(position);
|
||||||
recyclerAdapter.notifyItemRemoved(position);
|
recyclerAdapter.notifyItemRemoved(position);
|
||||||
|
|
|
@ -3,12 +3,14 @@ package de.danoeh.antennapod.core.asynctask;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.R;
|
import de.danoeh.antennapod.core.R;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
|
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
|
|
||||||
/** Removes a feed in the background. */
|
/** Removes a feed in the background. */
|
||||||
|
@ -16,6 +18,7 @@ public class FeedRemover extends AsyncTask<Void, Void, Void> {
|
||||||
Context context;
|
Context context;
|
||||||
ProgressDialog dialog;
|
ProgressDialog dialog;
|
||||||
Feed feed;
|
Feed feed;
|
||||||
|
public boolean skipOnCompletion = false;
|
||||||
|
|
||||||
public FeedRemover(Context context, Feed feed) {
|
public FeedRemover(Context context, Feed feed) {
|
||||||
super();
|
super();
|
||||||
|
@ -38,6 +41,10 @@ public class FeedRemover extends AsyncTask<Void, Void, Void> {
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void result) {
|
protected void onPostExecute(Void result) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
if(skipOnCompletion) {
|
||||||
|
context.sendBroadcast(new Intent(
|
||||||
|
PlaybackService.ACTION_SKIP_CURRENT_EPISODE));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -571,7 +571,7 @@ public class PlaybackService extends Service {
|
||||||
try {
|
try {
|
||||||
final List<FeedItem> queue = taskManager.getQueue();
|
final List<FeedItem> queue = taskManager.getQueue();
|
||||||
isInQueue = QueueAccess.ItemListAccess(queue).contains(item.getId());
|
isInQueue = QueueAccess.ItemListAccess(queue).contains(item.getId());
|
||||||
nextItem = DBTasks.getQueueSuccessorOfItem(this, item.getId(), queue);
|
nextItem = DBTasks.getQueueSuccessorOfItem(item.getId(), queue);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
// isInQueue remains false
|
// isInQueue remains false
|
||||||
|
|
|
@ -394,14 +394,12 @@ public final class DBTasks {
|
||||||
/**
|
/**
|
||||||
* Returns the successor of a FeedItem in the queue.
|
* Returns the successor of a FeedItem in the queue.
|
||||||
*
|
*
|
||||||
* @param context Used for accessing the DB.
|
|
||||||
* @param itemId ID of the FeedItem
|
* @param itemId ID of the FeedItem
|
||||||
* @param queue Used for determining the successor of the item. If this parameter is null, the method will load
|
* @param queue Used for determining the successor of the item. If this parameter is null, the method will load
|
||||||
* the queue from the database in the same thread.
|
* the queue from the database in the same thread.
|
||||||
* @return Successor of the FeedItem or null if the FeedItem is not in the queue or has no successor.
|
* @return Successor of the FeedItem or null if the FeedItem is not in the queue or has no successor.
|
||||||
*/
|
*/
|
||||||
public static FeedItem getQueueSuccessorOfItem(Context context,
|
public static FeedItem getQueueSuccessorOfItem(final long itemId, List<FeedItem> queue) {
|
||||||
final long itemId, List<FeedItem> queue) {
|
|
||||||
FeedItem result = null;
|
FeedItem result = null;
|
||||||
if (queue == null) {
|
if (queue == null) {
|
||||||
queue = DBReader.getQueue();
|
queue = DBReader.getQueue();
|
||||||
|
|
Loading…
Reference in New Issue