This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
forked from ReVanced/revanced-integrations
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube): add
Miniplayer
patch (Replaces `Enable tablet mini p…
…layer` patch)
- Loading branch information
Showing
5 changed files
with
245 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
app/src/main/java/app/revanced/integrations/youtube/patches/general/MiniplayerPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
package app.revanced.integrations.youtube.patches.general; | ||
|
||
import static app.revanced.integrations.youtube.patches.general.MiniplayerPatch.MiniplayerType.MODERN_1; | ||
import static app.revanced.integrations.youtube.patches.general.MiniplayerPatch.MiniplayerType.MODERN_2; | ||
import static app.revanced.integrations.youtube.patches.general.MiniplayerPatch.MiniplayerType.MODERN_3; | ||
import static app.revanced.integrations.youtube.patches.general.MiniplayerPatch.MiniplayerType.ORIGINAL; | ||
import static app.revanced.integrations.youtube.utils.ExtendedUtils.validateValue; | ||
|
||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import app.revanced.integrations.shared.utils.Logger; | ||
import app.revanced.integrations.shared.utils.ResourceUtils; | ||
import app.revanced.integrations.shared.utils.Utils; | ||
import app.revanced.integrations.youtube.settings.Settings; | ||
|
||
@SuppressWarnings("unused") | ||
public final class MiniplayerPatch { | ||
|
||
/** | ||
* Mini player type. Null fields indicates to use the original un-patched value. | ||
*/ | ||
public enum MiniplayerType { | ||
/** Unmodified type, and same as un-patched. */ | ||
ORIGINAL(null, null), | ||
PHONE(false, null), | ||
TABLET(true, null), | ||
MODERN_1(null, 1), | ||
MODERN_2(null, 2), | ||
MODERN_3(null, 3); | ||
|
||
/** | ||
* Legacy tablet hook value. | ||
*/ | ||
@Nullable | ||
final Boolean legacyTabletOverride; | ||
|
||
/** | ||
* Modern player type used by YT. | ||
*/ | ||
@Nullable | ||
final Integer modernPlayerType; | ||
|
||
MiniplayerType(@Nullable Boolean legacyTabletOverride, @Nullable Integer modernPlayerType) { | ||
this.legacyTabletOverride = legacyTabletOverride; | ||
this.modernPlayerType = modernPlayerType; | ||
} | ||
|
||
public boolean isModern() { | ||
return modernPlayerType != null; | ||
} | ||
} | ||
|
||
/** | ||
* Modern subtitle overlay for {@link MiniplayerType#MODERN_2}. | ||
* Resource is not present in older targets, and this field will be zero. | ||
*/ | ||
private static final int MODERN_OVERLAY_SUBTITLE_TEXT | ||
= ResourceUtils.getIdIdentifier("modern_miniplayer_subtitle_text"); | ||
|
||
private static final MiniplayerType CURRENT_TYPE = Settings.MINIPLAYER_TYPE.get(); | ||
|
||
private static final boolean HIDE_EXPAND_CLOSE_ENABLED = | ||
(CURRENT_TYPE == MODERN_1 || CURRENT_TYPE == MODERN_3) && Settings.MINIPLAYER_HIDE_EXPAND_CLOSE.get(); | ||
|
||
private static final boolean HIDE_SUBTEXT_ENABLED = | ||
(CURRENT_TYPE == MODERN_1 || CURRENT_TYPE == MODERN_3) && Settings.MINIPLAYER_HIDE_SUBTEXT.get(); | ||
|
||
private static final boolean HIDE_REWIND_FORWARD_ENABLED = | ||
CURRENT_TYPE == MODERN_1 && Settings.MINIPLAYER_HIDE_REWIND_FORWARD.get(); | ||
|
||
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; | ||
} | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static boolean getLegacyTabletMiniplayerOverride(boolean original) { | ||
Boolean isTablet = CURRENT_TYPE.legacyTabletOverride; | ||
return isTablet == null | ||
? original | ||
: isTablet; | ||
} | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static boolean getModernMiniplayerOverride(boolean original) { | ||
return CURRENT_TYPE == ORIGINAL | ||
? original | ||
: CURRENT_TYPE.isModern(); | ||
} | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static int getModernMiniplayerOverrideType(int original) { | ||
Integer modernValue = CURRENT_TYPE.modernPlayerType; | ||
return modernValue == null | ||
? original | ||
: modernValue; | ||
} | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static void adjustMiniplayerOpacity(ImageView view) { | ||
if (CURRENT_TYPE == MODERN_1) { | ||
view.setImageAlpha(OPACITY_LEVEL); | ||
} | ||
} | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static void hideMiniplayerExpandClose(ImageView view) { | ||
Utils.hideViewByRemovingFromParentUnderCondition(HIDE_EXPAND_CLOSE_ENABLED, view); | ||
} | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static void hideMiniplayerRewindForward(ImageView view) { | ||
Utils.hideViewByRemovingFromParentUnderCondition(HIDE_REWIND_FORWARD_ENABLED, view); | ||
} | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static void hideMiniplayerSubTexts(View view) { | ||
// Different subviews are passed in, but only TextView and layouts are of interest here. | ||
final boolean hideView = HIDE_SUBTEXT_ENABLED && (view instanceof TextView || view instanceof LinearLayout); | ||
Utils.hideViewByRemovingFromParentUnderCondition(hideView, view); | ||
} | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static void playerOverlayGroupCreated(View group) { | ||
// Modern 2 has an half broken subtitle that is always present. | ||
// Always hide it to make the miniplayer mostly usable. | ||
if (CURRENT_TYPE == MODERN_2 && MODERN_OVERLAY_SUBTITLE_TEXT != 0) { | ||
if (group instanceof ViewGroup viewGroup) { | ||
View subtitleText = Utils.getChildView(viewGroup, true, | ||
view -> view.getId() == MODERN_OVERLAY_SUBTITLE_TEXT); | ||
|
||
if (subtitleText != null) { | ||
subtitleText.setVisibility(View.GONE); | ||
Logger.printDebug(() -> "Modern overlay subtitle view set to hidden"); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters