|
|
|
@ -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
|
|
|
|
|