favorite settings basic fuction

This commit is contained in:
TrueZhuanjia
2025-06-04 01:49:59 +08:00
parent 2775ca09c7
commit 59660840e4
13 changed files with 191 additions and 62 deletions
@@ -1095,7 +1095,7 @@ static NSMutableSet* hostList;
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position {
SettingsViewController* settingsViewController = (SettingsViewController*)[revealController rearViewController];
revealController.navBarMenuDelegate = settingsViewController;
if (position == FrontViewPositionLeft) {
self.navigationItem.leftBarButtonItems = @[_settingsButton];
}
@@ -1595,9 +1595,6 @@ static NSMutableSet* hostList;
}
}
}
[dataMan saveData];
}
@@ -140,6 +140,7 @@
@class SWRevealViewController;
@protocol SWRevealViewControllerDelegate;
@protocol RearNavigationBarMenuDelegate;
#pragma mark - SWRevealViewController Class
@@ -318,6 +319,7 @@ typedef NS_ENUM(NSInteger, SWRevealToggleAnimationType)
// Delegate
@property (nonatomic,weak) id<SWRevealViewControllerDelegate> delegate;
@property (nonatomic,weak) id<RearNavigationBarMenuDelegate> navBarMenuDelegate;
@property (nonatomic,assign) bool isStreaming;
@property (nonatomic,assign) bool mainFrameIsInHostView;
@@ -329,6 +331,7 @@ typedef NS_ENUM(NSInteger, SWRevealToggleAnimationType)
@end
#pragma mark - SWRevealViewControllerDelegate Protocol
typedef enum
@@ -340,6 +343,15 @@ typedef enum
} SWRevealControllerOperation;
#pragma mark - RearNavigationBarMenuDelegate Protocol
@protocol RearNavigationBarMenuDelegate<NSObject>
@optional
- (void)switchToFavoriteSettings;
- (void)switchToAllSettings;
@end
@protocol SWRevealViewControllerDelegate<NSObject>
@@ -618,7 +618,6 @@ static CGFloat scaledValue( CGFloat v1, CGFloat min2, CGFloat max2, CGFloat min1
@end
#pragma mark - SWRevealViewController Class
@interface SWRevealViewController()<UIGestureRecognizerDelegate>
@@ -999,20 +998,16 @@ const int FrontViewPositionNone = 0xff;
}
if (@available(iOS 14.0, *)) {
UIAction *action1 = [UIAction actionWithTitle:@"操作1" image:[UIImage systemImageNamed:@"doc"] identifier:nil handler:^(__kindof UIAction * _Nonnull action) {
NSLog(@"执行操作1");
UIAction *favoriteSettingAction = [UIAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Favorite Settings"] image:[UIImage systemImageNamed:@"bookmark"] identifier:nil handler:^(__kindof UIAction * _Nonnull action) {
[self favoriteSettingSelected];
}];
UIAction *action2 = [UIAction actionWithTitle:@"操作2" image:[UIImage systemImageNamed:@"folder"] identifier:nil handler:^(__kindof UIAction * _Nonnull action) {
NSLog(@"执行操作2");
UIAction *allSettingAction = [UIAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"All Settings"] image:[UIImage systemImageNamed:@"circle.grid.3x3"] identifier:nil handler:^(__kindof UIAction * _Nonnull action) {
[self allSettingSelected];
}];
UIAction *deleteAction = [UIAction actionWithTitle:@"删除" image:[UIImage systemImageNamed:@"trash"] identifier:nil handler:^(__kindof UIAction * _Nonnull action) {
NSLog(@"执行删除操作");
}];
deleteAction.attributes = UIMenuElementAttributesDestructive;
// 创建菜单
UIMenu *menu = [UIMenu menuWithTitle:@"" children:@[action1, action2, deleteAction]];
UIMenu *menu = [UIMenu menuWithTitle:@"" children:@[favoriteSettingAction, allSettingAction]];
_moreButton.menu = menu;
}
else{
@@ -1023,8 +1018,8 @@ const int FrontViewPositionNone = 0xff;
}
- (void)moreButtonTapped:(UIBarButtonItem *)sender {
UIMenuItem *item1 = [[UIMenuItem alloc] initWithTitle:@"操作1" action:@selector(action1)];
UIMenuItem *item2 = [[UIMenuItem alloc] initWithTitle:@"操作2" action:@selector(action2)];
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]];
@@ -1041,17 +1036,26 @@ const int FrontViewPositionNone = 0xff;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(action1) || action == @selector(action2)) {
if (action == @selector(favoriteSettingSelected) || action == @selector(allSettingsSelected)) {
return YES;
}
return NO;
}
- (void)action1 {
NSLog(@"执行操作1");
- (void)favoriteSettingSelected {
if ([self.navBarMenuDelegate respondsToSelector:@selector(switchToFavoriteSettings)]) {
[self.navBarMenuDelegate switchToFavoriteSettings];
} else NSLog(@"Delegate not set or does not respond to switchToFavoriteSettings:");
}
- (void)action2 {
- (void)allSettingSelected {
if ([self.navBarMenuDelegate respondsToSelector:@selector(switchToAllSettings)]) {
[self.navBarMenuDelegate switchToAllSettings];
} else NSLog(@"Delegate not set or does not respond to switchToAllSettings:");
}
- (void)allSettingsSelected {
NSLog(@"执行操作2");
}
@@ -15,7 +15,7 @@
#import "MainFrameViewController.h"
#import "CustomEdgeSlideGestureRecognizer.h"
@interface SettingsViewController : UIViewController
@interface SettingsViewController : UIViewController <RearNavigationBarMenuDelegate>
@property (strong, nonatomic) IBOutlet UINavigationBar *navigationBar;
@property (strong, nonatomic) IBOutlet UIStackView *resolutionStack;
@property (strong, nonatomic) IBOutlet UIStackView *fpsStack;
@@ -104,6 +104,11 @@
#pragma clang diagnostic pop
typedef NS_ENUM(NSInteger, SettingsMenuMode) {
AllSettings,
FavoriteSettings,
};
- (void)saveSettings;
+ (bool)isLandscapeNow;
- (void)updateResolutionTable;
@@ -28,10 +28,14 @@
uint16_t oscLayoutFingers;
CustomEdgeSlideGestureRecognizer *slideToCloseSettingsViewRecognizer;
UIStackView *parentStack;
NSMutableDictionary *_settingStackDict;
NSMutableArray *_favoriteSettingStackIdentifiers;
uint8_t currentSettingsMenuMode;
}
@dynamic overrideUserInterfaceStyle;
//static NSString* bitrateFormat;
static const int bitrateTable[] = {
500,
@@ -398,6 +402,12 @@ BOOL isCustomResolution(CGSize res) {
[parentStack.widthAnchor constraintEqualToAnchor:self.scrollView.contentLayoutGuide.widthAnchor]
]];
}
- (void)addSetting:(UIStackView *)stack ofIdentifier:(NSString* )identifier to:(MenuSectionView* )menuSection{
stack.accessibilityIdentifier = identifier;
[_settingStackDict setObject:stack forKey:identifier];
[menuSection addSubStackView:stack];
}
- (void)layoutSections{
MenuSectionView *videoSection = [[MenuSectionView alloc] init];
@@ -405,12 +415,10 @@ BOOL isCustomResolution(CGSize res) {
if (@available(iOS 13.0, *)) {
[videoSection setSectionIcon:[UIImage systemImageNamed:@"airplayvideo"]];
} else [videoSection setSectionIcon:nil];
self.resolutionStack.accessibilityIdentifier = @"resolutionStack";
self.fpsStack.accessibilityIdentifier = @"fpsStack";
self.codecStack.accessibilityIdentifier = @"codecStack";
[videoSection addSubStackView:_resolutionStack];
[videoSection addSubStackView:_fpsStack];
[videoSection addSubStackView:_codecStack];
[self addSetting:self.resolutionStack ofIdentifier:@"resolutionStack" to:videoSection];
[self addSetting:self.fpsStack ofIdentifier:@"fpsStack" to:videoSection];
[self addSetting:self.codecStack ofIdentifier:@"codecStack" to:videoSection];
[videoSection addToParentStack:parentStack];
[videoSection setExpanded:YES];
//_fpsStack.userInteractionEnabled = NO;
@@ -420,19 +428,13 @@ BOOL isCustomResolution(CGSize res) {
if (@available(iOS 13.0, *)) {
[gesturesSection setSectionIcon:[UIImage systemImageNamed:@"hand.draw"]];
} else [gesturesSection setSectionIcon:nil];
self.keyboardToggleFingerNumStack.accessibilityIdentifier = @"keyboardToggleFingerNumStack";
self.slideToSettingsScreenEdgeStack.accessibilityIdentifier = @"slideToSettingsScreenEdgeStack";
self.slideToCmdToolScreenEdgeStack.accessibilityIdentifier = @"slideToCmdToolScreenEdgeStack";
self.slideToSettingsDistanceStack.accessibilityIdentifier = @"slideToSettingsDistanceStack";
[gesturesSection addSubStackView:_keyboardToggleFingerNumStack];
[gesturesSection addSubStackView:_slideToSettingsScreenEdgeStack];
[gesturesSection addSubStackView:_slideToCmdToolScreenEdgeStack];
[gesturesSection addSubStackView:_slideToSettingsDistanceStack];
// [gesturesSection addSubStackView:_unlockDisplayOrientationStack];
[self addSetting:self.keyboardToggleFingerNumStack ofIdentifier:@"keyboardToggleFingerNumStack" to:gesturesSection];
[self addSetting:self.slideToSettingsScreenEdgeStack ofIdentifier:@"slideToSettingsScreenEdgeStack" to:gesturesSection];
[self addSetting:self.slideToCmdToolScreenEdgeStack ofIdentifier:@"slideToCmdToolScreenEdgeStack" to:gesturesSection];
[self addSetting:self.slideToSettingsDistanceStack ofIdentifier:@"slideToSettingsDistanceStack" to:gesturesSection];
[gesturesSection addToParentStack:parentStack];
[gesturesSection setExpanded:YES];
}
@@ -497,6 +499,7 @@ BOOL isCustomResolution(CGSize res) {
- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture {
if (gesture.state == UIGestureRecognizerStateBegan) {
// capture setting stack
CGPoint point = [gesture locationInView:self.view];
UIView *touchedView = [self.view hitTest:point withEvent:nil];
UIStackView* capturedStack;
@@ -507,16 +510,99 @@ BOOL isCustomResolution(CGSize res) {
else NSLog(@"hit test: not setting stack captured");
// NSLog(@"hit test obj: %@", touchedView);
NSLog(@"hit test name: %@", capturedStack.accessibilityIdentifier);
if(capturedStack == nil) return;
// actionsheet
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *favoriteAction = [UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Add to favorite"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
[self addSettingToFavorite:capturedStack];
// 在这里执行收藏逻辑
}];
[actionSheet addAction:favoriteAction];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
actionSheet.popoverPresentationController.sourceView = self.view;
actionSheet.popoverPresentationController.sourceRect = CGRectMake(point.x, point.y, 1, 1);
}
[self presentViewController:actionSheet animated:YES completion:nil];
}
}
- (void)addSettingToFavorite:(UIStackView* )settingStack{
[_favoriteSettingStackIdentifiers addObject:settingStack.accessibilityIdentifier];
for(NSString *identifier in _favoriteSettingStackIdentifiers){
NSLog(@"favorite setting: %@", identifier);
}
}
- (void)switchToFavoriteSettings{
[self updateTheme];
currentSettingsMenuMode = FavoriteSettings;
DataManager* dataMan = [[DataManager alloc] init];
Settings *currentSettings = [dataMan retrieveSettings];
currentSettings.settingsMenuMode = [NSNumber numberWithInteger:currentSettingsMenuMode];
[dataMan saveData];
for(UIView* view in parentStack.subviews){
[view removeFromSuperview];
}
parentStack.spacing = 15;
for(NSString* settingIdentifier in _favoriteSettingStackIdentifiers){
[parentStack addArrangedSubview:_settingStackDict[settingIdentifier]];
}
}
- (void)switchToAllSettings{
[self updateTheme];
currentSettingsMenuMode = AllSettings;
DataManager* dataMan = [[DataManager alloc] init];
Settings *currentSettings = [dataMan retrieveSettings];
currentSettings.settingsMenuMode = [NSNumber numberWithInteger:currentSettingsMenuMode];
[dataMan saveData];
for(UIView* view in parentStack.subviews){
[view removeFromSuperview];
}
[self initParentStack];
[self layoutSections];
}
- (void)saveFavoriteSettingStackIdentifiers {
[[NSUserDefaults standardUserDefaults] setObject:_favoriteSettingStackIdentifiers forKey:@"FavoriteSettingStackIdentifiers"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)loadFavoriteSettingStackIdentifiers {
NSArray *savedArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"FavoriteSettingStackIdentifiers"];
if ([savedArray isKindOfClass:[NSArray class]]) {
_favoriteSettingStackIdentifiers = [savedArray mutableCopy];
} else {
_favoriteSettingStackIdentifiers = [NSMutableArray array];
}
/*
for(NSString* str in _favoriteSettingStackIdentifiers){
NSLog(@"favarite setting loaded: %@", str);
}
*/
}
- (void)viewDidLoad {
//[self updateTheme];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
[self.view addGestureRecognizer:longPress];
_settingStackDict = [[NSMutableDictionary alloc] init];
// return;
BOOL isIPad = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
if(isIPad){
@@ -530,6 +616,8 @@ BOOL isCustomResolution(CGSize res) {
}
// [self swi];
self->slideToCloseSettingsViewRecognizer = [[CustomEdgeSlideGestureRecognizer alloc] initWithTarget:self action:@selector(edgeSwiped)];
slideToCloseSettingsViewRecognizer.edges = UIRectEdgeLeft;
slideToCloseSettingsViewRecognizer.normalizedThresholdDistance = 0.0;
@@ -553,6 +641,21 @@ BOOL isCustomResolution(CGSize res) {
DataManager* dataMan = [[DataManager alloc] init];
TemporarySettings* currentSettings = [dataMan getSettings];
currentSettingsMenuMode = currentSettings.settingsMenuMode.intValue;
[self loadFavoriteSettingStackIdentifiers];
switch (currentSettingsMenuMode) {
case FavoriteSettings:
[self switchToFavoriteSettings];
break;
case AllSettings:
[self switchToAllSettings];
break;
default:
break;
}
// Ensure we pick a bitrate that falls exactly onto a slider notch
_bitrate = bitrateTable[[self getSliderValueForBitrate:[currentSettings.bitrate intValue]]];
@@ -1395,7 +1498,9 @@ BOOL isCustomResolution(CGSize res) {
unlockDisplayOrientation:unlockDisplayOrientation
resolutionSelected:resolutionSelected
externalDisplayMode:externalDisplayMode
localMousePointerMode:localMousePointerMode];
localMousePointerMode:localMousePointerMode
settinsMenuMode:currentSettingsMenuMode];
[self saveFavoriteSettingStackIdentifiers];
}
- (void)didReceiveMemoryWarning {