Merge pull request #3352 from ByteHamster/delete-current-feed

Fixed deleting currently playing feed
This commit is contained in:
H. Lehmann 2019-08-31 14:03:56 +02:00 committed by GitHub
commit a0ee6a8ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 43 deletions

View File

@ -487,9 +487,6 @@ public class PlaybackService extends MediaBrowserServiceCompat {
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0);
//If the user asks to play External Media, the casting session, if on, should end.
flavorHelper.castDisconnect(playable instanceof ExternalMedia);
if (playable instanceof FeedMedia) {
playable = DBReader.getFeedMedia(((FeedMedia) playable).getId());
}
if (allowStreamAlways) {
UserPreferences.setAllowMobileStreaming(true);
}
@ -499,6 +496,14 @@ public class PlaybackService extends MediaBrowserServiceCompat {
stateManager.stopService();
return Service.START_NOT_STICKY;
}
if (playable instanceof FeedMedia) {
playable = DBReader.getFeedMedia(((FeedMedia) playable).getId());
}
if (playable == null) {
Log.d(TAG, "Playable was not found. Stopping service.");
stateManager.stopService();
return Service.START_NOT_STICKY;
}
mediaPlayer.playMediaObject(playable, stream, startWhenPrepared, prepareImmediately);
} else {
Log.d(TAG, "Did not handle intent to PlaybackService: " + intent);

View File

@ -831,15 +831,14 @@ public final class DBReader {
* Searches the DB for a FeedMedia of the given id.
*
* @param mediaId The id of the object
* @return The found object
* @return The found object, or null if it does not exist
*/
@Nullable
public static FeedMedia getFeedMedia(final long mediaId) {
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
Cursor mediaCursor = null;
try {
mediaCursor = adapter.getSingleFeedMediaCursor(mediaId);
try (Cursor mediaCursor = adapter.getSingleFeedMediaCursor(mediaId)) {
if (!mediaCursor.moveToFirst()) {
return null;
}
@ -847,19 +846,13 @@ public final class DBReader {
int indexFeedItem = mediaCursor.getColumnIndex(PodDBAdapter.KEY_FEEDITEM);
long itemId = mediaCursor.getLong(indexFeedItem);
FeedMedia media = FeedMedia.fromCursor(mediaCursor);
if (media != null) {
FeedItem item = getFeedItem(itemId);
if (item != null) {
media.setItem(item);
item.setMedia(media);
}
FeedItem item = getFeedItem(itemId);
if (item != null) {
media.setItem(item);
item.setMedia(media);
}
return media;
} finally {
if (mediaCursor != null) {
mediaCursor.close();
}
adapter.close();
}
}

View File

@ -138,23 +138,9 @@ public class DBWriter {
public static Future<?> deleteFeed(final Context context, final long feedId) {
return dbExec.submit(() -> {
DownloadRequester requester = DownloadRequester.getInstance();
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context
.getApplicationContext());
final Feed feed = DBReader.getFeed(feedId);
if (feed != null) {
if (PlaybackPreferences.getCurrentlyPlayingMedia() == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA
&& PlaybackPreferences.getLastPlayedFeedId() == feed
.getId()) {
IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
SharedPreferences.Editor editor = prefs.edit();
editor.putLong(
PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID,
-1);
editor.commit();
}
// delete stored media files and mark them as read
List<FeedItem> queue = DBReader.getQueue();
List<FeedItem> removed = new ArrayList<>();
@ -163,19 +149,12 @@ public class DBWriter {
}
for (FeedItem item : feed.getItems()) {
if(queue.remove(item)) {
if (queue.remove(item)) {
removed.add(item);
}
if (item.getState() == FeedItem.State.PLAYING && PlaybackService.isRunning) {
context.stopService(new Intent(context, PlaybackService.class));
}
if (item.getMedia() != null
&& item.getMedia().isDownloaded()) {
File mediaFile = new File(item.getMedia()
.getFile_url());
mediaFile.delete();
} else if (item.getMedia() != null
&& requester.isDownloadingFile(item.getMedia())) {
if (item.getMedia() != null && item.getMedia().isDownloaded()) {
deleteFeedMediaSynchronous(context, item.getMedia());
} else if (item.getMedia() != null && requester.isDownloadingFile(item.getMedia())) {
requester.cancelDownload(context, item.getMedia());
}
}