From bbee22218a97575c5737151b75eeed4d68473cb2 Mon Sep 17 00:00:00 2001 From: Bryce Hackel <34104885+bhackel@users.noreply.github.com> Date: Wed, 4 Sep 2024 00:09:51 -0700 Subject: [PATCH] Add alternate seek; Improve smoothing hopefully --- Source/Settings.xm | 2 ++ YTLitePlus.h | 1 + YTLitePlus.xm | 36 ++++++++++--------- .../ar.lproj/Localizable.strings | 2 ++ .../bg.lproj/Localizable.strings | 2 ++ .../de.lproj/Localizable.strings | 2 ++ .../en.lproj/Localizable.strings | 2 ++ .../es.lproj/Localizable.strings | 2 ++ .../fr.lproj/Localizable.strings | 2 ++ .../ja.lproj/Localizable.strings | 2 ++ .../pt.lproj/Localizable.strings | 2 ++ .../ro.lproj/Localizable.strings | 2 ++ .../ru.lproj/Localizable.strings | 2 ++ .../template.lproj/Localizable.strings | 2 ++ .../tr.lproj/Localizable.strings | 2 ++ .../vi.lproj/Localizable.strings | 2 ++ .../zh_TW.lproj/Localizable.strings | 2 ++ 17 files changed, 50 insertions(+), 17 deletions(-) diff --git a/Source/Settings.xm b/Source/Settings.xm index 864275b..a4074b3 100644 --- a/Source/Settings.xm +++ b/Source/Settings.xm @@ -395,6 +395,8 @@ static const NSInteger YTLiteSection = 789; sensitivityPicker, // Toggle for haptic feedback BASIC_SWITCH(LOC(@"PLAYER_GESTURES_HAPTIC_FEEDBACK"), nil, @"playerGesturesHapticFeedback_enabled"), + // Toggle for alternate seek method + BASIC_SWITCH(LOC(@"PLAYER_GESTURES_SEEK_ALTERNATE"), LOC(@"PLAYER_GESTURES_SEEK_ALTERNATE_DESC"), @"gestureSeekAlternate_enabled"), ]; YTSettingsPickerViewController *picker = [[%c(YTSettingsPickerViewController) alloc] initWithNavTitle:LOC(@"PLAYER_GESTURES_TITLE") pickerSectionTitle:nil rows:rows selectedItemIndex:NSNotFound parentResponder:[self parentResponder]]; [settingsViewController pushViewController:picker]; diff --git a/YTLitePlus.h b/YTLitePlus.h index 1c3ead2..ef23a6c 100644 --- a/YTLitePlus.h +++ b/YTLitePlus.h @@ -187,6 +187,7 @@ typedef NS_ENUM(NSUInteger, GestureSection) { @property UIPanGestureRecognizer *scrubGestureRecognizer; @property (nonatomic, strong, readwrite) YTFineScrubberFilmstripView *fineScrubberFilmstrip; - (CGFloat)scrubXForScrubRange:(CGFloat)scrubRange; +- (CGFloat)scrubRangeForScrubX:(CGFloat)scrubX; @end // Hide Collapse Button - @arichornlover diff --git a/YTLitePlus.xm b/YTLitePlus.xm index 9670a34..3137fcd 100644 --- a/YTLitePlus.xm +++ b/YTLitePlus.xm @@ -749,10 +749,6 @@ BOOL isTabSelected = NO; static CGFloat deadzoneStartingXTranslation; // Variable to track the X translation of the pan gesture after exiting the deadzone static CGFloat adjustedTranslationX; - // Variable used to smooth out the X translation - static CGFloat smoothedTranslationX = 0; - // Constant for the filter constant to change responsiveness - // static const CGFloat filterConstant = 0.1; // Constant for the deadzone radius that can be changed in the settings static CGFloat deadzoneRadius = (CGFloat)GetFloat(@"playerGesturesDeadzone"); // Constant for the sensitivity factor that can be changed in the settings @@ -791,9 +787,11 @@ BOOL isTabSelected = NO; float volumeSensitivityFactor = 3.0; float newVolume = initialVolume + ((translationX / 1000.0) * sensitivityFactor * volumeSensitivityFactor); newVolume = fmaxf(fminf(newVolume, 1.0), 0.0); - // Improve smoothness - ignore if the volume is within 0.01 of the current volume + // Improve smoothness - ignore if the volume is within a certain distance of the current volume, + // but also allow it to change to 100% or to 0% when close to the edges CGFloat currentVolume = [[AVAudioSession sharedInstance] outputVolume]; - if (fabs(newVolume - currentVolume) < 0.01 && currentVolume > 0.01 && currentVolume < 0.99) { + CGFloat changeThresh = 0.02; + if ((fabs(newVolume - currentVolume) < changeThresh) && (currentVolume > changeThresh) && (currentVolume < (1-changeThresh))) { return; } // https://stackoverflow.com/questions/50737943/how-to-change-volume-programmatically-on-ios-11-4 @@ -812,18 +810,23 @@ BOOL isTabSelected = NO; // Calculate the new seek X position CGFloat sensitivityFactor = 1; // Adjust this value to make seeking more/less sensitive CGFloat newSeekXPosition = initialTimeXPosition + translationX * sensitivityFactor; - // Create a CGPoint using this new X position - CGPoint newSeekPoint = CGPointMake(newSeekXPosition, 0); - // Send this to a seek method in the player bar controller - [playerBarController didScrubToPoint:newSeekPoint]; + // Decide between seek methods + if (IS_ENABLED(@"gestureSeekAlternate_enabled")) { + // Alternate seek method used by uYou + // Convert the new X position back to a fraction of the total time + CGFloat newVideoFraction = [playerBar scrubRangeForScrubX:newSeekXPosition]; + // Calculate the new video time based on this fraction + CGFloat newVideoTime = newVideoFraction * totalTime; + [self seekToTime:newVideoTime]; + } else { + // Vanilla YouTube seek method used when dragging the seek bar + // Create a CGPoint using this new X position + CGPoint newSeekPoint = CGPointMake(newSeekXPosition, 0); + // Send this to a seek method in the player bar controller + [playerBarController didScrubToPoint:newSeekPoint]; + } }; - // Helper function to smooth out the X translation - // CGFloat (^applyLowPassFilter)(CGFloat) = ^(CGFloat newTranslation) { - // smoothedTranslationX = filterConstant * newTranslation + (1 - filterConstant) * smoothedTranslationX; - // return smoothedTranslationX; - // }; - /***** Helper functions for running the selected gesture *****/ // Helper function to run any setup for the selected gesture mode void (^runSelectedGestureSetup)(NSString*) = ^(NSString *sectionKey) { @@ -959,7 +962,6 @@ BOOL isTabSelected = NO; isValidHorizontalPan = YES; deadzoneStartingXTranslation = translation.x; adjustedTranslationX = 0; - smoothedTranslationX = 0; // Run the setup for the selected gesture mode switch (gestureSection) { case GestureSectionTop: diff --git a/lang/YTLitePlus.bundle/ar.lproj/Localizable.strings b/lang/YTLitePlus.bundle/ar.lproj/Localizable.strings index f697808..e792be0 100644 --- a/lang/YTLitePlus.bundle/ar.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/ar.lproj/Localizable.strings @@ -33,6 +33,8 @@ "MIDDLE_SECTION" = "Middle Section"; "BOTTOM_SECTION" = "Bottom Section"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Enable Haptic Feedback"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "خيارات تراكب ضوابط الفيديو"; diff --git a/lang/YTLitePlus.bundle/bg.lproj/Localizable.strings b/lang/YTLitePlus.bundle/bg.lproj/Localizable.strings index 9e8441c..f13582f 100644 --- a/lang/YTLitePlus.bundle/bg.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/bg.lproj/Localizable.strings @@ -33,6 +33,8 @@ "MIDDLE_SECTION" = "Middle Section"; "BOTTOM_SECTION" = "Bottom Section"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Enable Haptic Feedback"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "Опции за контрол на видеото"; diff --git a/lang/YTLitePlus.bundle/de.lproj/Localizable.strings b/lang/YTLitePlus.bundle/de.lproj/Localizable.strings index 333a3cd..66ca490 100644 --- a/lang/YTLitePlus.bundle/de.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/de.lproj/Localizable.strings @@ -33,6 +33,8 @@ "MIDDLE_SECTION" = "Middle Section"; "BOTTOM_SECTION" = "Bottom Section"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Enable Haptic Feedback"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "Overlay-Optionen für Videosteuerungen"; diff --git a/lang/YTLitePlus.bundle/en.lproj/Localizable.strings b/lang/YTLitePlus.bundle/en.lproj/Localizable.strings index dd4c6fb..48c9cbd 100644 --- a/lang/YTLitePlus.bundle/en.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/en.lproj/Localizable.strings @@ -33,6 +33,8 @@ "MIDDLE_SECTION" = "Middle Section"; "BOTTOM_SECTION" = "Bottom Section"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Enable Haptic Feedback"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "Video Controls Overlay Options"; diff --git a/lang/YTLitePlus.bundle/es.lproj/Localizable.strings b/lang/YTLitePlus.bundle/es.lproj/Localizable.strings index 5f206cb..4e4e775 100644 --- a/lang/YTLitePlus.bundle/es.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/es.lproj/Localizable.strings @@ -33,6 +33,8 @@ "MIDDLE_SECTION" = "Sección Media"; "BOTTOM_SECTION" = "Sección Inferior"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Habilitar Retroalimentación Háptica"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "Opciones de superposición de controles de vídeo"; diff --git a/lang/YTLitePlus.bundle/fr.lproj/Localizable.strings b/lang/YTLitePlus.bundle/fr.lproj/Localizable.strings index 1b38433..dfb005d 100644 --- a/lang/YTLitePlus.bundle/fr.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/fr.lproj/Localizable.strings @@ -33,6 +33,8 @@ "MIDDLE_SECTION" = "Middle Section"; "BOTTOM_SECTION" = "Bottom Section"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Enable Haptic Feedback"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "Options de l'overlay des contrôles vidéo"; diff --git a/lang/YTLitePlus.bundle/ja.lproj/Localizable.strings b/lang/YTLitePlus.bundle/ja.lproj/Localizable.strings index 0fb4e5b..25ceba1 100644 --- a/lang/YTLitePlus.bundle/ja.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/ja.lproj/Localizable.strings @@ -33,6 +33,8 @@ "MIDDLE_SECTION" = "Middle Section"; "BOTTOM_SECTION" = "Bottom Section"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Enable Haptic Feedback"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "動画コントロールオーバーレイの設定"; diff --git a/lang/YTLitePlus.bundle/pt.lproj/Localizable.strings b/lang/YTLitePlus.bundle/pt.lproj/Localizable.strings index eb1e6b4..1313db2 100644 --- a/lang/YTLitePlus.bundle/pt.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/pt.lproj/Localizable.strings @@ -33,6 +33,8 @@ "MIDDLE_SECTION" = "Seção do Meio"; "BOTTOM_SECTION" = "Seção Inferior"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Habilitar Feedback Tátil"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "Opções de Sobreposição de Controles de Vídeo"; diff --git a/lang/YTLitePlus.bundle/ro.lproj/Localizable.strings b/lang/YTLitePlus.bundle/ro.lproj/Localizable.strings index dcbf88d..98ff898 100644 --- a/lang/YTLitePlus.bundle/ro.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/ro.lproj/Localizable.strings @@ -33,6 +33,8 @@ "MIDDLE_SECTION" = "Middle Section"; "BOTTOM_SECTION" = "Bottom Section"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Enable Haptic Feedback"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "Opțiuni Overlay Controale Video"; diff --git a/lang/YTLitePlus.bundle/ru.lproj/Localizable.strings b/lang/YTLitePlus.bundle/ru.lproj/Localizable.strings index 6656a2e..e9eed53 100644 --- a/lang/YTLitePlus.bundle/ru.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/ru.lproj/Localizable.strings @@ -33,6 +33,8 @@ "MIDDLE_SECTION" = "Middle Section"; "BOTTOM_SECTION" = "Bottom Section"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Enable Haptic Feedback"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "Video Controls Overlay Options"; diff --git a/lang/YTLitePlus.bundle/template.lproj/Localizable.strings b/lang/YTLitePlus.bundle/template.lproj/Localizable.strings index 5bfba8d..5300fbf 100644 --- a/lang/YTLitePlus.bundle/template.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/template.lproj/Localizable.strings @@ -48,6 +48,8 @@ https://github.com/PoomSmart/Return-YouTube-Dislikes/tree/main/layout/Library/Ap "MIDDLE_SECTION" = "Middle Section"; "BOTTOM_SECTION" = "Bottom Section"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Enable Haptic Feedback"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "Video Controls Overlay Options"; diff --git a/lang/YTLitePlus.bundle/tr.lproj/Localizable.strings b/lang/YTLitePlus.bundle/tr.lproj/Localizable.strings index 82d24b1..e4025f2 100644 --- a/lang/YTLitePlus.bundle/tr.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/tr.lproj/Localizable.strings @@ -33,6 +33,8 @@ "MIDDLE_SECTION" = "Middle Section"; "BOTTOM_SECTION" = "Bottom Section"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Enable Haptic Feedback"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "Video Kontrol Seç."; diff --git a/lang/YTLitePlus.bundle/vi.lproj/Localizable.strings b/lang/YTLitePlus.bundle/vi.lproj/Localizable.strings index 538ba40..854748d 100644 --- a/lang/YTLitePlus.bundle/vi.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/vi.lproj/Localizable.strings @@ -33,6 +33,8 @@ "MIDDLE_SECTION" = "Phần giữa"; "BOTTOM_SECTION" = "Phần dưới"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Bật phản hồi xúc giác"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "Lớp phủ video"; diff --git a/lang/YTLitePlus.bundle/zh_TW.lproj/Localizable.strings b/lang/YTLitePlus.bundle/zh_TW.lproj/Localizable.strings index d573c76..412aba6 100644 --- a/lang/YTLitePlus.bundle/zh_TW.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/zh_TW.lproj/Localizable.strings @@ -34,6 +34,8 @@ "MIDDLE_SECTION" = "Middle Section"; "BOTTOM_SECTION" = "Bottom Section"; "PLAYER_GESTURES_HAPTIC_FEEDBACK" = "Enable Haptic Feedback"; +"PLAYER_GESTURES_SEEK_ALTERNATE" = "Alternate seek method"; +"PLAYER_GESTURES_SEEK_ALTERNATE_DESC" = "Use a different method that increases content visibility"; // Video controls overlay options "VIDEO_CONTROLS_OVERLAY_OPTIONS" = "影片區覆蓋按鈕設定";