fix(YouTube Music): Fix crashes on Android 5-6 (#1321)

Co-authored-by: kitadai31 <90122968+kitadai31@users.noreply.github.com>
This commit is contained in:
Parsa307 2025-12-28 19:20:40 +03:30 committed by GitHub
parent d764aa6653
commit d13adb5401
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 23 additions and 11 deletions

View file

@ -98,7 +98,7 @@ class PlaylistRequest private constructor(
Objects.requireNonNull(videoId)
synchronized(cache) {
val now = System.currentTimeMillis()
cache.values.removeIf { request: PlaylistRequest ->
cache.values.removeAll { request ->
val expired = request.isExpired(now)
if (expired) Logger.printDebug { "Removing expired stream: " + request.videoId }
expired

View file

@ -11,6 +11,8 @@ import org.apache.commons.lang3.ArrayUtils;
import app.revanced.extension.shared.utils.ResourceUtils;
import static app.revanced.extension.shared.utils.Utils.isSDKAbove;
@SuppressWarnings("unused")
public class DrawableColorPatch {
private static final int[] DARK_COLORS = {
@ -55,7 +57,7 @@ public class DrawableColorPatch {
// headerGradient is litho, so this view is sometimes used elsewhere, like the button of the action bar.
// In order to prevent the gradient to be applied to the button of the action bar,
// Add a layout listener to the ImageView.
if (headerGradient != null && gradientView.getForeground() == null) {
if (isSDKAbove(23) && headerGradient != null && gradientView.getForeground() == null) {
gradientView.setForeground(headerGradient);
gradientView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
if (gradientView.getParent() instanceof View view &&

View file

@ -2,6 +2,7 @@ package app.revanced.extension.shared.patches.spoof;
import static app.revanced.extension.shared.innertube.utils.J2V8Support.supportJ2V8;
import static app.revanced.extension.shared.innertube.utils.StreamingDataOuterClassUtils.prioritizeResolution;
import static app.revanced.extension.shared.utils.Utils.isSDKAbove;
import android.net.Uri;
import android.text.TextUtils;
@ -341,7 +342,11 @@ public class SpoofStreamingDataPatch {
public static void initializeJavascript() {
if (SPOOF_STREAMING_DATA_USE_JS) {
// Download JavaScript and initialize the Cipher class
CompletableFuture.runAsync(ThrottlingParameterUtils::initializeJavascript);
if (isSDKAbove(24)) {
CompletableFuture.runAsync(ThrottlingParameterUtils::initializeJavascript);
} else {
Utils.runOnBackgroundThread(ThrottlingParameterUtils::initializeJavascript);
}
}
}

View file

@ -3,6 +3,7 @@ package app.revanced.extension.shared.settings;
import static app.revanced.extension.shared.utils.ResourceUtils.getIdIdentifier;
import static app.revanced.extension.shared.utils.ResourceUtils.getLayoutIdentifier;
import static app.revanced.extension.shared.utils.ResourceUtils.getStringIdentifier;
import static app.revanced.extension.shared.utils.Utils.isSDKAbove;
import android.annotation.SuppressLint;
import android.app.Activity;
@ -109,9 +110,11 @@ public abstract class BaseHostActivity extends Activity {
toolbar.setNavigationOnClickListener(getNavigationClickListener(this));
toolbar.setTitle(STRING_REVANCED_SETTINGS_TITLE);
final int margin = Utils.dipToPixels(16);
toolbar.setTitleMarginStart(margin);
toolbar.setTitleMarginEnd(margin);
if (isSDKAbove(24)) {
final int margin = Utils.dipToPixels(16);
toolbar.setTitleMarginStart(margin);
toolbar.setTitleMarginEnd(margin);
}
TextView toolbarTextView = Utils.getChildView(toolbar, false, view -> view instanceof TextView);
if (toolbarTextView != null) {
toolbarTextView.setTextColor(BaseThemeUtils.getAppForegroundColor());

View file

@ -228,9 +228,11 @@ public class WebViewHostActivity extends Activity {
toolbar.setNavigationIcon(BaseThemeUtils.getBackButtonDrawable(false));
toolbar.setNavigationOnClickListener(view -> this.finish());
toolbar.setTitle(toolbarLabel);
final int margin = Utils.dipToPixels(16);
toolbar.setTitleMarginStart(margin);
toolbar.setTitleMarginEnd(margin);
if (isSDKAbove(24)) {
final int margin = Utils.dipToPixels(16);
toolbar.setTitleMarginStart(margin);
toolbar.setTitleMarginEnd(margin);
}
TextView textView = Utils.getChildView(toolbar, view -> view instanceof TextView);
if (textView != null) {
textView.setTextColor(Color.BLACK);

View file

@ -94,7 +94,7 @@ public abstract class AbstractPreferenceFragment extends PreferenceFragment {
showSettingUserDialogConfirmation(pref, setting);
return;
} else if (setting.rebootApp) {
showRestartDialog(getContext());
showRestartDialog(getActivity());
}
}
@ -130,7 +130,7 @@ public abstract class AbstractPreferenceFragment extends PreferenceFragment {
private void showSettingUserDialogConfirmation(Preference pref, Setting<?> setting) {
Utils.verifyOnMainThread();
final var context = getContext();
final var context = getActivity();
if (confirmDialogTitle == null) {
confirmDialogTitle = str("revanced_confirm_user_dialog_title");
}