forked from ReVanced/revanced-integrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Merge branch
feat/yt-bump
to dev
- Loading branch information
1 parent
c12b9a3
commit 48a7ac4
Showing
22 changed files
with
865 additions
and
499 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); | ||
} | ||
} |
Oops, something went wrong.