Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions ModernSettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,7 @@ - (void)configureURLHostMenuForCell:(ModernSettingsCompactButtonCell *)cell

NSMutableArray<UIAction *> *actions = [NSMutableArray array];

// Normal host
for (NSString *host in hosts) {
UIAction *action = [UIAction actionWithTitle:host
image:nil
Expand All @@ -2572,6 +2573,56 @@ - (void)configureURLHostMenuForCell:(ModernSettingsCompactButtonCell *)cell
[actions addObject:action];
}

// Custom host
UIAction *customAction = [UIAction actionWithTitle:@"Custom"
image:nil
identifier:nil
handler:^(__kindof UIAction * _Nonnull a) {

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Custom host"
message:@"Enter an URL"
preferredStyle:UIAlertControllerStyleAlert];


[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.keyboardType = UIKeyboardTypeURL;
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:nil];

UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"Save"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
UITextField *textField = alert.textFields.firstObject;
NSString *customHost = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

if (customHost.length > 0) {
[defaults setObject:customHost forKey:@"tweet_url_host"];
[defaults synchronize];

if (indexPath) {
[self.tableView reloadRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
}
}];

[alert addAction:cancelAction];
[alert addAction:saveAction];

[self presentViewController:alert animated:YES completion:nil];
}];

if (currentHost.length > 0 && ![hosts containsObject:currentHost]) {
customAction.state = UIMenuElementStateOn;
}

[actions addObject:customAction];


UIMenu *menu = [UIMenu menuWithTitle:@"URL"
image:nil
identifier:nil
Expand Down