fix(YouTube - Video quality): Fix wrong qualities sometimes shown in player button dialog
This commit is contained in:
parent
621292644c
commit
178eed7fcd
2 changed files with 24 additions and 25 deletions
|
|
@ -8,7 +8,6 @@ import androidx.annotation.Nullable;
|
||||||
import com.google.android.libraries.youtube.innertube.model.media.VideoQuality;
|
import com.google.android.libraries.youtube.innertube.model.media.VideoQuality;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import app.revanced.extension.shared.Logger;
|
import app.revanced.extension.shared.Logger;
|
||||||
import app.revanced.extension.shared.Utils;
|
import app.revanced.extension.shared.Utils;
|
||||||
|
|
@ -45,13 +44,11 @@ public class RememberVideoQualityPatch {
|
||||||
private static final IntegerSetting shortsQualityWifi = Settings.SHORTS_QUALITY_DEFAULT_WIFI;
|
private static final IntegerSetting shortsQualityWifi = Settings.SHORTS_QUALITY_DEFAULT_WIFI;
|
||||||
private static final IntegerSetting shortsQualityMobile = Settings.SHORTS_QUALITY_DEFAULT_MOBILE;
|
private static final IntegerSetting shortsQualityMobile = Settings.SHORTS_QUALITY_DEFAULT_MOBILE;
|
||||||
|
|
||||||
private static boolean qualityNeedsUpdating;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The available qualities of the current video.
|
* The available qualities of the current video.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private static List<VideoQuality> currentQualities;
|
private static VideoQuality[] currentQualities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current quality of the video playing.
|
* The current quality of the video playing.
|
||||||
|
|
@ -67,7 +64,7 @@ public class RememberVideoQualityPatch {
|
||||||
private static VideoQualityMenuInterface currentMenuInterface;
|
private static VideoQualityMenuInterface currentMenuInterface;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static List<VideoQuality> getCurrentQualities() {
|
public static VideoQuality[] getCurrentQualities() {
|
||||||
return currentQualities;
|
return currentQualities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -138,11 +135,11 @@ public class RememberVideoQualityPatch {
|
||||||
Utils.verifyOnMainThread();
|
Utils.verifyOnMainThread();
|
||||||
currentMenuInterface = menu;
|
currentMenuInterface = menu;
|
||||||
|
|
||||||
final boolean availableQualitiesChanged = currentQualities == null
|
final boolean availableQualitiesChanged = (currentQualities == null)
|
||||||
|| currentQualities.size() != qualities.length;
|
|| !Arrays.equals(currentQualities, qualities);
|
||||||
if (availableQualitiesChanged) {
|
if (availableQualitiesChanged) {
|
||||||
currentQualities = Arrays.asList(qualities);
|
currentQualities = qualities;
|
||||||
Logger.printDebug(() -> "VideoQualities: " + currentQualities);
|
Logger.printDebug(() -> "VideoQualities: " + Arrays.toString(currentQualities));
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoQuality updatedCurrentQuality = qualities[originalQualityIndex];
|
VideoQuality updatedCurrentQuality = qualities[originalQualityIndex];
|
||||||
|
|
@ -155,17 +152,12 @@ public class RememberVideoQualityPatch {
|
||||||
VideoQualityDialogButton.updateButtonIcon(updatedCurrentQuality);
|
VideoQualityDialogButton.updateButtonIcon(updatedCurrentQuality);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int preferredQuality = getDefaultQualityResolution();
|
|
||||||
if (preferredQuality == AUTOMATIC_VIDEO_QUALITY_VALUE) {
|
|
||||||
return originalQualityIndex; // Nothing to do.
|
|
||||||
}
|
|
||||||
|
|
||||||
// After changing videos the qualities can initially be for the prior video.
|
// After changing videos the qualities can initially be for the prior video.
|
||||||
// If the qualities have changed and the default is not auto then an update is needed.
|
// If the qualities have changed and the default is not auto then an update is needed.
|
||||||
if (!qualityNeedsUpdating && !availableQualitiesChanged) {
|
final int preferredQuality = getDefaultQualityResolution();
|
||||||
return originalQualityIndex;
|
if (preferredQuality == AUTOMATIC_VIDEO_QUALITY_VALUE || !availableQualitiesChanged) {
|
||||||
|
return originalQualityIndex; // Nothing to do.
|
||||||
}
|
}
|
||||||
qualityNeedsUpdating = false;
|
|
||||||
|
|
||||||
// Find the highest quality that is equal to or less than the preferred.
|
// Find the highest quality that is equal to or less than the preferred.
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
@ -213,7 +205,7 @@ public class RememberVideoQualityPatch {
|
||||||
Logger.printDebug(() -> "Cannot save default quality, qualities is null");
|
Logger.printDebug(() -> "Cannot save default quality, qualities is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
VideoQuality quality = currentQualities.get(userSelectedQualityIndex);
|
VideoQuality quality = currentQualities[userSelectedQualityIndex];
|
||||||
saveDefaultQuality(quality.patch_getResolution());
|
saveDefaultQuality(quality.patch_getResolution());
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
@ -243,7 +235,6 @@ public class RememberVideoQualityPatch {
|
||||||
currentQualities = null;
|
currentQualities = null;
|
||||||
currentQuality = null;
|
currentQuality = null;
|
||||||
currentMenuInterface = null;
|
currentMenuInterface = null;
|
||||||
qualityNeedsUpdating = true;
|
|
||||||
|
|
||||||
// Hide the quality button until playback starts and the qualities are available.
|
// Hide the quality button until playback starts and the qualities are available.
|
||||||
VideoQualityDialogButton.updateButtonIcon(null);
|
VideoQualityDialogButton.updateButtonIcon(null);
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ public class VideoQualityDialogButton {
|
||||||
},
|
},
|
||||||
view -> {
|
view -> {
|
||||||
try {
|
try {
|
||||||
List<VideoQuality> qualities = RememberVideoQualityPatch.getCurrentQualities();
|
VideoQuality[] qualities = RememberVideoQualityPatch.getCurrentQualities();
|
||||||
VideoQualityMenuInterface menu = RememberVideoQualityPatch.getCurrentMenuInterface();
|
VideoQualityMenuInterface menu = RememberVideoQualityPatch.getCurrentMenuInterface();
|
||||||
if (qualities == null || menu == null) {
|
if (qualities == null || menu == null) {
|
||||||
Logger.printDebug(() -> "Cannot reset quality, videoQualities is null");
|
Logger.printDebug(() -> "Cannot reset quality, videoQualities is null");
|
||||||
|
|
@ -186,13 +186,13 @@ public class VideoQualityDialogButton {
|
||||||
*/
|
*/
|
||||||
private static void showVideoQualityDialog(Context context) {
|
private static void showVideoQualityDialog(Context context) {
|
||||||
try {
|
try {
|
||||||
List<VideoQuality> currentQualities = RememberVideoQualityPatch.getCurrentQualities();
|
VideoQuality[] currentQualities = RememberVideoQualityPatch.getCurrentQualities();
|
||||||
VideoQuality currentQuality = RememberVideoQualityPatch.getCurrentQuality();
|
VideoQuality currentQuality = RememberVideoQualityPatch.getCurrentQuality();
|
||||||
if (currentQualities == null || currentQuality == null) {
|
if (currentQualities == null || currentQuality == null) {
|
||||||
Logger.printDebug(() -> "Cannot show qualities dialog, videoQualities is null");
|
Logger.printDebug(() -> "Cannot show qualities dialog, videoQualities is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (currentQualities.size() < 2) {
|
if (currentQualities.length < 2) {
|
||||||
// Should never happen.
|
// Should never happen.
|
||||||
Logger.printException(() -> "Cannot show qualities dialog, no qualities available");
|
Logger.printException(() -> "Cannot show qualities dialog, no qualities available");
|
||||||
return;
|
return;
|
||||||
|
|
@ -205,9 +205,17 @@ public class VideoQualityDialogButton {
|
||||||
}
|
}
|
||||||
|
|
||||||
// -1 adjustment for automatic quality at first index.
|
// -1 adjustment for automatic quality at first index.
|
||||||
final int listViewSelectedIndex = currentQualities.indexOf(currentQuality) - 1;
|
int listViewSelectedIndex = 0;
|
||||||
|
for (VideoQuality quality : currentQualities) {
|
||||||
|
if (quality == currentQuality) {
|
||||||
|
// -1 adjustment for the missing automatic quality in the dialog list.
|
||||||
|
listViewSelectedIndex--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
listViewSelectedIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
List<String> qualityLabels = new ArrayList<>(currentQualities.size() - 1);
|
List<String> qualityLabels = new ArrayList<>(currentQualities.length - 1);
|
||||||
for (VideoQuality availableQuality : currentQualities) {
|
for (VideoQuality availableQuality : currentQualities) {
|
||||||
if (availableQuality.patch_getResolution() != AUTOMATIC_VIDEO_QUALITY_VALUE) {
|
if (availableQuality.patch_getResolution() != AUTOMATIC_VIDEO_QUALITY_VALUE) {
|
||||||
qualityLabels.add(availableQuality.patch_getQualityName());
|
qualityLabels.add(availableQuality.patch_getQualityName());
|
||||||
|
|
@ -310,7 +318,7 @@ public class VideoQualityDialogButton {
|
||||||
listView.setOnItemClickListener((parent, view, which, id) -> {
|
listView.setOnItemClickListener((parent, view, which, id) -> {
|
||||||
try {
|
try {
|
||||||
final int originalIndex = which + 1; // Adjust for automatic.
|
final int originalIndex = which + 1; // Adjust for automatic.
|
||||||
VideoQuality selectedQuality = currentQualities.get(originalIndex);
|
VideoQuality selectedQuality = currentQualities[originalIndex];
|
||||||
Logger.printDebug(() -> "User clicked on quality: " + selectedQuality);
|
Logger.printDebug(() -> "User clicked on quality: " + selectedQuality);
|
||||||
|
|
||||||
if (RememberVideoQualityPatch.shouldRememberVideoQuality()) {
|
if (RememberVideoQualityPatch.shouldRememberVideoQuality()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue