From 3120cd785b64485d62450cd4705961bb75d2a12d Mon Sep 17 00:00:00 2001 From: TrueZhuanjia Date: Thu, 5 Jun 2025 17:39:23 +0800 Subject: [PATCH] - auto save favorite settings with order - auto setup morebutton menu in 2 settings mode --- Limelight/Database/DataManager.h | 5 ++ .../ViewControllers/SWRevealViewController.h | 3 + .../ViewControllers/SWRevealViewController.m | 81 ++++++++++++++----- .../ViewControllers/SettingsViewController.h | 5 -- .../ViewControllers/SettingsViewController.m | 13 ++- 5 files changed, 79 insertions(+), 28 deletions(-) diff --git a/Limelight/Database/DataManager.h b/Limelight/Database/DataManager.h index 14b00e00..b55a0820 100644 --- a/Limelight/Database/DataManager.h +++ b/Limelight/Database/DataManager.h @@ -28,6 +28,11 @@ typedef NS_ENUM(NSInteger, TouchEventPriorityEnum) { TouchMovePriority// deprecated by GUI }; +typedef NS_ENUM(NSInteger, SettingsMenuMode) { + AllSettings, + FavoriteSettings, +}; + - (void) saveSettingsWithBitrate:(NSInteger)bitrate framerate:(NSInteger)framerate height:(NSInteger)height diff --git a/Limelight/ViewControllers/SWRevealViewController.h b/Limelight/ViewControllers/SWRevealViewController.h index e02f8d0c..1ec55319 100755 --- a/Limelight/ViewControllers/SWRevealViewController.h +++ b/Limelight/ViewControllers/SWRevealViewController.h @@ -137,6 +137,8 @@ #import +#import "DataManager.h" + @class SWRevealViewController; @protocol SWRevealViewControllerDelegate; @@ -349,6 +351,7 @@ typedef enum @optional - (void)switchToFavoriteSettings; - (void)switchToAllSettings; +- (SettingsMenuMode)getSettingsMenuMode; @end diff --git a/Limelight/ViewControllers/SWRevealViewController.m b/Limelight/ViewControllers/SWRevealViewController.m index ebe954ba..dd0717c4 100755 --- a/Limelight/ViewControllers/SWRevealViewController.m +++ b/Limelight/ViewControllers/SWRevealViewController.m @@ -31,7 +31,6 @@ #import "SWRevealViewController.h" #import "LocalizationHelper.h" -#import "DataManager.h" #import "ThemeManager.h" @@ -644,6 +643,7 @@ static CGFloat scaledValue( CGFloat v1, CGFloat min2, CGFloat max2, CGFloat min1 NSMutableArray *_animationQueue; BOOL _userInteractionStore; UIViewController *_primaryViewController; + } const int FrontViewPositionNone = 0xff; @@ -862,6 +862,7 @@ const int FrontViewPositionNone = 0xff; - (void)willMoveToPosition{ _separatorLine.hidden = _frontViewPosition == FrontViewPositionLeft; + if(_frontViewPosition != FrontViewPositionLeft) [self setupMoreButtonMenu]; } @@ -985,7 +986,7 @@ const int FrontViewPositionNone = 0xff; } - (void)setupMoreButton{ - _moreButton = [[UIBarButtonItem alloc] init]; + if(!_moreButton) _moreButton = [[UIBarButtonItem alloc] init]; //[moreButton setAction:@selector(moreButtonTapped:)]; if (@available(iOS 13.0, *)) { @@ -997,39 +998,60 @@ const int FrontViewPositionNone = 0xff; } else { [_moreButton setTitle:[LocalizationHelper localizedStringForKey:@"More"]]; } + // more option button +} +- (UIAction* )getFavoriteMenuAction API_AVAILABLE(ios(13.0)){ + return [UIAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Favorite Settings"] image:[UIImage systemImageNamed:@"bookmark"] identifier:nil handler:^(__kindof UIAction * _Nonnull action) { + [self favoriteSettingSelected]; + }]; +} +- (UIAction* )getAllSettingMenuAction API_AVAILABLE(ios(13.0)){ + return [UIAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"All Settings"] image:[UIImage systemImageNamed:@"circle.grid.3x3"] identifier:nil handler:^(__kindof UIAction * _Nonnull action) { + [self allSettingSelected]; + }]; +} + +- (void)setupMoreButtonMenu{ if (@available(iOS 14.0, *)) { - UIAction *favoriteSettingAction = [UIAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Favorite Settings"] image:[UIImage systemImageNamed:@"bookmark"] identifier:nil handler:^(__kindof UIAction * _Nonnull action) { - [self favoriteSettingSelected]; - }]; - - UIAction *allSettingAction = [UIAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"All Settings"] image:[UIImage systemImageNamed:@"circle.grid.3x3"] identifier:nil handler:^(__kindof UIAction * _Nonnull action) { - [self allSettingSelected]; - }]; + UIMenu *menu; // 创建菜单 - UIMenu *menu = [UIMenu menuWithTitle:@"" children:@[favoriteSettingAction, allSettingAction]]; + switch ([self getSettingsMenuMode]) { + case AllSettings: + menu = [UIMenu menuWithTitle:@"" children:@[[self getFavoriteMenuAction]]]; + break; + case FavoriteSettings: + menu = [UIMenu menuWithTitle:@"" children:@[[self getAllSettingMenuAction]]]; + break; + default: + break; + } _moreButton.menu = menu; } else{ [_moreButton setTarget:self]; [_moreButton setAction:@selector(moreButtonTapped:)]; } - // more option button } - (void)moreButtonTapped:(UIBarButtonItem *)sender { - UIMenuItem *item1 = [[UIMenuItem alloc] initWithTitle:@"操作1" action:@selector(favoriteSettingSelected)]; - UIMenuItem *item2 = [[UIMenuItem alloc] initWithTitle:@"操作2" action:@selector(allSettingsSelected)]; - - UIMenuController *menuController = [UIMenuController sharedMenuController]; - [menuController setMenuItems:@[item1, item2]]; - - UIView *targetView = [sender valueForKey:@"view"]; - [menuController setTargetRect:targetView.bounds inView:targetView]; - [menuController setMenuVisible:YES animated:YES]; - - [self becomeFirstResponder]; + if (@available(iOS 14.0, *)) { + + + } else { + UIMenuItem *item1 = [[UIMenuItem alloc] initWithTitle:@"操作1" action:@selector(favoriteSettingSelected)]; + UIMenuItem *item2 = [[UIMenuItem alloc] initWithTitle:@"操作2" action:@selector(allSettingsSelected)]; + + UIMenuController *menuController = [UIMenuController sharedMenuController]; + [menuController setMenuItems:@[item1, item2]]; + + UIView *targetView = [sender valueForKey:@"view"]; + [menuController setTargetRect:targetView.bounds inView:targetView]; + [menuController setMenuVisible:YES animated:YES]; + + [self becomeFirstResponder]; + } } - (BOOL)canBecomeFirstResponder { @@ -1043,13 +1065,28 @@ const int FrontViewPositionNone = 0xff; return NO; } +- (SettingsMenuMode)getSettingsMenuMode { + if ([self.navBarMenuDelegate respondsToSelector:@selector(getSettingsMenuMode)]) { + return [self.navBarMenuDelegate getSettingsMenuMode]; + + } else return AllSettings; +} + - (void)favoriteSettingSelected { + if (@available(iOS 13.0, *)) { + UIAction* allSettings = [self getAllSettingMenuAction]; + if (@available(iOS 14.0, *)) _moreButton.menu = [UIMenu menuWithTitle:@"" children:@[allSettings]]; + } if ([self.navBarMenuDelegate respondsToSelector:@selector(switchToFavoriteSettings)]) { [self.navBarMenuDelegate switchToFavoriteSettings]; } else NSLog(@"Delegate not set or does not respond to switchToFavoriteSettings:"); } - (void)allSettingSelected { + if (@available(iOS 13.0, *)) { + UIAction* favoriteSettings = [self getFavoriteMenuAction]; + if (@available(iOS 14.0, *)) _moreButton.menu = [UIMenu menuWithTitle:@"" children:@[favoriteSettings]]; + } if ([self.navBarMenuDelegate respondsToSelector:@selector(switchToAllSettings)]) { [self.navBarMenuDelegate switchToAllSettings]; } else NSLog(@"Delegate not set or does not respond to switchToAllSettings:"); diff --git a/Limelight/ViewControllers/SettingsViewController.h b/Limelight/ViewControllers/SettingsViewController.h index 648cc14e..b002d1f1 100644 --- a/Limelight/ViewControllers/SettingsViewController.h +++ b/Limelight/ViewControllers/SettingsViewController.h @@ -104,11 +104,6 @@ #pragma clang diagnostic pop -typedef NS_ENUM(NSInteger, SettingsMenuMode) { - AllSettings, - FavoriteSettings, -}; - - (void)saveSettings; + (bool)isLandscapeNow; - (void)updateResolutionTable; diff --git a/Limelight/ViewControllers/SettingsViewController.m b/Limelight/ViewControllers/SettingsViewController.m index 060a557c..bd88b6cf 100644 --- a/Limelight/ViewControllers/SettingsViewController.m +++ b/Limelight/ViewControllers/SettingsViewController.m @@ -364,6 +364,10 @@ BOOL isCustomResolution(CGSize res) { exitButton.frame = CGRectMake(0, 20, 200, 50); // Adjust Y and height as needed }*/ +- (SettingsMenuMode)getSettingsMenuMode{ + return currentSettingsMenuMode; +} + - (void)edgeSwiped { [self simulateSettingsButtonPress]; } @@ -747,6 +751,7 @@ BOOL isCustomResolution(CGSize res) { // [parentStack addSubview:capturedStack]; originalIndex = newIndex; capturedStack.hidden = NO; + [self saveFavoriteSettingStackIdentifiers]; } // 移除快照视图,显示原始视图 break; @@ -804,6 +809,13 @@ BOOL isCustomResolution(CGSize res) { - (void)saveFavoriteSettingStackIdentifiers { + + [_favoriteSettingStackIdentifiers removeAllObjects]; + + for(NSInteger i = 0; i < parentStack.arrangedSubviews.count; i++){ + [_favoriteSettingStackIdentifiers addObject:parentStack.arrangedSubviews[i].accessibilityIdentifier]; + } + [[NSUserDefaults standardUserDefaults] setObject:_favoriteSettingStackIdentifiers forKey:@"FavoriteSettingStackIdentifiers"]; [[NSUserDefaults standardUserDefaults] synchronize]; } @@ -1734,7 +1746,6 @@ BOOL isCustomResolution(CGSize res) { externalDisplayMode:externalDisplayMode localMousePointerMode:localMousePointerMode settinsMenuMode:currentSettingsMenuMode]; - [self saveFavoriteSettingStackIdentifiers]; } - (void)didReceiveMemoryWarning {