Do not switch screens when clicking "Remove podcast" (#6259)

This commit is contained in:
GitStart 2023-04-07 13:21:52 +01:00 committed by GitHub
parent 7ed78887c4
commit a828660b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 9 deletions

View File

@ -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<Feed> 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<Feed> feeds) {
String message = getMessageId(context, feeds);
showDialog(context, feeds, message);
showDialog(context, feeds, message, null);
}
private static void showDialog(Context context, List<Feed> feeds, String message) {
private static void showDialog(Context context, List<Feed> 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);

View File

@ -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()));

View File

@ -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);

View File

@ -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;
}