From e5b1eda3a128de21007cf1856ed2198a5c008295 Mon Sep 17 00:00:00 2001 From: TrueZhuanjia Date: Thu, 5 Jun 2025 22:03:26 +0800 Subject: [PATCH] favorite setting stack removal function --- Limelight/Database/DataManager.h | 1 + .../ViewControllers/SWRevealViewController.h | 2 + .../ViewControllers/SWRevealViewController.m | 54 ++++++++++++-- .../ViewControllers/SettingsViewController.m | 73 +++++++++++++++---- 4 files changed, 111 insertions(+), 19 deletions(-) diff --git a/Limelight/Database/DataManager.h b/Limelight/Database/DataManager.h index b55a0820..dd4700bf 100644 --- a/Limelight/Database/DataManager.h +++ b/Limelight/Database/DataManager.h @@ -31,6 +31,7 @@ typedef NS_ENUM(NSInteger, TouchEventPriorityEnum) { typedef NS_ENUM(NSInteger, SettingsMenuMode) { AllSettings, FavoriteSettings, + RemoveSettingItem, }; - (void) saveSettingsWithBitrate:(NSInteger)bitrate diff --git a/Limelight/ViewControllers/SWRevealViewController.h b/Limelight/ViewControllers/SWRevealViewController.h index 1ec55319..8262226d 100755 --- a/Limelight/ViewControllers/SWRevealViewController.h +++ b/Limelight/ViewControllers/SWRevealViewController.h @@ -352,6 +352,8 @@ typedef enum - (void)switchToFavoriteSettings; - (void)switchToAllSettings; - (SettingsMenuMode)getSettingsMenuMode; +- (void)enterRemoveSettingItemMode; +- (void)doneRemoveSettingItem; @end diff --git a/Limelight/ViewControllers/SWRevealViewController.m b/Limelight/ViewControllers/SWRevealViewController.m index dd0717c4..50d7ffde 100755 --- a/Limelight/ViewControllers/SWRevealViewController.m +++ b/Limelight/ViewControllers/SWRevealViewController.m @@ -1012,17 +1012,58 @@ const int FrontViewPositionNone = 0xff; }]; } +- (UIAction* )getRemoveSettingItemAction API_AVAILABLE(ios(13.0)){ + return [UIAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Remove Items"] image:[UIImage systemImageNamed:@"minus.circle"] identifier:nil handler:^(__kindof UIAction * _Nonnull action) { + [self removeSettingItemSelected]; + }]; +} + +- (UIAction* )getDoneRemoveSettingAction API_AVAILABLE(ios(13.0)){ + return [UIAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Done"] image:[UIImage systemImageNamed:@"checkmark.circle"] identifier:nil handler:^(__kindof UIAction * _Nonnull action) { + [self doneRemoveSettingItemSelected]; + }]; +} + + +- (void)removeSettingItemSelected{ + if (@available(iOS 13.0, *)) { + // UIAction* action1 = [self getAllSettingMenuAction]; + UIAction* action1 = [self getDoneRemoveSettingAction]; + if (@available(iOS 14.0, *)) _moreButton.menu = [UIMenu menuWithTitle:@"" children:@[action1]]; + } + + if ([self.navBarMenuDelegate respondsToSelector:@selector(enterRemoveSettingItemMode)]) { + [self.navBarMenuDelegate enterRemoveSettingItemMode]; + } else NSLog(@"Delegate not set or does not respond to switchToAllSettings:"); +} + +- (void)doneRemoveSettingItemSelected{ + if (@available(iOS 13.0, *)) { + UIAction* action1 = [self getAllSettingMenuAction]; + UIAction* action2 = [self getRemoveSettingItemAction]; + if (@available(iOS 14.0, *)) _moreButton.menu = [UIMenu menuWithTitle:@"" children:@[action1, action2]]; + } + + if ([self.navBarMenuDelegate respondsToSelector:@selector(doneRemoveSettingItem)]) { + [self.navBarMenuDelegate doneRemoveSettingItem]; + } else NSLog(@"Delegate not set or does not respond to switchToAllSettings:"); +} + + + - (void)setupMoreButtonMenu{ if (@available(iOS 14.0, *)) { UIMenu *menu; - + UIAction* action1 = [self getAllSettingMenuAction]; + UIAction* action2 = [self getRemoveSettingItemAction]; + // εˆ›ε»Ίθœε• switch ([self getSettingsMenuMode]) { case AllSettings: menu = [UIMenu menuWithTitle:@"" children:@[[self getFavoriteMenuAction]]]; break; case FavoriteSettings: - menu = [UIMenu menuWithTitle:@"" children:@[[self getAllSettingMenuAction]]]; + menu = [UIMenu menuWithTitle:@"" children:@[action1, action2]]; break; default: break; @@ -1074,8 +1115,9 @@ const int FrontViewPositionNone = 0xff; - (void)favoriteSettingSelected { if (@available(iOS 13.0, *)) { - UIAction* allSettings = [self getAllSettingMenuAction]; - if (@available(iOS 14.0, *)) _moreButton.menu = [UIMenu menuWithTitle:@"" children:@[allSettings]]; + UIAction* action1 = [self getAllSettingMenuAction]; + UIAction* action2 = [self getRemoveSettingItemAction]; + if (@available(iOS 14.0, *)) _moreButton.menu = [UIMenu menuWithTitle:@"" children:@[action1, action2]]; } if ([self.navBarMenuDelegate respondsToSelector:@selector(switchToFavoriteSettings)]) { [self.navBarMenuDelegate switchToFavoriteSettings]; @@ -1084,8 +1126,8 @@ const int FrontViewPositionNone = 0xff; - (void)allSettingSelected { if (@available(iOS 13.0, *)) { - UIAction* favoriteSettings = [self getFavoriteMenuAction]; - if (@available(iOS 14.0, *)) _moreButton.menu = [UIMenu menuWithTitle:@"" children:@[favoriteSettings]]; + UIAction* action1 = [self getFavoriteMenuAction]; + if (@available(iOS 14.0, *)) _moreButton.menu = [UIMenu menuWithTitle:@"" children:@[action1]]; } if ([self.navBarMenuDelegate respondsToSelector:@selector(switchToAllSettings)]) { [self.navBarMenuDelegate switchToAllSettings]; diff --git a/Limelight/ViewControllers/SettingsViewController.m b/Limelight/ViewControllers/SettingsViewController.m index bd88b6cf..3b3239fb 100644 --- a/Limelight/ViewControllers/SettingsViewController.m +++ b/Limelight/ViewControllers/SettingsViewController.m @@ -772,9 +772,35 @@ BOOL isCustomResolution(CGSize res) { [self saveFavoriteSettingStackIdentifiers]; } +- (void)attachRemoveButtonForStack:(UIStackView* )stack{ + UIButton* removeButton = [UIButton buttonWithType:UIButtonTypeSystem]; + if (@available(iOS 13.0, *)) { + UIImageSymbolConfiguration *config = [UIImageSymbolConfiguration configurationWithPointSize:16 weight:UIImageSymbolWeightMedium]; + [removeButton setImage:[UIImage systemImageNamed:@"minus.circle" withConfiguration:config] forState:UIControlStateNormal]; + } else { + [removeButton setTitle:@"Remove" forState:UIControlStateNormal]; + } + removeButton.accessibilityIdentifier = @"removeButton"; + removeButton.translatesAutoresizingMaskIntoConstraints = NO; + removeButton.tintColor = [UIColor redColor]; + + [removeButton addTarget:self action:@selector(removeSettingStackFromFavorites:) forControlEvents:UIControlEventTouchUpInside]; + + [stack addSubview:removeButton]; + [NSLayoutConstraint activateConstraints:@[ + [removeButton.trailingAnchor constraintEqualToAnchor:stack.trailingAnchor constant:-8], + [removeButton.topAnchor constraintEqualToAnchor:stack.topAnchor], + ]]; +} + +- (void)removeSettingStackFromFavorites:(UIButton* )sender{ + [sender.superview removeFromSuperview]; + [sender removeFromSuperview]; + [self saveFavoriteSettingStackIdentifiers]; +} + - (void)switchToFavoriteSettings{ [self updateTheme]; - currentSettingsMenuMode = FavoriteSettings; DataManager* dataMan = [[DataManager alloc] init]; Settings *currentSettings = [dataMan retrieveSettings]; @@ -791,13 +817,6 @@ BOOL isCustomResolution(CGSize res) { } - (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){ @@ -805,17 +824,45 @@ BOOL isCustomResolution(CGSize res) { } [self initParentStack]; [self layoutSections]; + [self updateTheme]; + //[self doneRemoveSettingItem]; + currentSettingsMenuMode = AllSettings; + DataManager* dataMan = [[DataManager alloc] init]; + Settings *currentSettings = [dataMan retrieveSettings]; + currentSettings.settingsMenuMode = [NSNumber numberWithInteger:currentSettingsMenuMode]; + [dataMan saveData]; + } +- (void)enterRemoveSettingItemMode{ + currentSettingsMenuMode = RemoveSettingItem; + for(UIStackView* stack in parentStack.arrangedSubviews){ + for(UIView* view in stack.subviews) view.userInteractionEnabled = false; + [self attachRemoveButtonForStack:stack]; + // stack.userInteractionEnabled = false; + } +} + +- (void)doneRemoveSettingItem{ + currentSettingsMenuMode = FavoriteSettings; + for(UIStackView* stack in parentStack.arrangedSubviews){ + //stack.userInteractionEnabled = true; + for(UIView* view in stack.subviews){ + if([view.accessibilityIdentifier isEqualToString:@"removeButton"]) [view removeFromSuperview]; + else view.userInteractionEnabled = true; + } + } +} - (void)saveFavoriteSettingStackIdentifiers { - [_favoriteSettingStackIdentifiers removeAllObjects]; - - for(NSInteger i = 0; i < parentStack.arrangedSubviews.count; i++){ - [_favoriteSettingStackIdentifiers addObject:parentStack.arrangedSubviews[i].accessibilityIdentifier]; + if(currentSettingsMenuMode == RemoveSettingItem){ + [_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]; }