diff options
author | Matej Drobnič <matej@matejdro.com> | 2023-10-22 16:53:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-22 16:53:41 +0200 |
commit | 346365b8d0aef14e79da921056d9438fe9d2663e (patch) | |
tree | 5fa0082c45493ffa16ffd0a63a3db722fd3206a1 /app/src/main | |
parent | fa75317bce95bdae152fa1171894d4c025e3921c (diff) | |
download | AntennaPod-346365b8d0aef14e79da921056d9438fe9d2663e.zip |
Delete local feed episodes (#6400)
Diffstat (limited to 'app/src/main')
10 files changed, 100 insertions, 14 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DeleteActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DeleteActionButton.java index 096d060c1..16a5a161c 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DeleteActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DeleteActionButton.java @@ -4,10 +4,14 @@ import android.content.Context; import android.view.View; import androidx.annotation.DrawableRes; import androidx.annotation.StringRes; + +import java.util.Collections; + import de.danoeh.antennapod.R; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.view.LocalDeleteModal; public class DeleteActionButton extends ItemActionButton { @@ -33,11 +37,17 @@ public class DeleteActionButton extends ItemActionButton { if (media == null) { return; } - DBWriter.deleteFeedMediaOfItem(context, media.getId()); + + LocalDeleteModal.showLocalFeedDeleteWarningIfNecessary(context, Collections.singletonList(item), + () -> DBWriter.deleteFeedMediaOfItem(context, media.getId())); } @Override public int getVisibility() { - return (item.getMedia() != null && item.getMedia().isDownloaded()) ? View.VISIBLE : View.INVISIBLE; + if (item.getMedia() != null && (item.getMedia().isDownloaded() || item.getFeed().isLocalFeed())) { + return View.VISIBLE; + } + + return View.INVISIBLE; } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java index 6a72348bc..29be41727 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java @@ -197,8 +197,8 @@ public class AddFeedFragment extends Fragment { } private Feed addLocalFolder(Uri uri) { - getActivity().getContentResolver() - .takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); + getActivity().getContentResolver().takePersistableUriPermission(uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); DocumentFile documentFile = DocumentFile.fromTreeUri(getContext(), uri); if (documentFile == null) { throw new IllegalArgumentException("Unable to retrieve document tree"); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java index 6b6fedd1f..1c949218a 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -367,7 +367,6 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem swipeActions.detach(); if (feed.isLocalFeed()) { speedDialBinding.fabSD.removeActionItemById(R.id.download_batch); - speedDialBinding.fabSD.removeActionItemById(R.id.delete_batch); } speedDialBinding.fabSD.removeActionItemById(R.id.remove_all_inbox_item); speedDialBinding.fabSD.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java index 0e4c883cf..1df1e02a2 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java @@ -172,7 +172,6 @@ public class FeedSettingsFragment extends Fragment { if (feed.isLocalFeed()) { findPreference(PREF_AUTHENTICATION).setVisible(false); - findPreference(PREF_AUTO_DELETE).setVisible(false); findPreference(PREF_CATEGORY_AUTO_DOWNLOAD).setVisible(false); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/actions/EpisodeMultiSelectActionHandler.java b/app/src/main/java/de/danoeh/antennapod/fragment/actions/EpisodeMultiSelectActionHandler.java index a14bfcd16..618c411ea 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/actions/EpisodeMultiSelectActionHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/actions/EpisodeMultiSelectActionHandler.java @@ -14,6 +14,7 @@ import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterfa import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.model.feed.FeedItem; +import de.danoeh.antennapod.view.LocalDeleteModal; public class EpisodeMultiSelectActionHandler { private static final String TAG = "EpisodeSelectHandler"; @@ -41,7 +42,7 @@ public class EpisodeMultiSelectActionHandler { } else if (actionId == R.id.download_batch) { downloadChecked(items); } else if (actionId == R.id.delete_batch) { - deleteChecked(items); + LocalDeleteModal.showLocalFeedDeleteWarningIfNecessary(activity, items, () -> deleteChecked(items)); } else { Log.e(TAG, "Unrecognized speed dial action item. Do nothing. id=" + actionId); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/DownloadsPreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/DownloadsPreferencesFragment.java index 7b0c3efdf..c17066fef 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/DownloadsPreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/DownloadsPreferencesFragment.java @@ -2,8 +2,12 @@ package de.danoeh.antennapod.fragment.preferences; import android.content.SharedPreferences; import android.os.Bundle; + import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceManager; +import androidx.preference.TwoStatePreference; + +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.PreferenceActivity; import de.danoeh.antennapod.core.util.download.FeedUpdateManager; @@ -17,9 +21,12 @@ import java.io.File; public class DownloadsPreferencesFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { private static final String PREF_SCREEN_AUTODL = "prefAutoDownloadSettings"; + private static final String PREF_AUTO_DELETE_LOCAL = "prefAutoDeleteLocal"; private static final String PREF_PROXY = "prefProxy"; private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir"; + private boolean blockAutoDeleteLocal = true; + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.preferences_downloads); @@ -63,6 +70,14 @@ public class DownloadsPreferencesFragment extends PreferenceFragmentCompat }); return true; }); + findPreference(PREF_AUTO_DELETE_LOCAL).setOnPreferenceChangeListener((preference, newValue) -> { + if (blockAutoDeleteLocal && newValue == Boolean.TRUE) { + showAutoDeleteEnableDialog(); + return false; + } else { + return true; + } + }); } private void setDataFolderText() { @@ -78,4 +93,16 @@ public class DownloadsPreferencesFragment extends PreferenceFragmentCompat FeedUpdateManager.restartUpdateAlarm(getContext(), true); } } + + private void showAutoDeleteEnableDialog() { + new MaterialAlertDialogBuilder(requireContext()) + .setMessage(R.string.pref_auto_local_delete_dialog_body) + .setPositiveButton(R.string.yes, (dialog, which) -> { + blockAutoDeleteLocal = false; + ((TwoStatePreference) findPreference(PREF_AUTO_DELETE_LOCAL)).setChecked(true); + blockAutoDeleteLocal = true; + }) + .setNegativeButton(R.string.cancel_label, null) + .show(); + } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/DeleteSwipeAction.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/DeleteSwipeAction.java index a4c69eb2b..e196b96b4 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/DeleteSwipeAction.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/DeleteSwipeAction.java @@ -2,10 +2,14 @@ package de.danoeh.antennapod.fragment.swipeactions; import android.content.Context; import androidx.fragment.app.Fragment; + +import java.util.Collections; + import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedItemFilter; +import de.danoeh.antennapod.view.LocalDeleteModal; public class DeleteSwipeAction implements SwipeAction { @@ -31,14 +35,16 @@ public class DeleteSwipeAction implements SwipeAction { @Override public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) { - if (!item.isDownloaded()) { + if (!item.isDownloaded() && !item.getFeed().isLocalFeed()) { return; } - DBWriter.deleteFeedMediaOfItem(fragment.requireContext(), item.getMedia().getId()); + LocalDeleteModal.showLocalFeedDeleteWarningIfNecessary( + fragment.requireContext(), Collections.singletonList(item), + () -> DBWriter.deleteFeedMediaOfItem(fragment.requireContext(), item.getMedia().getId())); } @Override public boolean willRemove(FeedItemFilter filter, FeedItem item) { - return filter.showDownloaded && item.isDownloaded(); + return filter.showDownloaded && (item.isDownloaded() || item.getFeed().isLocalFeed()); } } diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java index de4cec8fe..a72b32497 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -12,10 +12,12 @@ import androidx.fragment.app.Fragment; import com.google.android.material.snackbar.Snackbar; +import java.util.Arrays; + import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; -import de.danoeh.antennapod.storage.preferences.UserPreferences; +import de.danoeh.antennapod.core.util.FeedUtil; import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface; import de.danoeh.antennapod.core.storage.DBWriter; @@ -29,6 +31,7 @@ import de.danoeh.antennapod.dialog.ShareDialog; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.net.sync.model.EpisodeAction; +import de.danoeh.antennapod.view.LocalDeleteModal; /** * Handles interactions with the FeedItemMenu. @@ -56,6 +59,7 @@ public class FeedItemMenuHandler { final boolean isPlaying = hasMedia && PlaybackStatus.isPlaying(selectedItem.getMedia()); final boolean isInQueue = selectedItem.isTagged(FeedItem.TAG_QUEUE); final boolean fileDownloaded = hasMedia && selectedItem.getMedia().fileExists(); + final boolean isLocalFile = hasMedia && selectedItem.getFeed().isLocalFeed(); final boolean isFavorite = selectedItem.isTagged(FeedItem.TAG_FAVORITE); setItemVisibility(menu, R.id.skip_episode_item, isPlaying); @@ -80,7 +84,7 @@ public class FeedItemMenuHandler { setItemVisibility(menu, R.id.add_to_favorites_item, !isFavorite); setItemVisibility(menu, R.id.remove_from_favorites_item, isFavorite); - setItemVisibility(menu, R.id.remove_item, fileDownloaded); + setItemVisibility(menu, R.id.remove_item, fileDownloaded || isLocalFile); return true; } @@ -148,7 +152,8 @@ public class FeedItemMenuHandler { if (menuItemId == R.id.skip_episode_item) { context.sendBroadcast(MediaButtonReceiver.createIntent(context, KeyEvent.KEYCODE_MEDIA_NEXT)); } else if (menuItemId == R.id.remove_item) { - DBWriter.deleteFeedMediaOfItem(context, selectedItem.getMedia().getId()); + LocalDeleteModal.showLocalFeedDeleteWarningIfNecessary(context, Arrays.asList(selectedItem), + () -> DBWriter.deleteFeedMediaOfItem(context, selectedItem.getMedia().getId())); } else if (menuItemId == R.id.remove_inbox_item) { removeNewFlagWithUndo(fragment, selectedItem); } else if (menuItemId == R.id.mark_read_item) { @@ -225,7 +230,8 @@ public class FeedItemMenuHandler { final Handler h = new Handler(fragment.requireContext().getMainLooper()); final Runnable r = () -> { FeedMedia media = item.getMedia(); - if (media != null && FeedItemUtil.hasAlmostEnded(media) && UserPreferences.isAutoDelete()) { + boolean shouldAutoDelete = FeedUtil.shouldAutoDeleteItemsOnThatFeed(item.getFeed()); + if (media != null && FeedItemUtil.hasAlmostEnded(media) && shouldAutoDelete) { DBWriter.deleteFeedMediaOfItem(fragment.requireContext(), media.getId()); } }; diff --git a/app/src/main/java/de/danoeh/antennapod/view/LocalDeleteModal.java b/app/src/main/java/de/danoeh/antennapod/view/LocalDeleteModal.java new file mode 100644 index 000000000..4241cadca --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/view/LocalDeleteModal.java @@ -0,0 +1,32 @@ +package de.danoeh.antennapod.view; + +import android.content.Context; + +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import de.danoeh.antennapod.ui.i18n.R; +import de.danoeh.antennapod.model.feed.FeedItem; + +public class LocalDeleteModal { + public static void showLocalFeedDeleteWarningIfNecessary(Context context, Iterable<FeedItem> items, + Runnable deleteCommand) { + boolean anyLocalFeed = false; + for (FeedItem item : items) { + if (item.getFeed().isLocalFeed()) { + anyLocalFeed = true; + break; + } + } + + if (!anyLocalFeed) { + deleteCommand.run(); + return; + } + + new MaterialAlertDialogBuilder(context) + .setTitle(R.string.delete_episode_label) + .setMessage(R.string.delete_local_feed_warning_body) + .setPositiveButton(R.string.delete_label, (dialog, which) -> deleteCommand.run()) + .setNegativeButton(R.string.cancel_label, null) + .show(); + } +} diff --git a/app/src/main/res/xml/preferences_downloads.xml b/app/src/main/res/xml/preferences_downloads.xml index e1a1b9b00..b0a41dfb5 100644 --- a/app/src/main/res/xml/preferences_downloads.xml +++ b/app/src/main/res/xml/preferences_downloads.xml @@ -34,6 +34,12 @@ android:summary="@string/pref_auto_delete_sum" android:title="@string/pref_auto_delete_title"/> <SwitchPreferenceCompat + android:defaultValue="false" + android:enabled="true" + android:key="prefAutoDeleteLocal" + android:summary="@string/pref_auto_local_delete_sum" + android:title="@string/pref_auto_local_delete_title"/> + <SwitchPreferenceCompat android:defaultValue="true" android:enabled="true" android:key="prefFavoriteKeepsEpisode" |