Custom notification sounds.

pull/1/head
Matthew Chen 7 years ago
parent 60d839d7a4
commit a837c5d41b

@ -34,15 +34,16 @@
OWSTableSection *soundsSection = [OWSTableSection new];
soundsSection.headerTitle = NSLocalizedString(
@"NOTIFICATIONS_SECTION_SOUNDS", @"Label for settings UI allows user to change the notification sound.");
@"NOTIFICATIONS_SECTION_SOUNDS", @"Label for settings UI that allows user to change the notification sound.");
[soundsSection
addItem:[OWSTableItem
disclosureItemWithText:NSLocalizedString(@"NOTIFICATIONS_ITEM_SOUND",
@"Label for item that allows user to change the notification sound.")
actionBlock:^{
NotificationSoundsViewController *vc = [NotificationSoundsViewController new];
[weakSelf.navigationController pushViewController:vc animated:YES];
}]];
addItem:[OWSTableItem disclosureItemWithText:
NSLocalizedString(@"NOTIFICATIONS_ITEM_SOUND",
@"Label for settings view that allows user to change the notification sound.")
actionBlock:^{
NotificationSoundsViewController *vc =
[NotificationSoundsViewController new];
[weakSelf.navigationController pushViewController:vc animated:YES];
}]];
[contents addSection:soundsSection];
OWSTableSection *backgroundSection = [OWSTableSection new];

@ -23,7 +23,8 @@
{
[super viewDidLoad];
[self setTitle:NSLocalizedString(@"SETTINGS_NOTIFICATION_SOUND", nil)];
[self setTitle:NSLocalizedString(@"NOTIFICATIONS_ITEM_SOUND",
@"Label for settings view that allows user to change the notification sound.")];
OWSPreferences *preferences = [Environment preferences];
self.globalNotificationSound = preferences.globalNotificationSound;
@ -64,50 +65,28 @@
OWSTableSection *soundsSection = [OWSTableSection new];
soundsSection.headerTitle = NSLocalizedString(
@"NOTIFICATIONS_SECTION_SOUNDS", @"Label for settings UI allows user to change the notification sound.");
@"NOTIFICATIONS_SECTION_SOUNDS", @"Label for settings UI that allows user to change the notification sound.");
for (NSNumber *nsNotificationSound in [NotificationSounds allNotificationSounds]) {
NotificationSound notificationSound = (NotificationSound)nsNotificationSound.intValue;
// TODO: No disclosure, show checkmark.
[soundsSection
addItem:[OWSTableItem
disclosureItemWithText:[NotificationSounds displayNameForNotificationSound:notificationSound]
actionBlock:^{
[weakSelf notificationSoundWasSelected:notificationSound];
}]];
OWSTableItem *item;
if (notificationSound == self.globalNotificationSound) {
item = [OWSTableItem
checkmarkItemWithText:[NotificationSounds displayNameForNotificationSound:notificationSound]
actionBlock:^{
[weakSelf notificationSoundWasSelected:notificationSound];
}];
} else {
item =
[OWSTableItem actionItemWithText:[NotificationSounds displayNameForNotificationSound:notificationSound]
actionBlock:^{
[weakSelf notificationSoundWasSelected:notificationSound];
}];
}
[soundsSection addItem:item];
}
[contents addSection:soundsSection];
// OWSTableSection *backgroundSection = [OWSTableSection new];
// backgroundSection.headerTitle = NSLocalizedString(@"NOTIFICATIONS_SECTION_BACKGROUND", nil);
// [backgroundSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
// UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
// reuseIdentifier:@"UITableViewCellStyleValue1"];
//
// NotificationType notifType = [prefs notificationPreviewType];
// NSString *detailString = [prefs nameForNotificationPreviewType:notifType];
// cell.textLabel.text = NSLocalizedString(@"NOTIFICATIONS_SHOW", nil);
// cell.detailTextLabel.text = detailString;
// [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
//
// return cell;
// }
// actionBlock:^{
// NotificationSettingsOptionsViewController *vc =
// [NotificationSettingsOptionsViewController new];
// [weakSelf.navigationController pushViewController:vc
// animated:YES];
// }]];
// [contents addSection:backgroundSection];
//
// OWSTableSection *inAppSection = [OWSTableSection new];
// inAppSection.headerTitle = NSLocalizedString(@"NOTIFICATIONS_SECTION_INAPP", nil);
// [inAppSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"NOTIFICATIONS_SOUND", nil)
// isOn:[prefs soundInForeground]
// target:weakSelf
// selector:@selector(didToggleSoundNotificationsSwitch:)]];
// [contents addSection:inAppSection];
self.contents = contents;
}
@ -124,16 +103,13 @@
self.globalNotificationSound = notificationSound;
self.isDirty = YES;
[self updateTableContents];
[self updateNavigationItems];
}
//- (void)didToggleSoundNotificationsSwitch:(UISwitch *)sender {
// [Environment.preferences setSoundInForeground:sender.on];
//}
- (void)cancelWasPressed:(id)sender
{
// TODO: Add "discard changes?" alert.
[self dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popViewControllerAnimated:YES];
}
- (void)saveWasPressed:(id)sender
@ -141,7 +117,7 @@
OWSPreferences *preferences = [Environment preferences];
preferences.globalNotificationSound = self.globalNotificationSound;
[self dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popViewControllerAnimated:YES];
}
@end

@ -1146,7 +1146,7 @@
/* No comment provided by engineer. */
"NOTIFICATIONS_FOOTER_WARNING" = "Due to known bugs in Apple's push framework, message previews will only be shown if the message is retrieved within 30 seconds after being sent. The application badge might be inaccurate as a result.";
/* Label for item that allows user to change the notification sound. */
/* Label for settings view that allows user to change the notification sound. */
"NOTIFICATIONS_ITEM_SOUND" = "Sound";
/* No comment provided by engineer. */
@ -1158,7 +1158,7 @@
/* No comment provided by engineer. */
"NOTIFICATIONS_SECTION_INAPP" = "In-App Notifications";
/* Label for settings UI allows user to change the notification sound. */
/* Label for settings UI that allows user to change the notification sound. */
"NOTIFICATIONS_SECTION_SOUNDS" = "Sounds";
/* No comment provided by engineer. */
@ -1575,9 +1575,6 @@
/* Title for settings activity */
"SETTINGS_NAV_BAR_TITLE" = "Settings";
/* No comment provided by engineer. */
"SETTINGS_NOTIFICATION_SOUND" = "SETTINGS_NOTIFICATION_SOUND";
/* No comment provided by engineer. */
"SETTINGS_NOTIFICATIONS" = "Notifications";

@ -76,6 +76,12 @@ typedef UITableViewCell *_Nonnull (^OWSTableCustomCellBlock)(void);
customRowHeight:(CGFloat)customRowHeight
actionBlock:(nullable OWSTableActionBlock)actionBlock;
+ (OWSTableItem *)checkmarkItemWithText:(NSString *)text actionBlock:(nullable OWSTableActionBlock)actionBlock;
+ (OWSTableItem *)itemWithText:(NSString *)text
actionBlock:(nullable OWSTableActionBlock)actionBlock
accessoryType:(UITableViewCellAccessoryType)accessoryType;
+ (OWSTableItem *)subPageItemWithText:(NSString *)text actionBlock:(nullable OWSTableSubPageBlock)actionBlock;
+ (OWSTableItem *)subPageItemWithText:(NSString *)text

@ -147,20 +147,31 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
}
+ (OWSTableItem *)disclosureItemWithText:(NSString *)text actionBlock:(nullable OWSTableActionBlock)actionBlock
{
return [self itemWithText:text actionBlock:actionBlock accessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
+ (OWSTableItem *)checkmarkItemWithText:(NSString *)text actionBlock:(nullable OWSTableActionBlock)actionBlock
{
return [self itemWithText:text actionBlock:actionBlock accessoryType:UITableViewCellAccessoryCheckmark];
}
+ (OWSTableItem *)itemWithText:(NSString *)text
actionBlock:(nullable OWSTableActionBlock)actionBlock
accessoryType:(UITableViewCellAccessoryType)accessoryType
{
OWSAssert(text.length > 0);
OWSAssert(actionBlock);
OWSTableItem *item = [OWSTableItem new];
item.itemType = OWSTableItemTypeAction;
__weak OWSTableItem *weakItem = item;
item.actionBlock = actionBlock;
item.customCellBlock = ^{
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = text;
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f];
cell.textLabel.textColor = [UIColor blackColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.accessoryType = accessoryType;
return cell;
};
return item;

Loading…
Cancel
Save