Merge pull request #2314 from ByteHamster/delete-only-success

Check successful file deletion
This commit is contained in:
Martin Fietz 2017-10-15 21:39:34 +02:00 committed by GitHub
commit 5d8e820b82
2 changed files with 7 additions and 4 deletions

View File

@ -7,6 +7,8 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.event.MessageEvent;
import org.shredzone.flattr4j.model.Flattr;
import java.io.File;
@ -84,12 +86,13 @@ public class DBWriter {
if (media != null) {
Log.i(TAG, String.format("Requested to delete FeedMedia [id=%d, title=%s, downloaded=%s",
media.getId(), media.getEpisodeTitle(), String.valueOf(media.isDownloaded())));
boolean result = false;
if (media.isDownloaded()) {
// delete downloaded media file
File mediaFile = new File(media.getFile_url());
if (mediaFile.exists()) {
result = mediaFile.delete();
if (mediaFile.exists() && !mediaFile.delete()) {
MessageEvent evt = new MessageEvent(context.getString(R.string.delete_failed));
EventBus.getDefault().post(evt);
return;
}
media.setDownloaded(false);
media.setFile_url(null);
@ -129,7 +132,6 @@ public class DBWriter {
GpodnetPreferences.enqueueEpisodeAction(action);
}
}
Log.d(TAG, "Deleting File. Result: " + result);
EventBus.getDefault().post(FeedItemEvent.deletedMedia(Collections.singletonList(media.getItem())));
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
}

View File

@ -155,6 +155,7 @@
<string name="stream_label">Stream</string>
<string name="remove_label">Remove</string>
<string name="delete_label">Delete</string>
<string name="delete_failed">Unable to delete file. Rebooting the device could help.</string>
<string name="remove_episode_lable">Remove Episode</string>
<string name="marked_as_seen_label">Marked as seen</string>
<string name="mark_read_label">Mark as played</string>