diff --git a/Signal/src/ViewControllers/NotificationSettingsOptionsViewController.h b/Signal/src/ViewControllers/NotificationSettingsOptionsViewController.h index 28f306df3..c79105d69 100644 --- a/Signal/src/ViewControllers/NotificationSettingsOptionsViewController.h +++ b/Signal/src/ViewControllers/NotificationSettingsOptionsViewController.h @@ -1,13 +1,9 @@ // -// NotificationSettingsOptionsViewController.h -// Signal -// -// Created by Frederic Jacobs on 24/04/15. -// Copyright (c) 2015 Open Whisper Systems. All rights reserved. +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import +#import "OWSTableViewController.h" -@interface NotificationSettingsOptionsViewController : UITableViewController +@interface NotificationSettingsOptionsViewController : OWSTableViewController @end diff --git a/Signal/src/ViewControllers/NotificationSettingsOptionsViewController.m b/Signal/src/ViewControllers/NotificationSettingsOptionsViewController.m index 161309286..1af83d625 100644 --- a/Signal/src/ViewControllers/NotificationSettingsOptionsViewController.m +++ b/Signal/src/ViewControllers/NotificationSettingsOptionsViewController.m @@ -6,53 +6,49 @@ #import "Environment.h" #import "PropertyListPreferences.h" -@interface NotificationSettingsOptionsViewController () - -@property NSArray *options; - -@end - @implementation NotificationSettingsOptionsViewController - (void)viewDidLoad { - self.options = @[ @(NotificationNamePreview), @(NotificationNameNoPreview), @(NotificationNoNameNoPreview) ]; - - [super viewDidLoad]; + [self updateTableContents]; } -#pragma mark - Table view data source +#pragma mark - Table Contents -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 1; -} +- (void)updateTableContents +{ + OWSTableContents *contents = [OWSTableContents new]; -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return (NSInteger)[self.options count]; -} + __weak NotificationSettingsOptionsViewController *weakSelf = self; -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 - reuseIdentifier:@"NotificationSettingsOption"]; - PropertyListPreferences *prefs = [Environment preferences]; - NSUInteger notifType = [[self.options objectAtIndex:(NSUInteger)indexPath.row] unsignedIntegerValue]; - [[cell textLabel] setText:[prefs nameForNotificationPreviewType:notifType]]; + OWSTableSection *section = [OWSTableSection new]; + section.footerTitle = NSLocalizedString(@"NOTIFICATIONS_FOOTER_WARNING", nil); + PropertyListPreferences *prefs = [Environment preferences]; NotificationType selectedNotifType = [prefs notificationPreviewType]; - - if (selectedNotifType == notifType) { - cell.accessoryType = UITableViewCellAccessoryCheckmark; + for (NSNumber *option in + @[ @(NotificationNamePreview), @(NotificationNameNoPreview), @(NotificationNoNameNoPreview) ]) { + NotificationType notificationType = (NotificationType)option.intValue; + + [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ + UITableViewCell *cell = [UITableViewCell new]; + [[cell textLabel] setText:[prefs nameForNotificationPreviewType:notificationType]]; + if (selectedNotifType == notificationType) { + cell.accessoryType = UITableViewCellAccessoryCheckmark; + } + return cell; + } + actionBlock:^{ + [weakSelf setNotificationType:notificationType]; + }]]; } + [contents addSection:section]; - return cell; -} - -- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { - return NSLocalizedString(@"NOTIFICATIONS_FOOTER_WARNING", nil); + self.contents = contents; } -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - [Environment.preferences - setNotificationPreviewType:[[self.options objectAtIndex:(NSUInteger)indexPath.row] unsignedIntegerValue]]; +- (void)setNotificationType:(NotificationType)notificationType +{ + [Environment.preferences setNotificationPreviewType:notificationType]; [self.navigationController popViewControllerAnimated:YES]; } diff --git a/Signal/src/ViewControllers/NotificationSettingsViewController.h b/Signal/src/ViewControllers/NotificationSettingsViewController.h index 98efaf3ae..56ff55d1b 100644 --- a/Signal/src/ViewControllers/NotificationSettingsViewController.h +++ b/Signal/src/ViewControllers/NotificationSettingsViewController.h @@ -1,13 +1,9 @@ // -// NotificationPreviewViewController.h -// Signal -// -// Created by Dylan Bourgeois on 09/12/14. -// Copyright (c) 2014 Open Whisper Systems. All rights reserved. +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import +#import "OWSTableViewController.h" -@interface NotificationSettingsViewController : UITableViewController +@interface NotificationSettingsViewController : OWSTableViewController @end diff --git a/Signal/src/ViewControllers/NotificationSettingsViewController.m b/Signal/src/ViewControllers/NotificationSettingsViewController.m index 8927f7e06..00b7746f9 100644 --- a/Signal/src/ViewControllers/NotificationSettingsViewController.m +++ b/Signal/src/ViewControllers/NotificationSettingsViewController.m @@ -7,110 +7,80 @@ #import "NotificationSettingsOptionsViewController.h" #import "PropertyListPreferences.h" -#define kNotificationOptionSection 0 - -@interface NotificationSettingsViewController () - -@property NSArray *notificationsSections; - -@end - @implementation NotificationSettingsViewController -- (instancetype)init { - return [super initWithStyle:UITableViewStyleGrouped]; -} - - (void)viewDidLoad { [super viewDidLoad]; + [self setTitle:NSLocalizedString(@"SETTINGS_NOTIFICATIONS", nil)]; - self.notificationsSections = @[ - NSLocalizedString(@"NOTIFICATIONS_SECTION_BACKGROUND", nil), - NSLocalizedString(@"NOTIFICATIONS_SECTION_INAPP", nil) - ]; + [self updateTableContents]; } - (void)viewDidAppear:(BOOL)animated { - [self.tableView reloadData]; + [self updateTableContents]; } -#pragma mark - Table view data source - -- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { - return [self.notificationsSections objectAtIndex:(NSUInteger)section]; -} +#pragma mark - Table Contents -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return (NSInteger)self.notificationsSections.count; -} +- (void)updateTableContents +{ + OWSTableContents *contents = [OWSTableContents new]; -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 1; -} + __weak NotificationSettingsViewController *weakSelf = self; -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - NSString *cellIdentifier = @"SignalTableViewCellIdentifier"; - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; + PropertyListPreferences *prefs = [Environment preferences]; - if (cell == nil) { - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier]; - } + OWSTableSection *backgroundSection = [OWSTableSection new]; + backgroundSection.headerTitle = NSLocalizedString(@"NOTIFICATIONS_SECTION_BACKGROUND", nil); + [backgroundSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ + UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 + reuseIdentifier:@"UITableViewCellStyleValue1"]; - PropertyListPreferences *prefs = Environment.preferences; - if (indexPath.section == kNotificationOptionSection) { NotificationType notifType = [prefs notificationPreviewType]; NSString *detailString = [prefs nameForNotificationPreviewType:notifType]; [[cell textLabel] setText:NSLocalizedString(@"NOTIFICATIONS_SHOW", nil)]; [[cell detailTextLabel] setText:detailString]; [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; - } else { + + 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 itemWithCustomCellBlock:^{ + UITableViewCell *cell = [UITableViewCell new]; + BOOL soundEnabled = [prefs soundInForeground]; [[cell textLabel] setText:NSLocalizedString(@"NOTIFICATIONS_SOUND", nil)]; - [[cell detailTextLabel] setText:nil]; - UISwitch *switchv = [[UISwitch alloc] initWithFrame:CGRectZero]; - switchv.on = soundEnabled; - [switchv addTarget:self - action:@selector(didToggleSoundNotificationsSwitch:) - forControlEvents:UIControlEventValueChanged]; - - cell.accessoryView = switchv; + UISwitch *soundSwitch = [UISwitch new]; + soundSwitch.on = soundEnabled; + [soundSwitch addTarget:self + action:@selector(didToggleSoundNotificationsSwitch:) + forControlEvents:UIControlEventValueChanged]; + + cell.accessoryView = soundSwitch; + cell.selectionStyle = UITableViewCellSelectionStyleNone; + return cell; } + actionBlock:nil]]; + [contents addSection:inAppSection]; - return cell; + self.contents = contents; } +#pragma mark - Events + - (void)didToggleSoundNotificationsSwitch:(UISwitch *)sender { [Environment.preferences setSoundInForeground:sender.on]; } -- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath { - switch (indexPath.section) { - case kNotificationOptionSection: { - return indexPath; - } - default: { - return nil; - } - } -} - -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - switch (indexPath.section) { - case kNotificationOptionSection: { - NotificationSettingsOptionsViewController *vc = - [[NotificationSettingsOptionsViewController alloc] initWithStyle:UITableViewStyleGrouped]; - [self.navigationController pushViewController:vc animated:YES]; - break; - } - } -} - -- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; - cell.accessoryType = UITableViewCellAccessoryNone; -} - @end