Skip to content

Commit 4081508

Browse files
authored
Fix crash when the user clicks download then quits the history fragment (TeamNewPipe#9143)
* Fix crash when the user clicks download then quits the history fragment * add a nonnull annotation to the context parameter in the DownloadDialog constructor. * Revert "Merge branch 'TeamNewPipe:dev' into fix/HistoryFragmentDownloadDialogCrash" This reverts commit 968d7a7. * Revert "Merge branch 'TeamNewPipe:dev' into fix/HistoryFragmentDownloadDialogCrash" This reverts commit 968d7a7, reversing changes made to 52963ba. Reverted merge jlhzxc * update project to the latest dev branch * Revert "update project to the latest dev branch" This reverts commit fb3ed83. revert changes to build files * Revert "Revert "Merge branch 'TeamNewPipe:dev' into fix/HistoryFragmentDownloadDialogCrash"" This reverts commit f9e1835.
1 parent 1686060 commit 4081508

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public DownloadDialog() {
159159
* @param context the context to use just to obtain preferences and strings (will not be stored)
160160
* @param info the info from which to obtain downloadable streams and other info (e.g. title)
161161
*/
162-
public DownloadDialog(final Context context, @NonNull final StreamInfo info) {
162+
public DownloadDialog(@NonNull final Context context, @NonNull final StreamInfo info) {
163163
this.currentInfo = info;
164164

165165
// TODO: Adapt this code when the downloader support other types of stream deliveries

app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogDefaultEntry.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,19 @@ public enum StreamDialogDefaultEntry {
112112
ShareUtils.shareText(fragment.requireContext(), item.getName(), item.getUrl(),
113113
item.getThumbnailUrl())),
114114

115+
/**
116+
* Opens a {@link DownloadDialog} after fetching some stream info.
117+
* If the user quits the current fragment, it will not open a DownloadDialog.
118+
*/
115119
DOWNLOAD(R.string.download, (fragment, item) ->
116120
fetchStreamInfoAndSaveToDatabase(fragment.requireContext(), item.getServiceId(),
117121
item.getUrl(), info -> {
118-
final DownloadDialog downloadDialog =
119-
new DownloadDialog(fragment.requireContext(), info);
120-
downloadDialog.show(fragment.getChildFragmentManager(), "downloadDialog");
122+
if (fragment.getContext() != null) {
123+
final DownloadDialog downloadDialog =
124+
new DownloadDialog(fragment.requireContext(), info);
125+
downloadDialog.show(fragment.getChildFragmentManager(),
126+
"downloadDialog");
127+
}
121128
})
122129
),
123130

0 commit comments

Comments
 (0)