From 93ba7510e16ad51941eae02e48fd1e47446f9f3c Mon Sep 17 00:00:00 2001 From: wb9688 Date: Mon, 18 May 2020 11:44:24 +0200 Subject: [PATCH 1/2] Fix ListHelper ANR --- .../org/schabi/newpipe/util/ListHelper.java | 31 +++++++++---------- checkstyle-suppressions.xml | 4 +++ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/ListHelper.java b/app/src/main/java/org/schabi/newpipe/util/ListHelper.java index 1b2b74c6f..189b6823e 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ListHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ListHelper.java @@ -5,6 +5,7 @@ import android.content.SharedPreferences; import android.net.ConnectivityManager; import android.preference.PreferenceManager; +import androidx.annotation.Nullable; import androidx.annotation.StringRes; import org.schabi.newpipe.R; @@ -267,23 +268,22 @@ public final class ListHelper { } /** - * Get the audio from the list with the highest quality. Format will be ignored if it yields - * no results. + * Get the audio from the list with the highest quality. + * Format will be ignored if it yields no results. * - * @param format the format to look for - * @param audioStreams list the audio streams - * @return index of the audio with the highest average bitrate of the default format + * @param format The target format type or null if it doesn't matter + * @param audioStreams List of audio streams + * @return Index of audio stream that produces the most compact results or -1 if not found */ - static int getHighestQualityAudioIndex(final MediaFormat format, + static int getHighestQualityAudioIndex(@Nullable MediaFormat format, final List audioStreams) { int result = -1; - boolean hasOneFormat = false; if (audioStreams != null) { while (result == -1) { AudioStream prevStream = null; for (int idx = 0; idx < audioStreams.size(); idx++) { AudioStream stream = audioStreams.get(idx); - if ((format == null || stream.getFormat() == format || hasOneFormat) + if ((format == null || stream.getFormat() == format) && (prevStream == null || compareAudioStreamBitrate(prevStream, stream, AUDIO_FORMAT_QUALITY_RANKING) < 0)) { prevStream = stream; @@ -293,30 +293,29 @@ public final class ListHelper { if (result == -1 && format == null) { break; } - hasOneFormat = true; + format = null; } } return result; } /** - * Get the audio from the list with the lowest bitrate and efficient format. Format will be - * ignored if it yields no results. + * Get the audio from the list with the lowest bitrate and most efficient format. + * Format will be ignored if it yields no results. * * @param format The target format type or null if it doesn't matter * @param audioStreams List of audio streams - * @return Index of audio stream that can produce the most compact results or -1 if not found + * @return Index of audio stream that produces the most compact results or -1 if not found */ - static int getMostCompactAudioIndex(final MediaFormat format, + static int getMostCompactAudioIndex(@Nullable MediaFormat format, final List audioStreams) { int result = -1; - boolean hasOneFormat = false; if (audioStreams != null) { while (result == -1) { AudioStream prevStream = null; for (int idx = 0; idx < audioStreams.size(); idx++) { AudioStream stream = audioStreams.get(idx); - if ((format == null || stream.getFormat() == format || hasOneFormat) + if ((format == null || stream.getFormat() == format) && (prevStream == null || compareAudioStreamBitrate(prevStream, stream, AUDIO_FORMAT_EFFICIENCY_RANKING) > 0)) { prevStream = stream; @@ -326,7 +325,7 @@ public final class ListHelper { if (result == -1 && format == null) { break; } - hasOneFormat = true; + format = null; } } return result; diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml index d015a9e03..a4fc516f2 100644 --- a/checkstyle-suppressions.xml +++ b/checkstyle-suppressions.xml @@ -11,6 +11,10 @@ files="InfoListAdapter.java" lines="253,325"/> + + Date: Mon, 18 May 2020 11:44:47 +0200 Subject: [PATCH 2/2] Remove not needed Checkstyle stuff --- app/build.gradle | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 95ab1144b..26a22f7a3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -117,15 +117,6 @@ task runCheckstyle(type: Checkstyle) { } } -runCheckstyle.doLast { - reports.all { report -> - def outputFile = report.destination - if (outputFile.exists() && outputFile.text.contains("severity=\"error\"")) { - throw new GradleException("There were checkstyle errors! For more info check $outputFile") - } - } -} - configurations { ktlint }