Implement gesture selection

This commit is contained in:
Bryce Hackel
2024-08-15 10:45:27 -07:00
parent 8ed3d97d2d
commit 6854f91c1e
6 changed files with 63 additions and 38 deletions

View File

@@ -1,9 +1,6 @@
#import "../YTLitePlus.h"
//
static BOOL IsEnabled(NSString *key) {
return [[NSUserDefaults standardUserDefaults] boolForKey:key];
}
// Low Contrast Mode
static int contrastMode() {
return [[NSUserDefaults standardUserDefaults] integerForKey:@"lcm"];
}

View File

@@ -32,12 +32,6 @@
settingItemId:0]
*/
static BOOL IsEnabled(NSString *key) {
return [[NSUserDefaults standardUserDefaults] boolForKey:key];
}
static int GetSelection(NSString *key) {
return [[NSUserDefaults standardUserDefaults] integerForKey:key];
}
static int contrastMode() {
return [[NSUserDefaults standardUserDefaults] integerForKey:@"lcm"];
}
@@ -214,7 +208,7 @@ static const NSInteger YTLiteSection = 789;
# pragma mark - Player Gestures - @bhackel
// Helper to get the selected gesture mode
static NSString* (^sectionGestureSelectedMode)(GestureMode) = ^(GestureMode sectionIndex) {
static NSString* (^sectionGestureSelectedModeToString)(GestureMode) = ^(GestureMode sectionIndex) {
switch (sectionIndex) {
case GestureModeVolume:
return LOC(@"Volume (Beta)");
@@ -231,7 +225,7 @@ static const NSInteger YTLiteSection = 789;
// Helper to generate checkmark setting items for selecting gesture modes
static YTSettingsSectionItem* (^gestureCheckmarkSettingItem)(NSInteger, NSString *) = ^(NSInteger idx, NSString *key) {
return [YTSettingsSectionItemClass
checkmarkItemWithTitle:sectionGestureSelectedMode(idx)
checkmarkItemWithTitle:sectionGestureSelectedModeToString(idx)
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
[[NSUserDefaults standardUserDefaults] setInteger:idx forKey:key];
[settingsViewController reloadData];
@@ -245,7 +239,7 @@ static const NSInteger YTLiteSection = 789;
return [YTSettingsSectionItemClass itemWithTitle:LOC(sectionLabel)
accessibilityIdentifier:nil
detailTextBlock:^NSString *() {
return sectionGestureSelectedMode(GetSelection(sectionKey));
return sectionGestureSelectedModeToString(GetSelection(sectionKey));
}
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
NSArray <YTSettingsSectionItem *> *rows = @[
@@ -269,7 +263,7 @@ static const NSInteger YTLiteSection = 789;
// High level gestures menu
YTSettingsSectionItem *playerGesturesGroup = [YTSettingsSectionItemClass itemWithTitle:LOC(@"Player Gestures (Beta)") accessibilityIdentifier:nil detailTextBlock:nil selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
NSArray <YTSettingsSectionItem *> *rows = @[
createSectionGestureSelector(@"Top Section (Beta)", @"playerGestureTopSelection"),
createSectionGestureSelector(@"Top Section (Beta)", @"playerGestureTopSelection"),
createSectionGestureSelector(@"Middle Section (Beta)", @"playerGestureMiddleSelection"),
createSectionGestureSelector(@"Bottom Section (Beta)", @"playerGestureBottomSelection")
];

View File

@@ -1,8 +1,5 @@
#import "../YTLitePlus.h"
static BOOL IsEnabled(NSString *key) {
return [[NSUserDefaults standardUserDefaults] boolForKey:key];
}
static BOOL isDarkMode() {
return ([[NSUserDefaults standardUserDefaults] integerForKey:@"page_style"] == 1);
}

View File

@@ -1,9 +1,6 @@
#import "../YTLitePlus.h"
//
static BOOL IsEnabled(NSString *key) {
return [[NSUserDefaults standardUserDefaults] boolForKey:key];
}
static int appVersionSpoofer() {
return [[NSUserDefaults standardUserDefaults] integerForKey:@"versionSpoofer"];
}

View File

@@ -52,13 +52,28 @@
#define IS_ENABLED(k) [[NSUserDefaults standardUserDefaults] boolForKey:k]
#define APP_THEME_IDX [[NSUserDefaults standardUserDefaults] integerForKey:@"appTheme"]
// Enum for Player Gesture selected modes
// Avoid issues with multiple includes of this file
#pragma once
// Helper methods for key retrieval
#define IsEnabled(key) [[NSUserDefaults standardUserDefaults] boolForKey:key]
#define GetSelection(key) [[NSUserDefaults standardUserDefaults] integerForKey:key]
// Player Gesture selected mode enum
typedef NS_ENUM(NSUInteger, GestureMode) {
GestureModeVolume,
GestureModeBrightness,
GestureModeSeek,
GestureModeInvalid
};
// Gesture Section Enum
typedef NS_ENUM(NSUInteger, GestureSection) {
GestureSectionTop,
GestureSectionMiddle,
GestureSectionBottom,
GestureSectionInvalid
};
// YTSpeed
@interface YTVarispeedSwitchControllerOption : NSObject

View File

@@ -33,11 +33,6 @@ static NSString *accessGroupID() {
return accessGroup;
}
//
static BOOL IsEnabled(NSString *key) {
return [[NSUserDefaults standardUserDefaults] boolForKey:key];
}
# pragma mark - Tweaks
// Activate FLEX
@@ -673,13 +668,7 @@ BOOL isTabSelected = NO;
%orig;
}
%end
// Gesture Section Enum
typedef NS_ENUM(NSInteger, GestureSection) {
GestureSectionTop,
GestureSectionMiddle,
GestureSectionBottom,
GestureSectionInvalid
};
%hook YTPlayerViewController
// the pan gesture that will be created and added to the player view
@@ -715,7 +704,7 @@ typedef NS_ENUM(NSInteger, GestureSection) {
});
};
// Helper function to adjust seek time
void (^adjustSeek)(CGFloat) = ^(CGFloat translationX) {
void (^adjustSeek)(CGFloat, CGFloat) = ^(CGFloat translationX, CGFloat currentTime) {
// Calculate a seek fraction based on the horizontal translation
CGFloat totalDuration = self.currentVideoTotalMediaTime;
CGFloat viewWidth = self.view.bounds.size.width;
@@ -726,6 +715,32 @@ typedef NS_ENUM(NSInteger, GestureSection) {
CGFloat seekTime = currentTime + totalDuration * seekFraction;
[self seekToTime:seekTime];
};
// Helper function to run the selected gesture action
void (^runSelectedGesture)(NSString*, CGFloat, CGFloat, CGFloat, CGFloat) =
^(NSString *sectionKey, CGFloat translationX, CGFloat initialBrightness, CGFloat initialVolume, CGFloat currentTime) {
// Determine the selected gesture mode using the section key
GestureMode selectedGestureMode = (GestureMode)GetSelection(sectionKey);
// Handle the gesture action based on the selected mode
switch (selectedGestureMode) {
case GestureModeVolume:
adjustVolume(translationX, initialVolume);
break;
case GestureModeBrightness:
adjustBrightness(translationX, initialBrightness);
break;
case GestureModeSeek:
adjustSeek(translationX, currentTime);
break;
default:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Invalid Gesture Mode" message:@"Please report this bug." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
break;
}
};
// Handle gesture based on current gesture state
if (panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
@@ -766,11 +781,11 @@ typedef NS_ENUM(NSInteger, GestureSection) {
// Handle the gesture based on the identified section
if (isValidHorizontalPan) {
if (gestureSection == GestureSectionTop) {
adjustBrightness(translation.x, initialBrightness);
runSelectedGesture(@"playerGestureTopSelection", translation.x, initialBrightness, initialVolume, currentTime);
} else if (gestureSection == GestureSectionMiddle) {
adjustVolume(translation.x, initialVolume);
runSelectedGesture(@"playerGestureMiddleSelection", translation.x, initialBrightness, initialVolume, currentTime);
} else if (gestureSection == GestureSectionBottom) {
adjustSeek(translation.x);
runSelectedGesture(@"playerGestureBottomSelection", translation.x, initialBrightness, initialVolume, currentTime);
}
}
}
@@ -1041,4 +1056,14 @@ typedef NS_ENUM(NSInteger, GestureSection) {
if (![allKeys containsObject:@"fixCasting_enabled"]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"fixCasting_enabled"];
}
// Default gestures as volume, brightness, seek
if (![allKeys containsObject:@"playerGestureTopSelection"]) {
[[NSUserDefaults standardUserDefaults] setInteger:GestureModeVolume forKey:@"playerGestureTopSelection"];
}
if (![allKeys containsObject:@"playerGestureMiddleSelection"]) {
[[NSUserDefaults standardUserDefaults] setInteger:GestureModeBrightness forKey:@"playerGestureMiddleSelection"];
}
if (![allKeys containsObject:@"playerGestureBottomSelection"]) {
[[NSUserDefaults standardUserDefaults] setInteger:GestureModeSeek forKey:@"playerGestureBottomSelection"];
}
}