This repository has been archived by the owner on Oct 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: LisoUseInAIKyrios <[email protected]> Co-authored-by: kitadai31 <[email protected]>
- Loading branch information
1 parent
99d17bf
commit 61569ba
Showing
27 changed files
with
989 additions
and
521 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
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
126 changes: 117 additions & 9 deletions
126
app/src/main/java/app/revanced/integrations/youtube/patches/ChangeStartPagePatch.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 |
---|---|---|
@@ -1,21 +1,129 @@ | ||
package app.revanced.integrations.youtube.patches; | ||
|
||
import static java.lang.Boolean.FALSE; | ||
import static java.lang.Boolean.TRUE; | ||
|
||
import android.content.Intent; | ||
import android.net.Uri; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import app.revanced.integrations.shared.Logger; | ||
import app.revanced.integrations.youtube.settings.Settings; | ||
|
||
@SuppressWarnings("unused") | ||
public final class ChangeStartPagePatch { | ||
public static void changeIntent(final Intent intent) { | ||
final var startPage = Settings.START_PAGE.get(); | ||
if (startPage.isEmpty()) return; | ||
|
||
Logger.printDebug(() -> "Changing start page to " + startPage); | ||
public enum StartPage { | ||
/** | ||
* Unmodified type, and same as un-patched. | ||
*/ | ||
ORIGINAL("", null), | ||
|
||
/** | ||
* Browse id. | ||
*/ | ||
BROWSE("FEguide_builder", TRUE), | ||
EXPLORE("FEexplore", TRUE), | ||
HISTORY("FEhistory", TRUE), | ||
LIBRARY("FElibrary", TRUE), | ||
MOVIE("FEstorefront", TRUE), | ||
SUBSCRIPTIONS("FEsubscriptions", TRUE), | ||
TRENDING("FEtrending", TRUE), | ||
|
||
/** | ||
* Channel id, this can be used as a browseId. | ||
*/ | ||
GAMING("UCOpNcN46UbXVtpKMrmU4Abg", TRUE), | ||
LIVE("UC4R8DWoMoI7CAwX8_LjQHig", TRUE), | ||
MUSIC("UC-9-kyTW8ZkZNDHQJ6FgpwQ", TRUE), | ||
SPORTS("UCEgdi0XIXXZ-qJOFPf4JSKw", TRUE), | ||
|
||
/** | ||
* Playlist id, this can be used as a browseId. | ||
*/ | ||
LIKED_VIDEO("VLLL", TRUE), | ||
WATCH_LATER("VLWL", TRUE), | ||
|
||
/** | ||
* Intent action. | ||
*/ | ||
SEARCH("com.google.android.youtube.action.open.search", FALSE), | ||
SHORTS("com.google.android.youtube.action.open.shorts", FALSE); | ||
|
||
@Nullable | ||
final Boolean isBrowseId; | ||
|
||
@NonNull | ||
final String id; | ||
|
||
StartPage(@NonNull String id, @Nullable Boolean isBrowseId) { | ||
this.id = id; | ||
this.isBrowseId = isBrowseId; | ||
} | ||
|
||
private boolean isBrowseId() { | ||
return TRUE.equals(isBrowseId); | ||
} | ||
|
||
@SuppressWarnings("BooleanMethodIsAlwaysInverted") | ||
private boolean isIntentAction() { | ||
return FALSE.equals(isBrowseId); | ||
} | ||
} | ||
|
||
/** | ||
* Intent action when YouTube is cold started from the launcher. | ||
* <p> | ||
* If you don't check this, the hooking will also apply in the following cases: | ||
* Case 1. The user clicked Shorts button on the YouTube shortcut. | ||
* Case 2. The user clicked Shorts button on the YouTube widget. | ||
* In this case, instead of opening Shorts, the start page specified by the user is opened. | ||
*/ | ||
private static final String ACTION_MAIN = "android.intent.action.MAIN"; | ||
|
||
private static final StartPage START_PAGE = Settings.CHANGE_START_PAGE.get(); | ||
|
||
/** | ||
* There is an issue where the back button on the toolbar doesn't work properly. | ||
* As a workaround for this issue, instead of overriding the browserId multiple times, just override it once. | ||
*/ | ||
private static boolean appLaunched = false; | ||
|
||
public static String overrideBrowseId(@NonNull String original) { | ||
if (!START_PAGE.isBrowseId()) { | ||
return original; | ||
} | ||
|
||
if (appLaunched) { | ||
Logger.printDebug(() -> "Ignore override browseId as the app already launched"); | ||
return original; | ||
} | ||
appLaunched = true; | ||
|
||
Logger.printDebug(() -> "Changing browseId to " + START_PAGE.id); | ||
return START_PAGE.id; | ||
} | ||
|
||
public static void overrideIntentAction(@NonNull Intent intent) { | ||
if (!START_PAGE.isIntentAction()) { | ||
return; | ||
} | ||
|
||
if (!ACTION_MAIN.equals(intent.getAction())) { | ||
Logger.printDebug(() -> "Ignore override intent action" + | ||
" as the current activity is not the entry point of the application"); | ||
return; | ||
} | ||
|
||
if (appLaunched) { | ||
Logger.printDebug(() -> "Ignore override intent action as the app already launched"); | ||
return; | ||
} | ||
appLaunched = true; | ||
|
||
if (startPage.startsWith("www")) | ||
intent.setData(Uri.parse(startPage)); | ||
else | ||
intent.setAction("com.google.android.youtube.action." + startPage); | ||
final String intentAction = START_PAGE.id; | ||
Logger.printDebug(() -> "Changing intent action to " + intentAction); | ||
intent.setAction(intentAction); | ||
} | ||
} |
38 changes: 34 additions & 4 deletions
38
app/src/main/java/app/revanced/integrations/youtube/patches/HidePlayerButtonsPatch.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 |
---|---|---|
@@ -1,17 +1,47 @@ | ||
package app.revanced.integrations.youtube.patches; | ||
|
||
import android.view.View; | ||
|
||
import app.revanced.integrations.shared.Logger; | ||
import app.revanced.integrations.shared.Utils; | ||
import app.revanced.integrations.youtube.settings.Settings; | ||
|
||
@SuppressWarnings("unused") | ||
public final class HidePlayerButtonsPatch { | ||
|
||
private static final boolean HIDE_PLAYER_BUTTONS_ENABLED = Settings.HIDE_PLAYER_BUTTONS.get(); | ||
|
||
private static final int PLAYER_CONTROL_PREVIOUS_BUTTON_TOUCH_AREA_ID = | ||
Utils.getResourceIdentifier("player_control_previous_button_touch_area", "id"); | ||
|
||
private static final int PLAYER_CONTROL_NEXT_BUTTON_TOUCH_AREA_ID = | ||
Utils.getResourceIdentifier("player_control_next_button_touch_area", "id"); | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static boolean previousOrNextButtonIsVisible(boolean previousOrNextButtonVisible) { | ||
if (Settings.HIDE_PLAYER_BUTTONS.get()) { | ||
return false; | ||
public static void hidePreviousNextButtons(View parentView) { | ||
if (!HIDE_PLAYER_BUTTONS_ENABLED) { | ||
return; | ||
} | ||
|
||
// Must use a deferred call to main thread to hide the button. | ||
// Otherwise the layout crashes if set to hidden now. | ||
Utils.runOnMainThread(() -> { | ||
hideView(parentView, PLAYER_CONTROL_PREVIOUS_BUTTON_TOUCH_AREA_ID); | ||
hideView(parentView, PLAYER_CONTROL_NEXT_BUTTON_TOUCH_AREA_ID); | ||
}); | ||
} | ||
|
||
private static void hideView(View parentView, int resourceId) { | ||
View nextPreviousButton = parentView.findViewById(resourceId); | ||
|
||
if (nextPreviousButton == null) { | ||
Logger.printException(() -> "Could not find player previous/next button"); | ||
return; | ||
} | ||
return previousOrNextButtonVisible; | ||
|
||
Logger.printDebug(() -> "Hiding previous/next button"); | ||
Utils.hideViewByRemovingFromParentUnderCondition(true, nextPreviousButton); | ||
} | ||
} |
Oops, something went wrong.