mirror of
https://github.com/SoPat712/YTLitePlus.git
synced 2025-08-21 10:38:45 -04:00
Implement gesture selection
This commit is contained in:
@@ -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"];
|
||||
}
|
||||
|
@@ -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")
|
||||
];
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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"];
|
||||
}
|
||||
|
17
YTLitePlus.h
17
YTLitePlus.h
@@ -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
|
||||
|
@@ -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"];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user