From de8496f37f826fb20ab415b68e62eb298e18ef5d Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sat, 6 Nov 2021 22:21:28 +0100 Subject: [PATCH] Fix crash when deleting feed When the database is huge, loading the subscription item list takes a long time. Redirecting to the episodes screen after deleting sometimes results in the item list starting to update before. If the screen is then hidden before the Callable returns, the app crashes. --- .../antennapod/dialog/RemoveFeedDialog.java | 16 ++++++---------- .../fragment/FeedItemlistFragment.java | 4 ++-- .../antennapod/fragment/NavDrawerFragment.java | 5 ++--- .../fragment/SubscriptionFragment.java | 2 +- .../actions/FeedMultiSelectActionHandler.java | 2 +- 5 files changed, 12 insertions(+), 17 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 9fcf8be69..23c032248 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/RemoveFeedDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/RemoveFeedDialog.java @@ -19,18 +19,18 @@ import io.reactivex.schedulers.Schedulers; public class RemoveFeedDialog { private static final String TAG = "RemoveFeedDialog"; - public static void show(Context context, Feed feed, Runnable onSuccess) { + public static void show(Context context, Feed feed) { List feeds = Collections.singletonList(feed); String message = getMessageId(context, feeds); - showDialog(context, feeds, message, onSuccess); + showDialog(context, feeds, message); } - public static void show(Context context, List feeds, Runnable onSuccess) { + public static void show(Context context, List feeds) { String message = getMessageId(context, feeds); - showDialog(context, feeds, message, onSuccess); + showDialog(context, feeds, message); } - private static void showDialog(Context context, List feeds, String message, Runnable onSuccess) { + private static void showDialog(Context context, List feeds, String message) { ConfirmationDialog dialog = new ConfirmationDialog(context, R.string.remove_feed_label, message) { @Override public void onConfirmButtonPressed(DialogInterface clickedDialog) { @@ -42,20 +42,16 @@ public class RemoveFeedDialog { progressDialog.setCancelable(false); progressDialog.show(); - Completable.fromCallable(() -> { + Completable.fromAction(() -> { for (Feed feed : feeds) { DBWriter.deleteFeed(context, feed.getId()).get(); } - return null; }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( () -> { Log.d(TAG, "Feed(s) deleted"); - if (onSuccess != null) { - onSuccess.run(); - } progressDialog.dismiss(); }, error -> { Log.e(TAG, Log.getStackTraceString(error)); 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 1d40a28be..148cf6582 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -333,8 +333,8 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem new RenameFeedDialog(getActivity(), feed).show(); return true; } else if (itemId == R.id.remove_item) { - RemoveFeedDialog.show(getContext(), feed, () -> - ((MainActivity) getActivity()).loadFragment(EpisodesFragment.TAG, null)); + ((MainActivity) getActivity()).loadFragment(EpisodesFragment.TAG, null); + RemoveFeedDialog.show(getContext(), feed); 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 5abc42ab2..85de99766 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java @@ -164,9 +164,8 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS new RenameFeedDialog(getActivity(), feed).show(); return true; } else if (itemId == R.id.remove_item) { - RemoveFeedDialog.show(getContext(), feed, () -> { - ((MainActivity) getActivity()).loadFragment(EpisodesFragment.TAG, null); - }); + ((MainActivity) getActivity()).loadFragment(EpisodesFragment.TAG, null); + RemoveFeedDialog.show(getContext(), feed); return true; } return super.onContextItemSelected(item); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java index 0914996d3..a87575681 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -351,7 +351,7 @@ public class SubscriptionFragment extends Fragment new RenameFeedDialog(getActivity(), feed).show(); return true; } else if (itemId == R.id.remove_item) { - RemoveFeedDialog.show(getContext(), feed, null); + RemoveFeedDialog.show(getContext(), feed); return true; } else if (itemId == R.id.multi_select) { speedDialView.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/actions/FeedMultiSelectActionHandler.java b/app/src/main/java/de/danoeh/antennapod/fragment/actions/FeedMultiSelectActionHandler.java index 36df74347..04a19df4a 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/actions/FeedMultiSelectActionHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/actions/FeedMultiSelectActionHandler.java @@ -35,7 +35,7 @@ public class FeedMultiSelectActionHandler { public void handleAction(int id) { if (id == R.id.remove_item) { - RemoveFeedDialog.show(activity, selectedItems, null); + RemoveFeedDialog.show(activity, selectedItems); } else if (id == R.id.keep_updated) { keepUpdatedPrefHandler(); } else if (id == R.id.autodownload) {