Merge pull request #3613 from wb9688/fix-download-dialog-freeze

Fix download dialog freeze
This commit is contained in:
Stypox 2020-05-18 14:11:17 +02:00 committed by GitHub
commit 169b1cbd32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 25 deletions

View File

@ -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 { configurations {
ktlint ktlint
} }

View File

@ -5,6 +5,7 @@ import android.content.SharedPreferences;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import org.schabi.newpipe.R; 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 * Get the audio from the list with the highest quality.
* no results. * Format will be ignored if it yields no results.
* *
* @param format the format to look for * @param format The target format type or null if it doesn't matter
* @param audioStreams list the audio streams * @param audioStreams List of audio streams
* @return index of the audio with the highest average bitrate of the default format * @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<AudioStream> audioStreams) { final List<AudioStream> audioStreams) {
int result = -1; int result = -1;
boolean hasOneFormat = false;
if (audioStreams != null) { if (audioStreams != null) {
while (result == -1) { while (result == -1) {
AudioStream prevStream = null; AudioStream prevStream = null;
for (int idx = 0; idx < audioStreams.size(); idx++) { for (int idx = 0; idx < audioStreams.size(); idx++) {
AudioStream stream = audioStreams.get(idx); AudioStream stream = audioStreams.get(idx);
if ((format == null || stream.getFormat() == format || hasOneFormat) if ((format == null || stream.getFormat() == format)
&& (prevStream == null || compareAudioStreamBitrate(prevStream, stream, && (prevStream == null || compareAudioStreamBitrate(prevStream, stream,
AUDIO_FORMAT_QUALITY_RANKING) < 0)) { AUDIO_FORMAT_QUALITY_RANKING) < 0)) {
prevStream = stream; prevStream = stream;
@ -293,30 +293,29 @@ public final class ListHelper {
if (result == -1 && format == null) { if (result == -1 && format == null) {
break; break;
} }
hasOneFormat = true; format = null;
} }
} }
return result; return result;
} }
/** /**
* Get the audio from the list with the lowest bitrate and efficient format. Format will be * Get the audio from the list with the lowest bitrate and most efficient format.
* ignored if it yields no results. * Format will be ignored if it yields no results.
* *
* @param format The target format type or null if it doesn't matter * @param format The target format type or null if it doesn't matter
* @param audioStreams List of audio streams * @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<AudioStream> audioStreams) { final List<AudioStream> audioStreams) {
int result = -1; int result = -1;
boolean hasOneFormat = false;
if (audioStreams != null) { if (audioStreams != null) {
while (result == -1) { while (result == -1) {
AudioStream prevStream = null; AudioStream prevStream = null;
for (int idx = 0; idx < audioStreams.size(); idx++) { for (int idx = 0; idx < audioStreams.size(); idx++) {
AudioStream stream = audioStreams.get(idx); AudioStream stream = audioStreams.get(idx);
if ((format == null || stream.getFormat() == format || hasOneFormat) if ((format == null || stream.getFormat() == format)
&& (prevStream == null || compareAudioStreamBitrate(prevStream, stream, && (prevStream == null || compareAudioStreamBitrate(prevStream, stream,
AUDIO_FORMAT_EFFICIENCY_RANKING) > 0)) { AUDIO_FORMAT_EFFICIENCY_RANKING) > 0)) {
prevStream = stream; prevStream = stream;
@ -326,7 +325,7 @@ public final class ListHelper {
if (result == -1 && format == null) { if (result == -1 && format == null) {
break; break;
} }
hasOneFormat = true; format = null;
} }
} }
return result; return result;

View File

@ -11,6 +11,10 @@
files="InfoListAdapter.java" files="InfoListAdapter.java"
lines="253,325"/> lines="253,325"/>
<suppress checks="FinalParameters"
files="ListHelper.java"
lines="278,310"/>
<!-- org.schabi.newpipe.streams --> <!-- org.schabi.newpipe.streams -->
<suppress checks="FinalParameters" <suppress checks="FinalParameters"
files="DataReader.java" files="DataReader.java"