Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework building action sheets #1239

Open
wutschel opened this issue Jan 28, 2025 · 2 comments
Open

Rework building action sheets #1239

wutschel opened this issue Jan 28, 2025 · 2 comments

Comments

@wutschel
Copy link
Collaborator

Taken from review discussions in #1232.

Current implementation uses a generic and complex action sheet handler, which compares localized strings to determine the action to take. Alternative solution is to create a set of the actions:

UIAlertAction *action1 = [UIAlertAction ... handler:^{ [self do_this] }];
UIAlertAction *action2 = [UIAlertAction ... handler:^{ [self do_that] }];

In this case I would need to move the logic of what I am finally showing in the action sheet (currently a simple array of action strings which is majorly defined in AppDelegate) to the place where I am building the sheet. And ideally replacing the string in AppDelegate with enums. Something like this:

AppDelegate:

menu.sheetActions = @[
    action_play,
    action_queue,
];

ViewController:

UIAlertAction *action1 = [UIAlertAction ... handler:^{ [self play] }];
UIAlertAction *action2 = [UIAlertAction ... handler:^{ [self queue] }];

for (actionID in sheetActions) |
    switch (actionID) {
        case action_play:
            [alertCtrl addAction: action1];
            break;
        case action_queue:
            [alertCtrl addAction: action2];
            break;
       default:
           break;
    }
}
@kambala-decapitator
Copy link
Collaborator

please point to a couple of examples in the codebase

@wutschel
Copy link
Collaborator Author

Examples in the current codebase are the implementations of (void)actionSheetHandler:(NSString*) in DetailViewController, ShowInfoViewController and NowPlaying. In these methods the actions are processed by patterns like

if ([actiontitle isEqualToString:LOCALIZED_STR(@"Queue after current")]) {
    [self addQueueAfterCurrent:YES];
}
else if ([actiontitle isEqualToString:LOCALIZED_STR(@"Queue")]) {
    [self addQueueAfterCurrent:NO];
}
...

The actions themselves are added by looping through a list of action strings in sheetActions:

for (NSString *actionName in sheetActions) {
    NSString *actiontitle = actionName;
    UIAlertAction *action = [UIAlertAction actionWithTitle:actiontitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [self actionSheetHandler:actiontitle];
    }];
    [alertCtrl addAction:action];
}

The array sheetActions is usually defined in AppDelegate as part of the whole menu/UI hierarchy configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants