diff options
author | ByteHamster <info@bytehamster.com> | 2020-03-15 17:28:34 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-03-15 23:51:25 +0100 |
commit | a9d93c90749f463a2f2cba7481084e2ef1d814d5 (patch) | |
tree | 8e21406a72ae17590198261183ba880a225bf966 /core/src | |
parent | 03d1f41e9bd88e1920be306ef8bcd10642ce5527 (diff) | |
download | AntennaPod-a9d93c90749f463a2f2cba7481084e2ef1d814d5.zip |
Fixed error message when file was deleted
Diffstat (limited to 'core/src')
3 files changed, 27 insertions, 74 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/event/FeedItemEvent.java b/core/src/main/java/de/danoeh/antennapod/core/event/FeedItemEvent.java index 89ecf271b..4b14a72d2 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/event/FeedItemEvent.java +++ b/core/src/main/java/de/danoeh/antennapod/core/event/FeedItemEvent.java @@ -30,12 +30,16 @@ public class FeedItemEvent { return new FeedItemEvent(Action.DELETE_MEDIA, items); } + public static FeedItemEvent deletedMedia(FeedItem... items) { + return deletedMedia(Arrays.asList(items)); + } + public static FeedItemEvent updated(List<FeedItem> items) { return new FeedItemEvent(Action.UPDATE, items); } public static FeedItemEvent updated(FeedItem... items) { - return new FeedItemEvent(Action.UPDATE, Arrays.asList(items)); + return updated(Arrays.asList(items)); } @Override diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java index 8ebe18dc0..5b7e62964 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java @@ -6,9 +6,22 @@ import android.database.Cursor; import android.os.Looper; import android.text.TextUtils; import android.util.Log; - import androidx.annotation.VisibleForTesting; - +import de.danoeh.antennapod.core.ClientConfig; +import de.danoeh.antennapod.core.R; +import de.danoeh.antennapod.core.event.FeedItemEvent; +import de.danoeh.antennapod.core.event.FeedListUpdateEvent; +import de.danoeh.antennapod.core.event.MessageEvent; +import de.danoeh.antennapod.core.feed.Feed; +import de.danoeh.antennapod.core.feed.FeedItem; +import de.danoeh.antennapod.core.feed.FeedMedia; +import de.danoeh.antennapod.core.feed.FeedPreferences; +import de.danoeh.antennapod.core.preferences.UserPreferences; +import de.danoeh.antennapod.core.service.GpodnetSyncService; +import de.danoeh.antennapod.core.service.download.DownloadStatus; +import de.danoeh.antennapod.core.util.DownloadError; +import de.danoeh.antennapod.core.util.LongList; +import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator; import org.greenrobot.eventbus.EventBus; import java.util.ArrayList; @@ -24,23 +37,6 @@ import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.atomic.AtomicBoolean; -import de.danoeh.antennapod.core.ClientConfig; -import de.danoeh.antennapod.core.event.FeedListUpdateEvent; -import de.danoeh.antennapod.core.feed.Feed; -import de.danoeh.antennapod.core.feed.FeedItem; -import de.danoeh.antennapod.core.feed.FeedMedia; -import de.danoeh.antennapod.core.feed.FeedPreferences; -import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.core.service.GpodnetSyncService; -import de.danoeh.antennapod.core.service.download.DownloadStatus; -import de.danoeh.antennapod.core.service.playback.PlaybackService; -import de.danoeh.antennapod.core.util.DownloadError; -import de.danoeh.antennapod.core.util.IntentUtils; -import de.danoeh.antennapod.core.util.LongList; -import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator; -import de.danoeh.antennapod.core.util.exception.MediaFileNotFoundException; -import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter; - import static android.content.Context.MODE_PRIVATE; /** @@ -100,53 +96,6 @@ public final class DBTasks { } } - /** - * Starts playback of a FeedMedia object's file. This method will build an Intent based on the given parameters to - * start the {@link PlaybackService}. - * - * @param context Used for sending starting Services and Activities. - * @param media The FeedMedia object. - * @param showPlayer If true, starts the appropriate player activity ({@link de.danoeh.antennapod.activity.AudioplayerActivity} - * or {@link de.danoeh.antennapod.activity.VideoplayerActivity} - * @param startWhenPrepared Parameter for the {@link PlaybackService} start intent. If true, playback will start as - * soon as the PlaybackService has finished loading the FeedMedia object's file. - * @param shouldStream Parameter for the {@link PlaybackService} start intent. If true, the FeedMedia object's file - * will be streamed, otherwise the downloaded file will be used. If the downloaded file cannot be - * found, the PlaybackService will shutdown and the database entry of the FeedMedia object will be - * corrected. - */ - public static void playMedia(final Context context, final FeedMedia media, - boolean showPlayer, boolean startWhenPrepared, boolean shouldStream) { - try { - if (!shouldStream) { - if (!media.fileExists()) { - throw new MediaFileNotFoundException( - "No episode was found at " + media.getFile_url(), - media); - } - } - - new PlaybackServiceStarter(context, media) - .callEvenIfRunning(true) - .startWhenPrepared(startWhenPrepared) - .shouldStream(shouldStream) - .start(); - - if (showPlayer) { - // Launch media player - context.startActivity(PlaybackService.getPlayerActivityIntent( - context, media)); - } - DBWriter.addQueueItemAt(context, media.getItem().getId(), 0, false); - } catch (MediaFileNotFoundException e) { - e.printStackTrace(); - if (media.isPlaying()) { - IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE); - } - notifyMissingFeedMediaFile(context, media); - } - } - private static final AtomicBoolean isRefreshing = new AtomicBoolean(false); /** @@ -293,17 +242,16 @@ public final class DBTasks { } /** - * Notifies the database about a missing FeedMedia file. This method will correct the FeedMedia object's values in the - * DB and send a FeedUpdateBroadcast. + * Notifies the database about a missing FeedMedia file. This method will correct the FeedMedia object's + * values in the DB and send a FeedItemEvent. */ - public static void notifyMissingFeedMediaFile(final Context context, - final FeedMedia media) { - Log.i(TAG, - "The feedmanager was notified about a missing episode. It will update its database now."); + public static void notifyMissingFeedMediaFile(final Context context, final FeedMedia media) { + Log.i(TAG, "The feedmanager was notified about a missing episode. It will update its database now."); media.setDownloaded(false); media.setFile_url(null); DBWriter.setFeedMedia(media); - EventBus.getDefault().post(new FeedListUpdateEvent(media.getItem().getFeed())); + EventBus.getDefault().post(FeedItemEvent.deletedMedia(media.getItem())); + EventBus.getDefault().post(new MessageEvent(context.getString(R.string.error_file_not_found))); } @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index bbdcb912e..7dee73805 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -289,6 +289,7 @@ <string name="player_buffering_msg">Buffering</string> <string name="player_go_to_picture_in_picture">Picture-in-picture mode</string> <string name="unknown_media_key">AntennaPod - Unknown media key: %1$d</string> + <string name="error_file_not_found">File not found</string> <!-- Queue operations --> <string name="lock_queue">Lock Queue</string> |