From bed351668738cbe57d528f2be77383771789abf9 Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 27 Mar 2024 17:30:23 +0100 Subject: [PATCH 1/4] Fix non-desugared method being used Search for "Not supported at all minSDK levels" here: https://developer.android.com/studio/write/java8-support-table --- .../java/us/shandian/giga/service/DownloadManagerService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java b/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java index 42ff3ca8c..45211211f 100755 --- a/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java +++ b/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java @@ -411,7 +411,7 @@ public class DownloadManagerService extends Service { mission.threadCount = threads; mission.source = source; mission.nearLength = nearLength; - mission.recoveryInfo = recovery.toArray(MissionRecoveryInfo[]::new); + mission.recoveryInfo = recovery.toArray(new MissionRecoveryInfo[0]); if (ps != null) ps.setTemporalDir(DownloadManager.pickAvailableTemporalDir(this)); From d8a5d5545ddae5f19566a30e949db551b24da732 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 28 Mar 2024 10:56:50 +0100 Subject: [PATCH 2/4] Fix choosing audio format to mux with video-only download --- .../newpipe/util/SecondaryStreamHelper.java | 54 +++++++------------ 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/SecondaryStreamHelper.java b/app/src/main/java/org/schabi/newpipe/util/SecondaryStreamHelper.java index 75d9a3892..69dc697fe 100644 --- a/app/src/main/java/org/schabi/newpipe/util/SecondaryStreamHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/SecondaryStreamHelper.java @@ -11,7 +11,6 @@ import org.schabi.newpipe.extractor.stream.Stream; import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.util.StreamItemAdapter.StreamInfoWrapper; -import java.util.Comparator; import java.util.List; public class SecondaryStreamHelper { @@ -43,42 +42,27 @@ public class SecondaryStreamHelper { @NonNull final List audioStreams, @NonNull final VideoStream videoStream) { final MediaFormat mediaFormat = videoStream.getFormat(); - if (mediaFormat == null) { + + if (mediaFormat == MediaFormat.WEBM) { + return audioStreams + .stream() + .filter(audioStream -> audioStream.getFormat() == MediaFormat.WEBMA + || audioStream.getFormat() == MediaFormat.WEBMA_OPUS) + .max(ListHelper.getAudioFormatComparator(MediaFormat.WEBMA, + ListHelper.isLimitingDataUsage(context))) + .orElse(null); + + } else if (mediaFormat == MediaFormat.MPEG_4) { + return audioStreams + .stream() + .filter(audioStream -> audioStream.getFormat() == MediaFormat.M4A) + .max(ListHelper.getAudioFormatComparator(MediaFormat.M4A, + ListHelper.isLimitingDataUsage(context))) + .orElse(null); + + } else { return null; } - - switch (mediaFormat) { - case WEBM: - case MPEG_4: // Is MPEG-4 DASH? - break; - default: - return null; - } - - final boolean m4v = mediaFormat == MediaFormat.MPEG_4; - final boolean isLimitingDataUsage = ListHelper.isLimitingDataUsage(context); - - Comparator comparator = ListHelper.getAudioFormatComparator( - m4v ? MediaFormat.M4A : MediaFormat.WEBMA, isLimitingDataUsage); - int preferredAudioStreamIndex = ListHelper.getAudioIndexByHighestRank( - audioStreams, comparator); - - if (preferredAudioStreamIndex == -1) { - if (m4v) { - return null; - } - - comparator = ListHelper.getAudioFormatComparator( - MediaFormat.WEBMA_OPUS, isLimitingDataUsage); - preferredAudioStreamIndex = ListHelper.getAudioIndexByHighestRank( - audioStreams, comparator); - - if (preferredAudioStreamIndex == -1) { - return null; - } - } - - return audioStreams.get(preferredAudioStreamIndex); } public T getStream() { From d3afde8789df76456128207a5f1186727f50237d Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 28 Mar 2024 11:21:29 +0100 Subject: [PATCH 3/4] Remove unused DownloadDialog.onDismissListener --- .../newpipe/download/DownloadDialog.java | 20 ------------------- 1 file changed, 20 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 fa312e55e..4680e71a7 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -7,8 +7,6 @@ import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; import android.app.Activity; import android.content.ComponentName; import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnDismissListener; import android.content.Intent; import android.content.ServiceConnection; import android.content.SharedPreferences; @@ -113,9 +111,6 @@ public class DownloadDialog extends DialogFragment @State int selectedSubtitleIndex = 0; // default to the first item - @Nullable - private OnDismissListener onDismissListener = null; - private StoredDirectoryHelper mainStorageAudio = null; private StoredDirectoryHelper mainStorageVideo = null; private DownloadManager downloadManager = null; @@ -195,13 +190,6 @@ public class DownloadDialog extends DialogFragment this.selectedVideoIndex = ListHelper.getDefaultResolutionIndex(context, videoStreams); } - /** - * @param onDismissListener the listener to call in {@link #onDismiss(DialogInterface)} - */ - public void setOnDismissListener(@Nullable final OnDismissListener onDismissListener) { - this.onDismissListener = onDismissListener; - } - /*////////////////////////////////////////////////////////////////////////// // Android lifecycle @@ -364,14 +352,6 @@ public class DownloadDialog extends DialogFragment }); } - @Override - public void onDismiss(@NonNull final DialogInterface dialog) { - super.onDismiss(dialog); - if (onDismissListener != null) { - onDismissListener.onDismiss(dialog); - } - } - @Override public void onDestroy() { super.onDestroy(); From 5d9adce40dce1e10507131c2eb39c348ba2a6c50 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 28 Mar 2024 11:35:21 +0100 Subject: [PATCH 4/4] Fix NPE, since dismissing a dialog still calls onViewCreated() --- .../java/org/schabi/newpipe/download/DownloadDialog.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 4680e71a7..bbdb46292 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -115,7 +115,7 @@ public class DownloadDialog extends DialogFragment private StoredDirectoryHelper mainStorageVideo = null; private DownloadManager downloadManager = null; private ActionMenuItemView okButton = null; - private Context context; + private Context context = null; private boolean askForSavePath; private AudioTrackAdapter audioTrackAdapter; @@ -209,6 +209,8 @@ public class DownloadDialog extends DialogFragment return; } + // context will remain null if dismiss() was called above, allowing to check whether the + // dialog is being dismissed in onViewCreated() context = getContext(); setStyle(STYLE_NO_TITLE, ThemeHelper.getDialogTheme(context)); @@ -293,6 +295,9 @@ public class DownloadDialog extends DialogFragment @Nullable final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); dialogBinding = DownloadDialogBinding.bind(view); + if (context == null) { + return; // the dialog is being dismissed, see the call to dismiss() in onCreate() + } dialogBinding.fileName.setText(FilenameUtils.createFilename(getContext(), currentInfo.getName()));