From 8eed3ce8bc7d3214df72e4e4e68d3c6dfbe1f3c4 Mon Sep 17 00:00:00 2001 From: Bryce Hackel <34104885+bhackel@users.noreply.github.com> Date: Tue, 20 Aug 2024 18:14:02 -0700 Subject: [PATCH] Fix playback in feeds on iPad --- Source/Settings.xm | 22 ++++++++++++++-------- YTLitePlus.h | 4 ++-- YTLitePlus.xm | 8 ++++---- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Source/Settings.xm b/Source/Settings.xm index c25f262..5bfd862 100644 --- a/Source/Settings.xm +++ b/Source/Settings.xm @@ -266,7 +266,7 @@ static const NSInteger YTLiteSection = 789; return [YTSettingsSectionItemClass itemWithTitle:LOC(sectionLabel) accessibilityIdentifier:nil detailTextBlock:^NSString *() { - return sectionGestureSelectedModeToString(GetSelection(sectionKey)); + return sectionGestureSelectedModeToString(GetInteger(sectionKey)); } selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) { NSArray *rows = @[ @@ -280,7 +280,7 @@ static const NSInteger YTLiteSection = 789; initWithNavTitle:LOC(sectionLabel) pickerSectionTitle:nil rows:rows - selectedItemIndex:GetSelection(sectionKey) + selectedItemIndex:GetInteger(sectionKey) parentResponder:[self parentResponder] ]; [settingsViewController pushViewController:picker]; @@ -559,7 +559,7 @@ static const NSInteger YTLiteSection = 789; YTSettingsSectionItem *themeGroup = [YTSettingsSectionItemClass itemWithTitle:LOC(@"THEME_OPTIONS") accessibilityIdentifier:nil detailTextBlock:^NSString *() { - switch (GetSelection(@"appTheme")) { + switch (GetInteger(@"appTheme")) { case 1: return LOC(@"OLD_DARK_THEME"); case 0: @@ -583,7 +583,7 @@ static const NSInteger YTLiteSection = 789; BASIC_SWITCH(LOC(@"LOW_CONTRAST_MODE"), LOC(@"LOW_CONTRAST_MODE_DESC"), @"lowContrastMode_enabled"), lowContrastModeSection ]; - YTSettingsPickerViewController *picker = [[%c(YTSettingsPickerViewController) alloc] initWithNavTitle:LOC(@"THEME_OPTIONS") pickerSectionTitle:nil rows:rows selectedItemIndex:GetSelection(@"appTheme") parentResponder:[self parentResponder]]; + YTSettingsPickerViewController *picker = [[%c(YTSettingsPickerViewController) alloc] initWithNavTitle:LOC(@"THEME_OPTIONS") pickerSectionTitle:nil rows:rows selectedItemIndex:GetInteger(@"appTheme") parentResponder:[self parentResponder]]; [settingsViewController pushViewController:picker]; return YES; }]; @@ -595,7 +595,8 @@ static const NSInteger YTLiteSection = 789; YTSettingsSectionItem *playbackInFeedsGroup = [YTSettingsSectionItemClass itemWithTitle:LOC(@"PLAYBACK_IN_FEEDS") accessibilityIdentifier:nil detailTextBlock:^NSString *() { - switch (GetSelection(@"inline_muted_playback_enabled")) { + // The specific values were gathered by checking the value for each setting + switch (GetInteger(@"inline_muted_playback_enabled")) { case 3: return LOC(@"PLAYBACK_IN_FEEDS_WIFI_ONLY"); case 1: @@ -624,9 +625,14 @@ static const NSInteger YTLiteSection = 789; }], ]; // It seems values greater than 3 act the same as Always On (Index 1) - int (^getInlineSelection)() = ^int() { - int selection = GetSelection(@"inline_muted_playback_enabled") - 1; - return selection > 3 ? 1 : selection; + // Convert the stored value to an index for a picker (0 to 2) + NSInteger (^getInlineSelection)(void) = ^NSInteger(void) { + NSInteger selection = GetInteger(@"inline_muted_playback_enabled") - 1; + // Check if selection is within the valid bounds [0, 1, 2] + if (selection < 0 || selection > 2) { + return 1; + } + return selection; }; YTSettingsPickerViewController *picker = [[%c(YTSettingsPickerViewController) alloc] initWithNavTitle:LOC(@"PLAYBACK_IN_FEEDS") pickerSectionTitle:nil rows:rows selectedItemIndex:getInlineSelection() parentResponder:[self parentResponder]]; [settingsViewController pushViewController:picker]; diff --git a/YTLitePlus.h b/YTLitePlus.h index 8a41583..34c0deb 100644 --- a/YTLitePlus.h +++ b/YTLitePlus.h @@ -59,8 +59,8 @@ // Helper methods for key retrieval #define IsEnabled(key) [[NSUserDefaults standardUserDefaults] boolForKey:key] -#define GetSelection(key) [[NSUserDefaults standardUserDefaults] integerForKey:key] -#define GetFloat(key) [[NSUserDefaults standardUserDefaults] floatForKey:key] +#define GetInteger(key) [[NSUserDefaults standardUserDefaults] integerForKey:key] // NSInteger type +#define GetFloat(key) [[NSUserDefaults standardUserDefaults] floatForKey:key] // float type // Player Gesture selected mode enum diff --git a/YTLitePlus.xm b/YTLitePlus.xm index 61b9935..2df89b2 100644 --- a/YTLitePlus.xm +++ b/YTLitePlus.xm @@ -723,7 +723,7 @@ BOOL isTabSelected = NO; 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); + GestureMode selectedGestureMode = (GestureMode)GetInteger(sectionKey); // Handle the gesture action based on the selected mode switch (selectedGestureMode) { case GestureModeVolume: @@ -760,21 +760,21 @@ BOOL isTabSelected = NO; if (startLocation.y <= viewHeight / 3.0) { gestureSection = GestureSectionTop; // Cancel the gesture if the mode is disabled - if (GetSelection(@"playerGestureTopSelection") == GestureModeDisabled) { + if (GetInteger(@"playerGestureTopSelection") == GestureModeDisabled) { panGestureRecognizer.state = UIGestureRecognizerStateCancelled; return; } } else if (startLocation.y <= 2 * viewHeight / 3.0) { gestureSection = GestureSectionMiddle; // Cancel the gesture if the mode is disabled - if (GetSelection(@"playerGestureMiddleSelection") == GestureModeDisabled) { + if (GetInteger(@"playerGestureMiddleSelection") == GestureModeDisabled) { panGestureRecognizer.state = UIGestureRecognizerStateCancelled; return; } } else if (startLocation.y <= viewHeight) { gestureSection = GestureSectionBottom; // Cancel the gesture if the mode is disabled - if (GetSelection(@"playerGestureBottomSelection") == GestureModeDisabled) { + if (GetInteger(@"playerGestureBottomSelection") == GestureModeDisabled) { panGestureRecognizer.state = UIGestureRecognizerStateCancelled; return; }