Skip to content

Commit

Permalink
Move "Clear Reminder" to inline menu
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
  • Loading branch information
SystemKeeper committed Aug 9, 2023
1 parent 8cda909 commit 6bf3b55
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
31 changes: 19 additions & 12 deletions NextcloudTalk/NCChatViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -4223,9 +4223,9 @@ - (NSArray *)getSetReminderOptionsForMessage:(NCChatMessage *)message

void (^setReminderCompletion)(NSError * error) = ^void(NSError *error) {
if (error) {
[[JDStatusBarNotificationPresenter sharedPresenter] presentWithText:NSLocalizedString(@"Failed to add reminder", @"") dismissAfterDelay:5.0 includedStyle:JDStatusBarNotificationIncludedStyleError];
[[JDStatusBarNotificationPresenter sharedPresenter] presentWithText:NSLocalizedString(@"Error occurred when creating a reminder", @"") dismissAfterDelay:5.0 includedStyle:JDStatusBarNotificationIncludedStyleError];
} else {
[[JDStatusBarNotificationPresenter sharedPresenter] presentWithText:NSLocalizedString(@"Successfully added reminder", @"") dismissAfterDelay:5.0 includedStyle:JDStatusBarNotificationIncludedStyleSuccess];
[[JDStatusBarNotificationPresenter sharedPresenter] presentWithText:NSLocalizedString(@"Reminder was successfully set", @"") dismissAfterDelay:5.0 includedStyle:JDStatusBarNotificationIncludedStyleSuccess];
}
};

Expand Down Expand Up @@ -4376,27 +4376,34 @@ - (UIContextMenuConfiguration *)tableView:(UITableView *)tableView contextMenuCo
__weak typeof(self) weakSelf = self;
UIDeferredMenuElement *deferredMenuElement = [UIDeferredMenuElement elementWithUncachedProvider:^(void (^ _Nonnull completion)(NSArray<UIMenuElement *> * _Nonnull)) {
[[NCAPIController sharedInstance] getReminderForMessage:message withCompletionBlock:^(NSDictionary *responseDict, NSError *error) {
NSMutableArray *menuOptions = [[NSMutableArray alloc] init];

[menuOptions addObjectsFromArray:[weakSelf getSetReminderOptionsForMessage:message]];

if (responseDict && !error) {
// There's already an existing reminder set for this message
// -> offer a delete option
NSInteger timestamp = [[responseDict objectForKey:@"timestamp"] intValue];
NSDate *timestampDate = [NSDate dateWithTimeIntervalSince1970:timestamp];

UIAction *infoAction = [UIAction actionWithTitle:[NCUtils readableDateTimeFromDate:timestampDate] image:nil identifier:nil handler:^(UIAction *action){
}];
infoAction.attributes = UIMenuElementAttributesDisabled;

UIAction *deleteAction = [UIAction actionWithTitle:NSLocalizedString(@"Delete", @"") image:[UIImage systemImageNamed:@"trash"] identifier:nil handler:^(UIAction *action){
UIAction *clearAction = [UIAction actionWithTitle:NSLocalizedString(@"Clear reminder", @"") image:[UIImage systemImageNamed:@"trash"] identifier:nil handler:^(UIAction *action){
[[NCAPIController sharedInstance] deleteReminderForMessage:message withCompletionBlock:^(NSError *error) {
[[JDStatusBarNotificationPresenter sharedPresenter] presentWithText:NSLocalizedString(@"Successfully deleted reminder", @"") dismissAfterDelay:5.0 includedStyle:JDStatusBarNotificationIncludedStyleSuccess];
[[JDStatusBarNotificationPresenter sharedPresenter] presentWithText:NSLocalizedString(@"Reminder was successfully cleared", @"") dismissAfterDelay:5.0 includedStyle:JDStatusBarNotificationIncludedStyleSuccess];
}];
}];
deleteAction.attributes = UIMenuElementAttributesDestructive;
clearAction.subtitle = [NCUtils readableDateTimeFromDate:timestampDate];
clearAction.attributes = UIMenuElementAttributesDestructive;

completion(@[infoAction, deleteAction]);
} else {
completion([weakSelf getSetReminderOptionsForMessage:message]);
UIMenu *clearReminder = [UIMenu menuWithTitle:@""
image:nil
identifier:nil
options:UIMenuOptionsDisplayInline
children:@[clearAction]];

[menuOptions addObject:clearReminder];
}

completion(menuOptions);
}];
}];

Expand Down
21 changes: 12 additions & 9 deletions NextcloudTalk/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@
/* No comment provided by engineer. */
"Clear cache" = "Clear cache";

/* No comment provided by engineer. */
"Clear reminder" = "Clear reminder";

/* No comment provided by engineer. */
"Clear status message" = "Clear status message";

Expand Down Expand Up @@ -724,12 +727,12 @@
/* No comment provided by engineer. */
"End poll" = "End poll";

/* No comment provided by engineer. */
"Error occurred when creating a reminder" = "Error occurred when creating a reminder";

/* External signaling used */
"External" = "External";

/* No comment provided by engineer. */
"Failed to add reminder" = "Failed to add reminder";

/* No comment provided by engineer. */
"Failed to connect to %@" = "Failed to connect to %@";

Expand Down Expand Up @@ -1279,6 +1282,12 @@
/* No comment provided by engineer. */
"Reference API supported?" = "Reference API supported?";

/* No comment provided by engineer. */
"Reminder was successfully cleared" = "Reminder was successfully cleared";

/* No comment provided by engineer. */
"Reminder was successfully set" = "Reminder was successfully set";

/* No comment provided by engineer. */
"Remove" = "Remove";

Expand Down Expand Up @@ -1486,12 +1495,6 @@
/* No comment provided by engineer. */
"Submit vote" = "Submit vote";

/* No comment provided by engineer. */
"Successfully added reminder" = "Successfully added reminder";

/* No comment provided by engineer. */
"Successfully deleted reminder" = "Successfully deleted reminder";

/* No comment provided by engineer. */
"Switch account" = "Switch account";

Expand Down

0 comments on commit 6bf3b55

Please sign in to comment.