favorite setting stack removal function
This commit is contained in:
@@ -31,6 +31,7 @@ typedef NS_ENUM(NSInteger, TouchEventPriorityEnum) {
|
||||
typedef NS_ENUM(NSInteger, SettingsMenuMode) {
|
||||
AllSettings,
|
||||
FavoriteSettings,
|
||||
RemoveSettingItem,
|
||||
};
|
||||
|
||||
- (void) saveSettingsWithBitrate:(NSInteger)bitrate
|
||||
|
||||
@@ -352,6 +352,8 @@ typedef enum
|
||||
- (void)switchToFavoriteSettings;
|
||||
- (void)switchToAllSettings;
|
||||
- (SettingsMenuMode)getSettingsMenuMode;
|
||||
- (void)enterRemoveSettingItemMode;
|
||||
- (void)doneRemoveSettingItem;
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user