feat(YouTube - Overlay buttons): Add missing ALL_CONTENTS_WITH_TIME_ASCENDING type (#105)

* Add `ALL_CONTENTS_WITH_TIME_ASCENDING` type

* Rewrite function

* Update arrays.xml

* Update strings.xml

* Update strings.xml

* chore: Simplify

* fix: Apply code review suggestions

---------

Co-authored-by: inotia00 <108592928+inotia00@users.noreply.github.com>
This commit is contained in:
Hoàng Gia Bảo 2024-12-15 13:33:50 +07:00 committed by GitHub
parent dad6b3d5e4
commit 7023e5b323
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 33 deletions

View File

@ -7,18 +7,19 @@ public enum PlaylistIdPrefix {
* To check all available prefixes, * To check all available prefixes,
* See <a href="https://github.com/RobertWesner/YouTube-Play-All/blob/main/documentation/available-lists.md">this document</a>. * See <a href="https://github.com/RobertWesner/YouTube-Play-All/blob/main/documentation/available-lists.md">this document</a>.
*/ */
ALL_CONTENTS_WITH_TIME_DESCENDING("UU"), ALL_CONTENTS_WITH_TIME_ASCENDING("UL", false),
ALL_CONTENTS_WITH_POPULAR_DESCENDING("PU"), ALL_CONTENTS_WITH_TIME_DESCENDING("UU", true),
VIDEOS_ONLY_WITH_TIME_DESCENDING("UULF"), ALL_CONTENTS_WITH_POPULAR_DESCENDING("PU", true),
VIDEOS_ONLY_WITH_POPULAR_DESCENDING("UULP"), VIDEOS_ONLY_WITH_TIME_DESCENDING("UULF", true),
SHORTS_ONLY_WITH_TIME_DESCENDING("UUSH"), VIDEOS_ONLY_WITH_POPULAR_DESCENDING("UULP", true),
SHORTS_ONLY_WITH_POPULAR_DESCENDING("UUPS"), SHORTS_ONLY_WITH_TIME_DESCENDING("UUSH", true),
LIVESTREAMS_ONLY_WITH_TIME_DESCENDING("UULV"), SHORTS_ONLY_WITH_POPULAR_DESCENDING("UUPS", true),
LIVESTREAMS_ONLY_WITH_POPULAR_DESCENDING("UUPV"), LIVESTREAMS_ONLY_WITH_TIME_DESCENDING("UULV", true),
ALL_MEMBERSHIPS_CONTENTS("UUMO"), LIVESTREAMS_ONLY_WITH_POPULAR_DESCENDING("UUPV", true),
MEMBERSHIPS_VIDEOS_ONLY("UUMF"), ALL_MEMBERSHIPS_CONTENTS("UUMO", true),
MEMBERSHIPS_SHORTS_ONLY("UUMS"), MEMBERSHIPS_VIDEOS_ONLY("UUMF", true),
MEMBERSHIPS_LIVESTREAMS_ONLY("UUMV"); MEMBERSHIPS_SHORTS_ONLY("UUMS", true),
MEMBERSHIPS_LIVESTREAMS_ONLY("UUMV", true);
/** /**
* Prefix of playlist id. * Prefix of playlist id.
@ -26,7 +27,13 @@ public enum PlaylistIdPrefix {
@NonNull @NonNull
public final String prefixId; public final String prefixId;
PlaylistIdPrefix(@NonNull String prefixId) { /**
* Whether to use channelId.
*/
public final boolean useChannelId;
PlaylistIdPrefix(@NonNull String prefixId, boolean useChannelId) {
this.prefixId = prefixId; this.prefixId = prefixId;
this.useChannelId = useChannelId;
} }
} }

View File

@ -7,7 +7,6 @@ import static app.revanced.extension.youtube.patches.video.PlaybackSpeedPatch.us
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.media.AudioManager; import android.media.AudioManager;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -128,34 +127,37 @@ public class VideoUtils extends IntentUtils {
} }
public static void openVideo(@NonNull String videoId) { public static void openVideo(@NonNull String videoId) {
openVideo(getVideoScheme(videoId, false), ""); openVideo(getVideoScheme(videoId, false), false, null);
} }
public static void openVideo(@NonNull String videoId, boolean isShorts) { public static void openVideo(@NonNull String videoId, boolean isShorts) {
openVideo(getVideoScheme(videoId, isShorts), ""); openVideo(getVideoScheme(videoId, isShorts), isShorts, null);
} }
public static void openVideo(@NonNull PlaylistIdPrefix prefixId) { public static void openVideo(@NonNull PlaylistIdPrefix playlistIdPrefix) {
openVideo(getVideoScheme(), prefixId.prefixId); openVideo(getVideoScheme(), false, playlistIdPrefix);
} }
/** public static void openVideo(@NonNull String videoId, boolean isShorts, @Nullable PlaylistIdPrefix playlistIdPrefix) {
* Create playlist with all channel videos. final StringBuilder sb = new StringBuilder(getVideoScheme(videoId, isShorts));
*/ // Create playlist with all channel videos.
public static void openVideo(@NonNull String videoScheme, @NonNull String prefixId) { if (playlistIdPrefix != null) {
if (!TextUtils.isEmpty(prefixId)) { sb.append("&list=");
sb.append(playlistIdPrefix.prefixId);
if (playlistIdPrefix.useChannelId) {
final String channelId = VideoInformation.getChannelId(); final String channelId = VideoInformation.getChannelId();
// Channel id always starts with `UC` prefix // Channel id always starts with `UC` prefix
if (!channelId.startsWith("UC")) { if (!channelId.startsWith("UC")) {
showToastShort(str("revanced_overlay_button_play_all_not_available_toast")); showToastShort(str("revanced_overlay_button_play_all_not_available_toast"));
return; return;
} }
videoScheme += "&list=" + prefixId + channelId.substring(2); sb.append(channelId.substring(2));
} else {
sb.append(videoId);
}
} }
final String finalVideoScheme = videoScheme;
Logger.printInfo(() -> finalVideoScheme);
launchView(videoScheme, getContext().getPackageName()); launchView(sb.toString(), getContext().getPackageName());
} }
/** /**

View File

@ -136,6 +136,7 @@
<item>https://github.com/deniscerri/ytdlnis/releases/latest</item> <item>https://github.com/deniscerri/ytdlnis/releases/latest</item>
</string-array> </string-array>
<string-array name="revanced_overlay_button_play_all_type_entries"> <string-array name="revanced_overlay_button_play_all_type_entries">
<item>@string/revanced_overlay_button_play_all_type_entry_0</item>
<item>@string/revanced_overlay_button_play_all_type_entry_1</item> <item>@string/revanced_overlay_button_play_all_type_entry_1</item>
<item>@string/revanced_overlay_button_play_all_type_entry_2</item> <item>@string/revanced_overlay_button_play_all_type_entry_2</item>
<item>@string/revanced_overlay_button_play_all_type_entry_3</item> <item>@string/revanced_overlay_button_play_all_type_entry_3</item>
@ -150,6 +151,7 @@
<item>@string/revanced_overlay_button_play_all_type_entry_12</item> <item>@string/revanced_overlay_button_play_all_type_entry_12</item>
</string-array> </string-array>
<string-array name="revanced_overlay_button_play_all_type_entry_values"> <string-array name="revanced_overlay_button_play_all_type_entry_values">
<item>ALL_CONTENTS_WITH_TIME_ASCENDING</item>
<item>ALL_CONTENTS_WITH_TIME_DESCENDING</item> <item>ALL_CONTENTS_WITH_TIME_DESCENDING</item>
<item>ALL_CONTENTS_WITH_POPULAR_DESCENDING</item> <item>ALL_CONTENTS_WITH_POPULAR_DESCENDING</item>
<item>VIDEOS_ONLY_WITH_TIME_DESCENDING</item> <item>VIDEOS_ONLY_WITH_TIME_DESCENDING</item>

View File

@ -1057,6 +1057,7 @@ Tap and hold to undo.
Info: Info:
• May not work on livestreams."</string> • May not work on livestreams."</string>
<string name="revanced_overlay_button_play_all_type_title">Generate playlist mode</string> <string name="revanced_overlay_button_play_all_type_title">Generate playlist mode</string>
<string name="revanced_overlay_button_play_all_type_entry_0">All contents (Sort by time, Ascending)</string>
<string name="revanced_overlay_button_play_all_type_entry_1">All contents (Sort by time)</string> <string name="revanced_overlay_button_play_all_type_entry_1">All contents (Sort by time)</string>
<string name="revanced_overlay_button_play_all_type_entry_2">All contents (Sort by popular)</string> <string name="revanced_overlay_button_play_all_type_entry_2">All contents (Sort by popular)</string>
<string name="revanced_overlay_button_play_all_type_entry_3">Videos only (Sort by time)</string> <string name="revanced_overlay_button_play_all_type_entry_3">Videos only (Sort by time)</string>