From a828660b446fcc1a8a518c7a30622b905c7bf358 Mon Sep 17 00:00:00 2001 From: GitStart <1501599+gitstart@users.noreply.github.com> Date: Fri, 7 Apr 2023 13:21:52 +0100 Subject: [PATCH] Do not switch screens when clicking "Remove podcast" (#6259) --- .../antennapod/dialog/RemoveFeedDialog.java | 15 +++++++++++---- .../antennapod/fragment/FeedItemlistFragment.java | 8 ++++++-- .../antennapod/fragment/NavDrawerFragment.java | 9 +++++++-- .../antennapod/menuhandler/FeedMenuHandler.java | 2 +- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/RemoveFeedDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/RemoveFeedDialog.java index 23c032248..363b87ca6 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/RemoveFeedDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/RemoveFeedDialog.java @@ -5,6 +5,8 @@ import android.content.Context; import android.content.DialogInterface; import android.util.Log; +import androidx.annotation.Nullable; + import java.util.Collections; import java.util.List; @@ -19,21 +21,26 @@ import io.reactivex.schedulers.Schedulers; public class RemoveFeedDialog { private static final String TAG = "RemoveFeedDialog"; - public static void show(Context context, Feed feed) { + public static void show(Context context, Feed feed, @Nullable Runnable callback) { List feeds = Collections.singletonList(feed); String message = getMessageId(context, feeds); - showDialog(context, feeds, message); + showDialog(context, feeds, message, callback); } public static void show(Context context, List feeds) { String message = getMessageId(context, feeds); - showDialog(context, feeds, message); + showDialog(context, feeds, message, null); } - private static void showDialog(Context context, List feeds, String message) { + private static void showDialog(Context context, List feeds, String message, @Nullable Runnable callback) { ConfirmationDialog dialog = new ConfirmationDialog(context, R.string.remove_feed_label, message) { @Override public void onConfirmButtonPressed(DialogInterface clickedDialog) { + + if (callback != null) { + callback.run(); + } + clickedDialog.dismiss(); ProgressDialog progressDialog = new ProgressDialog(context); 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 ecc60c411..61883afe7 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -61,6 +61,7 @@ import de.danoeh.antennapod.model.download.DownloadStatus; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedItemFilter; +import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.ui.glide.FastBlurTransformation; import de.danoeh.antennapod.view.ToolbarIconTintManager; import de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder; @@ -270,8 +271,11 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem new RenameItemDialog(getActivity(), feed).show(); return true; } else if (itemId == R.id.remove_feed) { - ((MainActivity) getActivity()).loadFragment(AllEpisodesFragment.TAG, null); - RemoveFeedDialog.show(getContext(), feed); + RemoveFeedDialog.show(getContext(), feed, () -> { + ((MainActivity) getActivity()).loadFragment(UserPreferences.getDefaultPage(), null); + // Make sure fragment is hidden before actually starting to delete + getActivity().getSupportFragmentManager().executePendingTransactions(); + }); return true; } else if (itemId == R.id.action_search) { ((MainActivity) getActivity()).loadChildFragment(SearchFragment.newInstance(feed.getId(), feed.getTitle())); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java index e155e467d..ecb24a1e1 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java @@ -175,8 +175,13 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS new RenameItemDialog(getActivity(), feed).show(); return true; } else if (itemId == R.id.remove_feed) { - ((MainActivity) getActivity()).loadFragment(AllEpisodesFragment.TAG, null); - RemoveFeedDialog.show(getContext(), feed); + RemoveFeedDialog.show(getContext(), feed, () -> { + if (String.valueOf(feed.getId()).equals(getLastNavFragment(getContext()))) { + ((MainActivity) getActivity()).loadFragment(UserPreferences.getDefaultPage(), null); + // Make sure fragment is hidden before actually starting to delete + getActivity().getSupportFragmentManager().executePendingTransactions(); + } + }); return true; } return super.onContextItemSelected(item); diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java index e9b0c0b19..9b9525133 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java @@ -126,7 +126,7 @@ public class FeedMenuHandler { } else if (menuItemId == R.id.rename_item) { new RenameItemDialog(fragment.getActivity(), selectedFeed).show(); } else if (menuItemId == R.id.remove_feed) { - RemoveFeedDialog.show(context, selectedFeed); + RemoveFeedDialog.show(context, selectedFeed, null); } else { return false; }