From 10e18ec9ea40625398ea5bb188b0cc0cc3a76169 Mon Sep 17 00:00:00 2001 From: Zhidong Piao Date: Tue, 18 Oct 2022 00:08:02 +1100 Subject: [PATCH] Fix crash when the user clicks download then quits the history fragment --- .../info_list/dialog/StreamDialogDefaultEntry.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogDefaultEntry.java b/app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogDefaultEntry.java index 1265e976726..c67880d0eb8 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogDefaultEntry.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogDefaultEntry.java @@ -112,12 +112,19 @@ public enum StreamDialogDefaultEntry { ShareUtils.shareText(fragment.requireContext(), item.getName(), item.getUrl(), item.getThumbnailUrl())), + /** + * Opens a {@link DownloadDialog} after fetching some stream info. + * If the user quits the current fragment, it will not open a DownloadDialog. + */ DOWNLOAD(R.string.download, (fragment, item) -> fetchStreamInfoAndSaveToDatabase(fragment.requireContext(), item.getServiceId(), item.getUrl(), info -> { - final DownloadDialog downloadDialog = - new DownloadDialog(fragment.requireContext(), info); - downloadDialog.show(fragment.getChildFragmentManager(), "downloadDialog"); + if (fragment.getContext() != null) { + final DownloadDialog downloadDialog = + new DownloadDialog(fragment.requireContext(), info); + downloadDialog.show(fragment.getChildFragmentManager(), + "downloadDialog"); + } }) ),