Add player button in navbar

This commit is contained in:
Bryce Hackel
2024-08-25 14:04:32 -07:00
parent 7083d30d9c
commit fa922a1acd
20 changed files with 148 additions and 52 deletions

View File

@@ -41,8 +41,6 @@ static int appVersionSpoofer() {
@interface YTSettingsSectionItemManager (YTLitePlus)
- (void)updateYTLitePlusSectionWithEntry:(id)entry;
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls;
- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller;
@end
extern NSBundle *YTLitePlusBundle();
@@ -194,29 +192,6 @@ static const NSInteger YTLiteSection = 789;
];
[sectionItems addObject:pasteSettings];
YTSettingsSectionItem *videoPlayer = [%c(YTSettingsSectionItem)
itemWithTitle:LOC(@"VIDEO_PLAYER")
titleDescription:LOC(@"VIDEO_PLAYER_DESC")
accessibilityIdentifier:nil
detailTextBlock:nil
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
// Access the current view controller
UIViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"];
if (settingsViewController) {
// Present the video picker
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[(NSString *)kUTTypeMovie, (NSString *)kUTTypeVideo] inMode:UIDocumentPickerModeImport];
documentPicker.delegate = (id<UIDocumentPickerDelegate>)self;
documentPicker.allowsMultipleSelection = NO;
[settingsViewController presentViewController:documentPicker animated:YES completion:nil];
} else {
NSLog(@"settingsViewController is nil");
}
return YES; // Return YES to indicate that the action was handled
}
];
[sectionItems addObject:videoPlayer];
/*
YTSettingsSectionItem *appIcon = [%c(YTSettingsSectionItem)
itemWithTitle:LOC(@"CHANGE_APP_ICON")
@@ -652,6 +627,7 @@ static const NSInteger YTLiteSection = 789;
BASIC_SWITCH(LOC(@"CAST_CONFIRM"), LOC(@"CAST_CONFIRM_DESC"), @"castConfirm_enabled"),
BASIC_SWITCH(LOC(@"NEW_MINIPLAYER_STYLE"), LOC(@"NEW_MINIPLAYER_STYLE_DESC"), @"bigYTMiniPlayer_enabled"),
BASIC_SWITCH(LOC(@"HIDE_CAST_BUTTON"), LOC(@"HIDE_CAST_BUTTON_DESC"), @"hideCastButton_enabled"),
BASIC_SWITCH(LOC(@"VIDEO_PLAYER_BUTTON"), LOC(@"VIDEO_PLAYER_BUTTON_DESC"), @"videoPlayerButton_enabled"),
BASIC_SWITCH(LOC(@"HIDE_SPONSORBLOCK_BUTTON"), LOC(@"HIDE_SPONSORBLOCK_BUTTON_DESC"), @"hideSponsorBlockButton_enabled"),
BASIC_SWITCH(LOC(@"HIDE_HOME_TAB"), LOC(@"HIDE_HOME_TAB_DESC"), @"hideHomeTab_enabled"),
BASIC_SWITCH(LOC(@"FIX_CASTING"), LOC(@"FIX_CASTING_DESC"), @"fixCasting_enabled"),
@@ -679,30 +655,5 @@ static const NSInteger YTLiteSection = 789;
%orig;
}
// Implement the delegate method for document picker
%new
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
NSURL *pickedURL = [urls firstObject];
if (pickedURL) {
// Use AVPlayerViewController to play the video
AVPlayer *player = [AVPlayer playerWithURL:pickedURL];
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = player;
UIViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"];
if (settingsViewController) {
[settingsViewController presentViewController:playerViewController animated:YES completion:^{
[player play];
}];
}
}
}
%new
- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
// Handle cancellation if needed
NSLog(@"Document picker was cancelled");
}
%end

View File

@@ -46,6 +46,8 @@
#import "Tweaks/YouTubeHeader/YTMainAppControlsOverlayView.h"
#import "Tweaks/YouTubeHeader/YTMultiSizeViewController.h"
#import "Tweaks/YouTubeHeader/YTWatchLayerViewController.h"
#import "Tweaks/YouTubeHeader/YTPageStyleController.h"
#import "Tweaks/YouTubeHeader/YTRightNavigationButtons.h"
#define LOC(x) [tweakBundle localizedStringForKey:x value:nil table:nil]
#define YT_BUNDLE_ID @"com.google.ios.youtube"
@@ -172,9 +174,10 @@ typedef NS_ENUM(NSUInteger, GestureSection) {
@interface MDCButton : UIButton
@end
@interface YTRightNavigationButtons : UIView
@interface YTRightNavigationButtons (YTLitePlus)
@property YTQTMButton *notificationButton;
@property YTQTMButton *sponsorBlockButton;
@property YTQTMButton *videoPlayerButton;
@end
// BigYTMiniPlayer

View File

@@ -872,6 +872,100 @@ BOOL isTabSelected = NO;
%end
%end
// Video player button in the navigation bar - @bhackel
// This code is based on the iSponsorBlock button code
%group gVideoPlayerButton
NSInteger pageStyle = 0;
%hook YTRightNavigationButtons
%property (retain, nonatomic) YTQTMButton *videoPlayerButton;
- (NSMutableArray *)buttons {
NSMutableArray *retVal = %orig.mutableCopy;
[self.videoPlayerButton removeFromSuperview];
[self addSubview:self.videoPlayerButton];
if (!self.videoPlayerButton || pageStyle != [%c(YTPageStyleController) pageStyle]) {
self.videoPlayerButton = [%c(YTQTMButton) iconButton];
[self.videoPlayerButton enableNewTouchFeedback];
self.videoPlayerButton.frame = CGRectMake(0, 0, 40, 40);
if ([%c(YTPageStyleController) pageStyle]) { //dark mode
[self.videoPlayerButton setImage:[UIImage imageWithContentsOfFile:[tweakBundle pathForResource:@"YTLitePlusColored-1024" ofType:@"png"]] forState:UIControlStateNormal];
}
else { // light mode
UIImage *image = [UIImage imageWithContentsOfFile:[tweakBundle pathForResource:@"YTLitePlusColored-1024" ofType:@"png"]];
image = [image imageWithTintColor:UIColor.blackColor renderingMode:UIImageRenderingModeAlwaysTemplate];
[self.videoPlayerButton setImage:image forState:UIControlStateNormal];
[self.videoPlayerButton setTintColor:UIColor.blackColor];
}
pageStyle = [%c(YTPageStyleController) pageStyle];
[self.videoPlayerButton addTarget:self action:@selector(videoPlayerButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[retVal insertObject:self.videoPlayerButton atIndex:0];
}
return retVal;
}
- (NSMutableArray *)visibleButtons {
NSMutableArray *retVal = %orig.mutableCopy;
// fixes button overlapping yt logo on smaller devices
[self setLeadingPadding:-10];
if (self.videoPlayerButton) {
[self.videoPlayerButton removeFromSuperview];
[self addSubview:self.videoPlayerButton];
[retVal insertObject:self.videoPlayerButton atIndex:0];
}
return retVal;
}
// Method to handle the video player button press by showing a document picker
%new
- (void)videoPlayerButtonPressed:(UIButton *)sender {
// Traversing the responder chain to find the nearest UIViewController
UIResponder *responder = sender;
UIViewController *settingsViewController = nil;
while (responder) {
if ([responder isKindOfClass:[UIViewController class]]) {
settingsViewController = (UIViewController *)responder;
break;
}
responder = responder.nextResponder;
}
if (settingsViewController) {
// Present the video picker
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[(NSString *)kUTTypeMovie, (NSString *)kUTTypeVideo] inMode:UIDocumentPickerModeImport];
documentPicker.delegate = (id<UIDocumentPickerDelegate>)self;
documentPicker.allowsMultipleSelection = NO;
[settingsViewController presentViewController:documentPicker animated:YES completion:nil];
} else {
NSLog(@"No view controller found for the sender button.");
}
}
// Delegate method to handle the picked video by showing the apple player
%new
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
NSURL *pickedURL = [urls firstObject];
if (pickedURL) {
// Use AVPlayerViewController to play the video
AVPlayer *player = [AVPlayer playerWithURL:pickedURL];
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = player;
// Get the root view controller
UIViewController *presentingViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
// Present the Video Player
if (presentingViewController) {
[presentingViewController presentViewController:playerViewController animated:YES completion:^{
[player play];
}];
} else {
// Handle case where no view controller was found
NSLog(@"Error: No view controller found to present AVPlayerViewController.");
}
}
}
%end
%end
// App Settings Overlay Options
%group gDisableAccountSection
%hook YTSettingsSectionItemManager
@@ -1064,6 +1158,9 @@ BOOL isTabSelected = NO;
if (IsEnabled(@"playerGestures_enabled")) {
%init(playerGestures);
}
if (IsEnabled(@"videoPlayerButton_enabled")) {
%init(gVideoPlayerButton);
}
// Change the default value of some options
NSArray *allKeys = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys];
@@ -1079,6 +1176,9 @@ BOOL isTabSelected = NO;
if (![allKeys containsObject:@"fixCasting_enabled"]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"fixCasting_enabled"];
}
if (![allKeys containsObject:@"videoPlayerButton_enabled"]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"videoPlayerButton_enabled"];
}
// Default gestures as volume, brightness, seek
if (![allKeys containsObject:@"playerGestureTopSelection"]) {
[[NSUserDefaults standardUserDefaults] setInteger:GestureModeVolume forKey:@"playerGestureTopSelection"];

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -163,6 +163,9 @@
"HIDE_CAST_BUTTON" = "زر "إخفاء الإرسال" ;
"HIDE_CAST_BUTTON_DESC" = "مطلوب إعادة تشغيل التطبيق";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_SPONSORBLOCK_BUTTON" = "Hide iSponsorBlock button in the Navigation bar";
"HIDE_SPONSORBLOCK_BUTTON_DESC" = "";

View File

@@ -163,6 +163,9 @@
"HIDE_CAST_BUTTON" = "Скрийте бутона за стрийминг";
"HIDE_CAST_BUTTON_DESC" = "Необходим е рестарт на приложението.";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_SPONSORBLOCK_BUTTON" = "Скрийте бутона за iSponsorBlock в навигационната лента";
"HIDE_SPONSORBLOCK_BUTTON_DESC" = "";

View File

@@ -163,6 +163,9 @@
"HIDE_CAST_BUTTON" = "Cast button verstecken";
"HIDE_CAST_BUTTON_DESC" = "Google-Cast Button verstecken. Ein Neustart der App ist erforderlich.";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_SPONSORBLOCK_BUTTON" = "iSponsorBlock ausblenden";
"HIDE_SPONSORBLOCK_BUTTON_DESC" = "Blende die iSponsorBlock-Schaltfläche in der Navigationsleiste aus";

View File

@@ -163,6 +163,9 @@
"HIDE_CAST_BUTTON" = "Hide Cast button";
"HIDE_CAST_BUTTON_DESC" = "App restart is required.";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_SPONSORBLOCK_BUTTON" = "Hide iSponsorBlock button in the Navigation bar";
"HIDE_SPONSORBLOCK_BUTTON_DESC" = "";

View File

@@ -163,6 +163,9 @@
"HIDE_CAST_BUTTON" = "Ocultar botón Emitir";
"HIDE_CAST_BUTTON_DESC" = "Es necesario reiniciar la aplicación";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_SPONSORBLOCK_BUTTON" = "Ocultar el botón iSponsorBlock en la barra de navegación";
"HIDE_SPONSORBLOCK_BUTTON_DESC" = "";

View File

@@ -166,6 +166,9 @@
"HIDE_CAST_BUTTON" = "Masquer le bouton Cast";
"HIDE_CAST_BUTTON_DESC" = "Un redémarrage de l'application est requis.";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_SPONSORBLOCK_BUTTON" = "Masquer le bouton iSponsorBlock dans la barre de navigation";
"HIDE_SPONSORBLOCK_BUTTON_DESC" = "";

View File

@@ -163,6 +163,9 @@
"HIDE_CAST_BUTTON" = "キャストボタンを非表示";
"HIDE_CAST_BUTTON_DESC" = "アプリの再起動が必要です。";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_SPONSORBLOCK_BUTTON" = "ナビゲーションバーのiSponsorBlockボタンを非表示";
"HIDE_SPONSORBLOCK_BUTTON_DESC" = "";

View File

@@ -164,6 +164,9 @@
"HIDE_CAST_BUTTON" = "Ocultar o botão Transmitir";
"HIDE_CAST_BUTTON_DESC" = "A reinicialização do app é necessária.";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_SPONSORBLOCK_BUTTON" = "Ocultar o botão iSponsorBlock na barra de navegação";
"HIDE_SPONSORBLOCK_BUTTON_DESC" = "";

View File

@@ -163,6 +163,9 @@
"HIDE_CAST_BUTTON" = "Ascundere buton Proiectare";
"HIDE_CAST_BUTTON_DESC" = "Este necesară repornirea aplicației.";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_SPONSORBLOCK_BUTTON" = "Ascundere buton iSponsorBlock în bara de navigație";
"HIDE_SPONSORBLOCK_BUTTON_DESC" = "";

View File

@@ -163,6 +163,9 @@
"HIDE_CAST_BUTTON" = "Скрыть кнопку «Транслировать»";
"HIDE_CAST_BUTTON_DESC" = "Потребуется перезагрузка.";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_SPONSORBLOCK_BUTTON" = "Hide iSponsorBlock button in the Navigation bar";
"HIDE_SPONSORBLOCK_BUTTON_DESC" = "";

View File

@@ -178,6 +178,9 @@ https://github.com/PoomSmart/Return-YouTube-Dislikes/tree/main/layout/Library/Ap
"HIDE_CAST_BUTTON" = "Hide Cast button";
"HIDE_CAST_BUTTON_DESC" = "App restart is required.";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_SPONSORBLOCK_BUTTON" = "Hide iSponsorBlock button in the Navigation bar";
"HIDE_SPONSORBLOCK_BUTTON_DESC" = "";

View File

@@ -163,6 +163,9 @@
"HIDE_CAST_BUTTON" = "Yayınla düğmesini gizle";
"HIDE_CAST_BUTTON_DESC" = "Yeniden başlatılmalı.";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_SPONSORBLOCK_BUTTON" = "Gezinme çubuğunda iSponsorBlock düğmesini gizle";
"HIDE_SPONSORBLOCK_BUTTON_DESC" = "";

View File

@@ -229,6 +229,9 @@
"HIDE_CAST_BUTTON" = "Ẩn nút Truyền";
"HIDE_CAST_BUTTON_DESC" = "Khởi động lại ứng dụng là bắt buộc.";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_HOVER_CARD" = "Ẩn thẻ di chuột trên Màn hình kết thúc (YTNoHoverCards)";
"HIDE_HOVER_CARD_DESC" = "Ẩn màn hình kết thúc (hình thu nhỏ) của người tạo ở cuối video.";

View File

@@ -164,6 +164,9 @@
"HIDE_CAST_BUTTON" = "隱藏投放按鈕";
"HIDE_CAST_BUTTON_DESC" = "重新啟動應用程式以套用變更。";
"VIDEO_PLAYER_BUTTON" = "Video Player Button";
"VIDEO_PLAYER_BUTTON_DESC" = "Show a button in the navigation bar to open downloaded videos in the Apple player";
"HIDE_SPONSORBLOCK_BUTTON" = "隱藏 iSponsorBlock 按鈕";
"HIDE_SPONSORBLOCK_BUTTON_DESC" = "";