diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java index 310b3023f..7839955dc 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java @@ -49,6 +49,7 @@ import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; +import java.io.File; import java.lang.ref.WeakReference; import java.util.HashSet; import java.util.Set; @@ -63,6 +64,7 @@ import de.luhmer.owncloudnewsreader.helper.ThemeUtils; import de.luhmer.owncloudnewsreader.model.PodcastItem; import de.luhmer.owncloudnewsreader.model.TTSItem; +import de.luhmer.owncloudnewsreader.services.PodcastDownloadService; import de.luhmer.owncloudnewsreader.view.PodcastSlidingUpPanelLayout; import de.luhmer.owncloudnewsreader.widget.WidgetProvider; @@ -90,6 +92,7 @@ public class NewsDetailActivity extends PodcastFragmentActivity { private int currentPosition; private MenuItem menuItem_PlayPodcast; + private MenuItem menuItem_RemovePodcast; private MenuItem menuItem_Starred; private MenuItem menuItem_Read; private MenuItem menuItem_Incognito; @@ -401,6 +404,11 @@ public void updateActionBarIcons() { menuItem_PlayPodcast.setVisible(podcastAvailable); } + if(menuItem_RemovePodcast != null) { + File file = new File(PodcastDownloadService.getUrlToPodcastFile(this, podcastItem.link, false)); + menuItem_RemovePodcast.setVisible(file.exists()); + } + if (menuItem_Starred != null) { int res = isStarred ? R.drawable.ic_star_24_theme_aware : R.drawable.ic_star_border_24dp_theme_aware; menuItem_Starred.setIcon(res); @@ -442,6 +450,7 @@ public boolean onCreateOptionsMenu(Menu menu) { menuItem_Starred = menu.findItem(R.id.action_starred); menuItem_Read = menu.findItem(R.id.action_read); menuItem_PlayPodcast = menu.findItem(R.id.action_playPodcast); + menuItem_RemovePodcast = menu.findItem(R.id.action_removePodcast); menuItem_Incognito = menu.findItem(R.id.action_incognito_mode); if (mShowFastActions) { @@ -493,6 +502,12 @@ public boolean onOptionsItemSelected(MenuItem item) { this.openInBrowser(currentPosition); } else if (itemId == R.id.action_playPodcast) { openPodcast(rssItem); + } else if (itemId == R.id.action_removePodcast) { + removePodcastMedia(rssItem, (result) -> { + if (menuItem_RemovePodcast != null) { + menuItem_RemovePodcast.setVisible(!result); + } + }); } else if (itemId == R.id.action_tts) { this.startTTS(currentPosition); } else if (itemId == R.id.action_ShareItem) { diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java index 76053600c..a1267b6e1 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java @@ -28,6 +28,7 @@ import org.greenrobot.eventbus.Subscribe; import java.io.File; +import java.util.function.Consumer; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -319,6 +320,35 @@ public void openPodcast(final RssItem rssItem) { } + public void removePodcastMedia(final RssItem rssItem, final Consumer callback) { + final PodcastItem podcastItem = DatabaseConnectionOrm.ParsePodcastItemFromRssItem(this, rssItem); + File file = new File(PodcastDownloadService.getUrlToPodcastFile(this, podcastItem.link, false)); + + if (!file.exists()) { + callback.accept(true); + } + + AlertDialog.Builder alertDialog = new AlertDialog.Builder(this) + .setNegativeButton("Remove", (dialogInterface, i) -> { + boolean success = file.delete() && file.getParentFile().delete(); // remove audio file and parent folder + if (!success) { + Toast.makeText(PodcastFragmentActivity.this, "Failed to remove media for \"" + podcastItem.title + "\"", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(PodcastFragmentActivity.this, "Media for \"" + podcastItem.title + "\" has been removed", Toast.LENGTH_SHORT).show(); + } + + callback.accept(success); + }) + .setNeutralButton("Cancel", (dialogInterface, i) -> { + callback.accept(false); + }) + .setTitle("Are you sure?") + .setMessage("Do you want to remove downloaded media for \"" + podcastItem.title + "?\""); + + alertDialog.show(); + } + + @Override public void pausePodcast() { MediaControllerCompat.getMediaController(PodcastFragmentActivity.this).getTransportControls().pause(); diff --git a/News-Android-App/src/main/res/drawable/ic_action_delete_24_theme_aware.xml b/News-Android-App/src/main/res/drawable/ic_action_delete_24_theme_aware.xml new file mode 100644 index 000000000..706763497 --- /dev/null +++ b/News-Android-App/src/main/res/drawable/ic_action_delete_24_theme_aware.xml @@ -0,0 +1,6 @@ + + + diff --git a/News-Android-App/src/main/res/menu/news_detail.xml b/News-Android-App/src/main/res/menu/news_detail.xml index b28f0f688..3150e84e9 100644 --- a/News-Android-App/src/main/res/menu/news_detail.xml +++ b/News-Android-App/src/main/res/menu/news_detail.xml @@ -28,6 +28,12 @@ android:icon="@drawable/ic_action_open_in_browser_24_theme_aware" android:title="@string/action_openInBrowser"/> + + Starred Read Play Podcast + Remove Podcast Media Open in Web browser Share Server Settings