mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-03 16:14:28 +02:00
fix(YouTube - Miniplayer): Patched app crashes after first launch or clearing data
This commit is contained in:
parent
8d045bc618
commit
74d39ff034
@ -12,6 +12,8 @@ import static app.revanced.extension.youtube.utils.ExtendedUtils.IS_19_26_OR_GRE
|
||||
import static app.revanced.extension.youtube.utils.ExtendedUtils.IS_19_29_OR_GREATER;
|
||||
import static app.revanced.extension.youtube.utils.ExtendedUtils.validateValue;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -82,11 +84,24 @@ public final class MiniplayerPatch {
|
||||
}
|
||||
}
|
||||
|
||||
private static final int MINIPLAYER_SIZE;
|
||||
private static int MINIPLAYER_SIZE = 0;
|
||||
|
||||
static {
|
||||
setMiniPlayerSize();
|
||||
}
|
||||
|
||||
private static void setMiniPlayerSize() {
|
||||
try {
|
||||
Context context = Utils.getContext();
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
Resources resources = context.getResources();
|
||||
if (resources == null) {
|
||||
return;
|
||||
}
|
||||
// YT appears to use the device screen dip width, plus an unknown fixed horizontal padding size.
|
||||
DisplayMetrics displayMetrics = Utils.getContext().getResources().getDisplayMetrics();
|
||||
DisplayMetrics displayMetrics = resources.getDisplayMetrics();
|
||||
final int deviceDipWidth = (int) (displayMetrics.widthPixels / displayMetrics.density);
|
||||
|
||||
// YT seems to use a minimum height to calculate the minimum miniplayer width based on the video.
|
||||
@ -116,15 +131,9 @@ public final class MiniplayerPatch {
|
||||
}
|
||||
|
||||
MINIPLAYER_SIZE = dipWidth;
|
||||
|
||||
final int opacity = validateValue(
|
||||
Settings.MINIPLAYER_OPACITY,
|
||||
0,
|
||||
100,
|
||||
"revanced_miniplayer_opacity_invalid_toast"
|
||||
);
|
||||
|
||||
OPACITY_LEVEL = (opacity * 255) / 100;
|
||||
} catch (Exception ex) {
|
||||
Logger.printException(() -> "setMiniPlayerSize failure", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,6 +184,17 @@ public final class MiniplayerPatch {
|
||||
|
||||
private static final int OPACITY_LEVEL;
|
||||
|
||||
static {
|
||||
final int opacity = validateValue(
|
||||
Settings.MINIPLAYER_OPACITY,
|
||||
0,
|
||||
100,
|
||||
"revanced_miniplayer_opacity_invalid_toast"
|
||||
);
|
||||
|
||||
OPACITY_LEVEL = (opacity * 255) / 100;
|
||||
}
|
||||
|
||||
public static final class MiniplayerHorizontalDragAvailability implements Setting.Availability {
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
@ -293,8 +313,13 @@ public final class MiniplayerPatch {
|
||||
*/
|
||||
public static int setMiniplayerDefaultSize(int original) {
|
||||
if (CURRENT_TYPE.isModern()) {
|
||||
if (MINIPLAYER_SIZE == 0) {
|
||||
setMiniPlayerSize();
|
||||
}
|
||||
if (MINIPLAYER_SIZE != 0) {
|
||||
return MINIPLAYER_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
return original;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user