favorite setting stack removal function
This commit is contained in:
1 parent
3120cd785b
commit
e5b1eda3a1
4 files changed
+111
-19
No files matched your search
@@ -31,6 +31,7 @@ typedef NS_ENUM(NSInteger, TouchEventPriorityEnum) {
|
|||||||
typedef NS_ENUM(NSInteger, SettingsMenuMode) {
|
typedef NS_ENUM(NSInteger, SettingsMenuMode) {
|
||||||
AllSettings,
|
AllSettings,
|
||||||
FavoriteSettings,
|
FavoriteSettings,
|
||||||
|
RemoveSettingItem,
|
||||||
};
|
};
|
||||||
|
|
||||||
- (void) saveSettingsWithBitrate:(NSInteger)bitrate
|
- (void) saveSettingsWithBitrate:(NSInteger)bitrate
|
||||||
|
|||||||
@@ -352,6 +352,8 @@ typedef enum
|
|||||||
- (void)switchToFavoriteSettings;
|
- (void)switchToFavoriteSettings;
|
||||||
- (void)switchToAllSettings;
|
- (void)switchToAllSettings;
|
||||||
- (SettingsMenuMode)getSettingsMenuMode;
|
- (SettingsMenuMode)getSettingsMenuMode;
|
||||||
|
- (void)enterRemoveSettingItemMode;
|
||||||
|
- (void)doneRemoveSettingItem;
|
||||||
@end
|
@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{
|
- (void)setupMoreButtonMenu{
|
||||||
if (@available(iOS 14.0, *)) {
|
if (@available(iOS 14.0, *)) {
|
||||||
UIMenu *menu;
|
UIMenu *menu;
|
||||||
|
UIAction* action1 = [self getAllSettingMenuAction];
|
||||||
|
UIAction* action2 = [self getRemoveSettingItemAction];
|
||||||
|
|
||||||
// 创建菜单
|
// 创建菜单
|
||||||
switch ([self getSettingsMenuMode]) {
|
switch ([self getSettingsMenuMode]) {
|
||||||
case AllSettings:
|
case AllSettings:
|
||||||
menu = [UIMenu menuWithTitle:@"" children:@[[self getFavoriteMenuAction]]];
|
menu = [UIMenu menuWithTitle:@"" children:@[[self getFavoriteMenuAction]]];
|
||||||
break;
|
break;
|
||||||
case FavoriteSettings:
|
case FavoriteSettings:
|
||||||
menu = [UIMenu menuWithTitle:@"" children:@[[self getAllSettingMenuAction]]];
|
menu = [UIMenu menuWithTitle:@"" children:@[action1, action2]];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -1074,8 +1115,9 @@ const int FrontViewPositionNone = 0xff;
|
|||||||
|
|
||||||
- (void)favoriteSettingSelected {
|
- (void)favoriteSettingSelected {
|
||||||
if (@available(iOS 13.0, *)) {
|
if (@available(iOS 13.0, *)) {
|
||||||
UIAction* allSettings = [self getAllSettingMenuAction];
|
UIAction* action1 = [self getAllSettingMenuAction];
|
||||||
if (@available(iOS 14.0, *)) _moreButton.menu = [UIMenu menuWithTitle:@"" children:@[allSettings]];
|
UIAction* action2 = [self getRemoveSettingItemAction];
|
||||||
|
if (@available(iOS 14.0, *)) _moreButton.menu = [UIMenu menuWithTitle:@"" children:@[action1, action2]];
|
||||||
}
|
}
|
||||||
if ([self.navBarMenuDelegate respondsToSelector:@selector(switchToFavoriteSettings)]) {
|
if ([self.navBarMenuDelegate respondsToSelector:@selector(switchToFavoriteSettings)]) {
|
||||||
[self.navBarMenuDelegate switchToFavoriteSettings];
|
[self.navBarMenuDelegate switchToFavoriteSettings];
|
||||||
@@ -1084,8 +1126,8 @@ const int FrontViewPositionNone = 0xff;
|
|||||||
|
|
||||||
- (void)allSettingSelected {
|
- (void)allSettingSelected {
|
||||||
if (@available(iOS 13.0, *)) {
|
if (@available(iOS 13.0, *)) {
|
||||||
UIAction* favoriteSettings = [self getFavoriteMenuAction];
|
UIAction* action1 = [self getFavoriteMenuAction];
|
||||||
if (@available(iOS 14.0, *)) _moreButton.menu = [UIMenu menuWithTitle:@"" children:@[favoriteSettings]];
|
if (@available(iOS 14.0, *)) _moreButton.menu = [UIMenu menuWithTitle:@"" children:@[action1]];
|
||||||
}
|
}
|
||||||
if ([self.navBarMenuDelegate respondsToSelector:@selector(switchToAllSettings)]) {
|
if ([self.navBarMenuDelegate respondsToSelector:@selector(switchToAllSettings)]) {
|
||||||
[self.navBarMenuDelegate switchToAllSettings];
|
[self.navBarMenuDelegate switchToAllSettings];
|
||||||
|
|||||||
@@ -772,9 +772,35 @@ BOOL isCustomResolution(CGSize res) {
|
|||||||
[self saveFavoriteSettingStackIdentifiers];
|
[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{
|
- (void)switchToFavoriteSettings{
|
||||||
[self updateTheme];
|
[self updateTheme];
|
||||||
|
|
||||||
currentSettingsMenuMode = FavoriteSettings;
|
currentSettingsMenuMode = FavoriteSettings;
|
||||||
DataManager* dataMan = [[DataManager alloc] init];
|
DataManager* dataMan = [[DataManager alloc] init];
|
||||||
Settings *currentSettings = [dataMan retrieveSettings];
|
Settings *currentSettings = [dataMan retrieveSettings];
|
||||||
@@ -791,13 +817,6 @@ BOOL isCustomResolution(CGSize res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)switchToAllSettings{
|
- (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){
|
for(UIView* view in parentStack.subviews){
|
||||||
@@ -805,17 +824,45 @@ BOOL isCustomResolution(CGSize res) {
|
|||||||
}
|
}
|
||||||
[self initParentStack];
|
[self initParentStack];
|
||||||
[self layoutSections];
|
[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 {
|
- (void)saveFavoriteSettingStackIdentifiers {
|
||||||
|
|
||||||
[_favoriteSettingStackIdentifiers removeAllObjects];
|
if(currentSettingsMenuMode == RemoveSettingItem){
|
||||||
|
[_favoriteSettingStackIdentifiers removeAllObjects];
|
||||||
for(NSInteger i = 0; i < parentStack.arrangedSubviews.count; i++){
|
for(NSInteger i = 0; i < parentStack.arrangedSubviews.count; i++){
|
||||||
[_favoriteSettingStackIdentifiers addObject:parentStack.arrangedSubviews[i].accessibilityIdentifier];
|
[_favoriteSettingStackIdentifiers addObject:parentStack.arrangedSubviews[i].accessibilityIdentifier];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[NSUserDefaults standardUserDefaults] setObject:_favoriteSettingStackIdentifiers forKey:@"FavoriteSettingStackIdentifiers"];
|
[[NSUserDefaults standardUserDefaults] setObject:_favoriteSettingStackIdentifiers forKey:@"FavoriteSettingStackIdentifiers"];
|
||||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user