From 8ef31d0b5af786fed5e691338f4d8175e63048bf Mon Sep 17 00:00:00 2001 From: evermind Date: Mon, 21 Aug 2023 00:22:01 +0200 Subject: [PATCH] fix DownloadDialog crash if there are no streams available yet If there are no streams the DownloadDialog will close again quickly, but the rxJava job fetching the VideoSegments is still going. This patch fixes that: - move initialization of getting VideoSegments rxJava job until after initToolbar() - have Disposable for the VideoSegments stuff that will be disposed if the DownloadDialog will be destroyed. --- .../org/schabi/newpipe/download/DownloadDialog.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index a8484c491a5..262567e4b22 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -87,6 +87,7 @@ import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; import io.reactivex.rxjava3.core.Single; import io.reactivex.rxjava3.disposables.CompositeDisposable; +import io.reactivex.rxjava3.disposables.Disposable; import io.reactivex.rxjava3.schedulers.Schedulers; import us.shandian.giga.get.MissionRecoveryInfo; import us.shandian.giga.postprocessing.Postprocessing; @@ -153,6 +154,8 @@ public class DownloadDialog extends DialogFragment private final ActivityResultLauncher requestDownloadPickVideoFolderLauncher = registerForActivityResult( new StartActivityForResult(), this::requestDownloadPickVideoFolderResult); + @NonNull + private Disposable youtubeVideoSegmentsDisposable; /*////////////////////////////////////////////////////////////////////////// @@ -254,8 +257,6 @@ public void onServiceConnected(final ComponentName cname, final IBinder service) downloadManager = mgr.getDownloadManager(); askForSavePath = mgr.askForSavePath(); - checkForYoutubeVideoSegments(); - context.unbindService(this); } @@ -332,6 +333,7 @@ public void onViewCreated(@NonNull final View view, showLoading(); initToolbar(dialogBinding.toolbarLayout.toolbar); + checkForYoutubeVideoSegments(); setupDownloadOptions(); prefs = PreferenceManager.getDefaultSharedPreferences(requireContext()); @@ -393,6 +395,7 @@ public void onDestroy() { @Override public void onDestroyView() { + youtubeVideoSegmentsDisposable.dispose(); dialogBinding = null; super.onDestroyView(); } @@ -1158,7 +1161,7 @@ private void continueSelectedDownload(@NonNull final StoredFileHelper storage) { } private void checkForYoutubeVideoSegments() { - disposables.add(Single.fromCallable(() -> { + youtubeVideoSegmentsDisposable = Single.fromCallable(() -> { VideoSegment[] videoSegments = null; try { videoSegments = SponsorBlockUtils @@ -1177,7 +1180,7 @@ private void checkForYoutubeVideoSegments() { setVideoSegments(videoSegments); okButton.setEnabled(true); hideLoading(); - })); + }); } public void showLoading() {