mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
feat(YouTube Music - Change start page): Add more start pages (#135)
* feat(YouTube Music - Change start page): Add more start pages * Add more start pages * feat: Switch to `EnumSetting`, Add `Default`, `Samples` and `Search`, Remove `Home` --------- Co-authored-by: ILoveOpenSourceApplications <ILoveOpenSourceApplications@users.noreply.github.com> Co-authored-by: inotia00 <108592928+inotia00@users.noreply.github.com>
This commit is contained in:

committed by
GitHub

parent
eb24578186
commit
f7109f9815
@ -0,0 +1,115 @@
|
||||
package app.revanced.extension.music.patches.general;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import app.revanced.extension.music.settings.Settings;
|
||||
import app.revanced.extension.shared.utils.Logger;
|
||||
import app.revanced.extension.shared.utils.ResourceUtils;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class ChangeStartPagePatch {
|
||||
|
||||
public enum StartPage {
|
||||
/**
|
||||
* Unmodified type, and same as un-patched.
|
||||
*/
|
||||
ORIGINAL(""),
|
||||
|
||||
/**
|
||||
* Browse id.
|
||||
*/
|
||||
CHARTS("FEmusic_charts"),
|
||||
EXPLORE("FEmusic_explore"),
|
||||
HISTORY("FEmusic_history"),
|
||||
LIBRARY("FEmusic_library_landing"),
|
||||
PODCASTS("FEmusic_non_music_audio"),
|
||||
SAMPLES("FEmusic_immersive"),
|
||||
SUBSCRIPTIONS("FEmusic_library_corpus_artists"),
|
||||
|
||||
/**
|
||||
* Playlist id, this can be used as a browseId.
|
||||
*/
|
||||
EPISODES_FOR_LATER("VLSE"),
|
||||
LIKED_MUSIC("VLLM"),
|
||||
|
||||
/**
|
||||
* Intent extra.
|
||||
*/
|
||||
SEARCH("", 1, "Eh4IBRDTnQEYmgMiEwiZn+H0r5WLAxVV5OcDHcHRBmPqpd25AQA=");
|
||||
|
||||
@NonNull
|
||||
final String browseId;
|
||||
|
||||
final int shortcutType;
|
||||
|
||||
/**
|
||||
* Unique identifier for shortcut (Base64).
|
||||
*/
|
||||
@NonNull
|
||||
final String shortcutId;
|
||||
|
||||
StartPage(@NonNull String browseId) {
|
||||
this(browseId, 0, "");
|
||||
}
|
||||
|
||||
StartPage(@NonNull String browseId, int shortcutType, @NonNull String shortcutId) {
|
||||
this.browseId = browseId;
|
||||
this.shortcutType = shortcutType;
|
||||
this.shortcutId = shortcutId;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Intent action when YouTube is cold started from the launcher.
|
||||
*/
|
||||
private static final String ACTION_MAIN = "android.intent.action.MAIN";
|
||||
|
||||
private static final String SHORTCUT_ACTION = "com.google.android.youtube.music.action.shortcut";
|
||||
|
||||
private static final String SHORTCUT_CLASS_DESCRIPTOR = "com.google.android.apps.youtube.music.activities.InternalMusicActivity";
|
||||
|
||||
private static final String SHORTCUT_TYPE = "com.google.android.youtube.music.action.shortcut_type";
|
||||
|
||||
private static final StartPage START_PAGE = Settings.CHANGE_START_PAGE.get();
|
||||
|
||||
public static String overrideBrowseId(@NonNull String browseId) {
|
||||
if (!browseId.equals("FEmusic_home")) {
|
||||
return browseId;
|
||||
}
|
||||
final String overrideBrowseId = START_PAGE.browseId;
|
||||
if (overrideBrowseId.isEmpty()) {
|
||||
return browseId;
|
||||
}
|
||||
|
||||
Logger.printDebug(() -> "Changing browseId to " + START_PAGE.name());
|
||||
return overrideBrowseId;
|
||||
}
|
||||
|
||||
public static void overrideIntent(@NonNull Intent intent) {
|
||||
if (!StringUtils.equals(intent.getAction(), ACTION_MAIN)) {
|
||||
Logger.printDebug(() -> "Ignore override intent action" +
|
||||
" as the current activity is not the entry point of the application");
|
||||
return;
|
||||
}
|
||||
final String overrideShortcutId = START_PAGE.shortcutId;
|
||||
if (overrideShortcutId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Activity mActivity = ResourceUtils.getActivity();
|
||||
if (mActivity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.printDebug(() -> "Changing intent action to " + START_PAGE.name());
|
||||
intent.setAction(SHORTCUT_ACTION);
|
||||
intent.setClassName(mActivity, SHORTCUT_CLASS_DESCRIPTOR);
|
||||
intent.setPackage(mActivity.getPackageName());
|
||||
intent.putExtra(SHORTCUT_TYPE, START_PAGE.shortcutType);
|
||||
intent.putExtra(SHORTCUT_ACTION, overrideShortcutId);
|
||||
}
|
||||
}
|
@ -32,17 +32,6 @@ public class GeneralPatch {
|
||||
|
||||
// endregion
|
||||
|
||||
// region [Change start page] patch
|
||||
|
||||
public static String changeStartPage(final String browseId) {
|
||||
if (!browseId.equals("FEmusic_home"))
|
||||
return browseId;
|
||||
|
||||
return Settings.CHANGE_START_PAGE.get();
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region [Disable dislike redirection] patch
|
||||
|
||||
public static boolean disableDislikeRedirection() {
|
||||
|
@ -6,6 +6,7 @@ import static app.revanced.extension.music.sponsorblock.objects.CategoryBehaviou
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import app.revanced.extension.music.patches.general.ChangeStartPagePatch.StartPage;
|
||||
import app.revanced.extension.music.patches.misc.AlbumMusicVideoPatch.RedirectType;
|
||||
import app.revanced.extension.music.patches.misc.client.AppClient.ClientType;
|
||||
import app.revanced.extension.music.patches.utils.PatchStatus;
|
||||
@ -91,7 +92,7 @@ public class Settings extends BaseSettings {
|
||||
|
||||
|
||||
// PreferenceScreen: General
|
||||
public static final StringSetting CHANGE_START_PAGE = new StringSetting("revanced_change_start_page", "FEmusic_home", true);
|
||||
public static final EnumSetting<StartPage> CHANGE_START_PAGE = new EnumSetting<>("revanced_change_start_page", StartPage.ORIGINAL, true);
|
||||
public static final BooleanSetting DISABLE_DISLIKE_REDIRECTION = new BooleanSetting("revanced_disable_dislike_redirection", FALSE);
|
||||
public static final BooleanSetting ENABLE_LANDSCAPE_MODE = new BooleanSetting("revanced_enable_landscape_mode", FALSE, true);
|
||||
public static final BooleanSetting CUSTOM_FILTER = new BooleanSetting("revanced_custom_filter", FALSE);
|
||||
|
@ -136,9 +136,7 @@ public class ReVancedPreferenceFragment extends PreferenceFragment {
|
||||
|
||||
final Setting<?> settings = getSettingFromPath(dataString);
|
||||
if (settings instanceof StringSetting stringSetting) {
|
||||
if (settings.equals(CHANGE_START_PAGE)) {
|
||||
ResettableListPreference.showDialog(mActivity, stringSetting, 2);
|
||||
} else if (settings.equals(BYPASS_IMAGE_REGION_RESTRICTIONS_DOMAIN)
|
||||
if (settings.equals(BYPASS_IMAGE_REGION_RESTRICTIONS_DOMAIN)
|
||||
|| settings.equals(CUSTOM_FILTER_STRINGS)
|
||||
|| settings.equals(CUSTOM_PLAYBACK_SPEEDS)
|
||||
|| settings.equals(ENABLE_CUSTOM_NAVIGATION_BAR_COLOR_VALUE)
|
||||
@ -163,7 +161,8 @@ public class ReVancedPreferenceFragment extends PreferenceFragment {
|
||||
Logger.printDebug(() -> "Failed to find the right value: " + dataString);
|
||||
}
|
||||
} else if (settings instanceof EnumSetting<?> enumSetting) {
|
||||
if (settings.equals(DISABLE_MUSIC_VIDEO_IN_ALBUM_REDIRECT_TYPE)
|
||||
if (settings.equals(CHANGE_START_PAGE)
|
||||
|| settings.equals(DISABLE_MUSIC_VIDEO_IN_ALBUM_REDIRECT_TYPE)
|
||||
|| settings.equals(RETURN_YOUTUBE_USERNAME_DISPLAY_FORMAT)
|
||||
|| settings.equals(SPOOF_CLIENT_TYPE)
|
||||
|| settings.equals(SPOOF_STREAMING_DATA_TYPE)
|
||||
|
Reference in New Issue
Block a user