mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
5.4 KiB
Matlab
169 lines
5.4 KiB
Matlab
7 years ago
|
//
|
||
6 years ago
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||
7 years ago
|
//
|
||
|
|
||
7 years ago
|
#import "OWSSoundSettingsViewController.h"
|
||
7 years ago
|
#import <AVFoundation/AVFoundation.h>
|
||
4 years ago
|
#import <SessionMessagingKit/OWSAudioPlayer.h>
|
||
|
#import <SessionMessagingKit/OWSSounds.h>
|
||
4 years ago
|
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
|
||
|
#import <SignalUtilitiesKit/UIUtil.h>
|
||
5 years ago
|
#import "Session-Swift.h"
|
||
7 years ago
|
|
||
7 years ago
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
|
@interface OWSSoundSettingsViewController ()
|
||
7 years ago
|
|
||
|
@property (nonatomic) BOOL isDirty;
|
||
|
|
||
7 years ago
|
@property (nonatomic) OWSSound currentSound;
|
||
7 years ago
|
|
||
7 years ago
|
@property (nonatomic, nullable) OWSAudioPlayer *audioPlayer;
|
||
7 years ago
|
|
||
7 years ago
|
@end
|
||
|
|
||
|
#pragma mark -
|
||
|
|
||
7 years ago
|
@implementation OWSSoundSettingsViewController
|
||
7 years ago
|
|
||
|
- (void)viewDidLoad
|
||
|
{
|
||
|
[super viewDidLoad];
|
||
|
|
||
7 years ago
|
[self setTitle:NSLocalizedString(@"SETTINGS_ITEM_NOTIFICATION_SOUND",
|
||
7 years ago
|
@"Label for settings view that allows user to change the notification sound.")];
|
||
7 years ago
|
self.currentSound
|
||
7 years ago
|
= (self.thread ? [OWSSounds notificationSoundForThread:self.thread] : [OWSSounds globalNotificationSound]);
|
||
7 years ago
|
|
||
|
[self updateTableContents];
|
||
|
[self updateNavigationItems];
|
||
5 years ago
|
|
||
5 years ago
|
[LKViewControllerUtilities setUpDefaultSessionStyleForVC:self withTitle:NSLocalizedString(@"Sound", @"") customBackButton:NO];
|
||
5 years ago
|
self.tableView.backgroundColor = UIColor.clearColor;
|
||
7 years ago
|
}
|
||
|
|
||
|
- (void)viewDidAppear:(BOOL)animated
|
||
|
{
|
||
7 years ago
|
[super viewDidAppear:animated];
|
||
|
|
||
7 years ago
|
[self updateTableContents];
|
||
|
}
|
||
|
|
||
|
- (void)updateNavigationItems
|
||
|
{
|
||
6 years ago
|
UIBarButtonItem *cancelItem =
|
||
|
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
|
||
|
target:self
|
||
|
action:@selector(cancelWasPressed:)
|
||
6 years ago
|
accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"cancel")];
|
||
5 years ago
|
|
||
5 years ago
|
cancelItem.tintColor = LKColors.text;
|
||
5 years ago
|
|
||
6 years ago
|
self.navigationItem.leftBarButtonItem = cancelItem;
|
||
7 years ago
|
|
||
|
if (self.isDirty) {
|
||
6 years ago
|
UIBarButtonItem *saveItem =
|
||
|
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave
|
||
|
target:self
|
||
|
action:@selector(saveWasPressed:)
|
||
6 years ago
|
accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"save")];
|
||
6 years ago
|
self.navigationItem.rightBarButtonItem = saveItem;
|
||
7 years ago
|
} else {
|
||
|
self.navigationItem.rightBarButtonItem = nil;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#pragma mark - Table Contents
|
||
|
|
||
|
- (void)updateTableContents
|
||
|
{
|
||
|
OWSTableContents *contents = [OWSTableContents new];
|
||
|
|
||
7 years ago
|
__weak OWSSoundSettingsViewController *weakSelf = self;
|
||
7 years ago
|
|
||
|
OWSTableSection *soundsSection = [OWSTableSection new];
|
||
|
soundsSection.headerTitle = NSLocalizedString(
|
||
7 years ago
|
@"NOTIFICATIONS_SECTION_SOUNDS", @"Label for settings UI that allows user to change the notification sound.");
|
||
7 years ago
|
|
||
7 years ago
|
NSArray<NSNumber *> *allSounds = [OWSSounds allNotificationSounds];
|
||
7 years ago
|
for (NSNumber *nsValue in allSounds) {
|
||
7 years ago
|
OWSSound sound = (OWSSound)nsValue.intValue;
|
||
7 years ago
|
OWSTableItem *item;
|
||
7 years ago
|
|
||
|
NSString *soundLabelText = ^{
|
||
|
NSString *baseName = [OWSSounds displayNameForSound:sound];
|
||
|
if (sound == OWSSound_Note) {
|
||
|
NSString *noteStringFormat = NSLocalizedString(@"SETTINGS_AUDIO_DEFAULT_TONE_LABEL_FORMAT",
|
||
|
@"Format string for the default 'Note' sound. Embeds the system {{sound name}}.");
|
||
|
return [NSString stringWithFormat:noteStringFormat, baseName];
|
||
|
} else {
|
||
|
return [OWSSounds displayNameForSound:sound];
|
||
|
}
|
||
|
}();
|
||
|
|
||
7 years ago
|
if (sound == self.currentSound) {
|
||
6 years ago
|
item = [OWSTableItem
|
||
|
checkmarkItemWithText:soundLabelText
|
||
6 years ago
|
accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, [OWSSounds displayNameForSound:sound])
|
||
6 years ago
|
actionBlock:^{
|
||
|
[weakSelf soundWasSelected:sound];
|
||
|
}];
|
||
7 years ago
|
} else {
|
||
6 years ago
|
item = [OWSTableItem
|
||
|
actionItemWithText:soundLabelText
|
||
6 years ago
|
accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, [OWSSounds displayNameForSound:sound])
|
||
6 years ago
|
actionBlock:^{
|
||
|
[weakSelf soundWasSelected:sound];
|
||
|
}];
|
||
7 years ago
|
}
|
||
|
[soundsSection addItem:item];
|
||
7 years ago
|
}
|
||
|
|
||
|
[contents addSection:soundsSection];
|
||
|
|
||
|
self.contents = contents;
|
||
|
}
|
||
|
|
||
|
#pragma mark - Events
|
||
|
|
||
7 years ago
|
- (void)soundWasSelected:(OWSSound)sound
|
||
7 years ago
|
{
|
||
7 years ago
|
[self.audioPlayer stop];
|
||
7 years ago
|
self.audioPlayer = [OWSSounds audioPlayerForSound:sound audioBehavior:OWSAudioBehavior_Playback];
|
||
7 years ago
|
// Suppress looping in this view.
|
||
7 years ago
|
self.audioPlayer.isLooping = NO;
|
||
7 years ago
|
[self.audioPlayer play];
|
||
7 years ago
|
|
||
7 years ago
|
if (self.currentSound == sound) {
|
||
7 years ago
|
return;
|
||
|
}
|
||
|
|
||
7 years ago
|
self.currentSound = sound;
|
||
7 years ago
|
self.isDirty = YES;
|
||
|
[self updateTableContents];
|
||
7 years ago
|
[self updateNavigationItems];
|
||
7 years ago
|
}
|
||
|
|
||
|
- (void)cancelWasPressed:(id)sender
|
||
|
{
|
||
|
// TODO: Add "discard changes?" alert.
|
||
7 years ago
|
[self.audioPlayer stop];
|
||
7 years ago
|
[self.navigationController popViewControllerAnimated:YES];
|
||
7 years ago
|
}
|
||
|
|
||
|
- (void)saveWasPressed:(id)sender
|
||
|
{
|
||
7 years ago
|
if (self.thread) {
|
||
|
[OWSSounds setNotificationSound:self.currentSound forThread:self.thread];
|
||
|
} else {
|
||
|
[OWSSounds setGlobalNotificationSound:self.currentSound];
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
[self.audioPlayer stop];
|
||
7 years ago
|
[self.navigationController popViewControllerAnimated:YES];
|
||
7 years ago
|
}
|
||
|
|
||
|
@end
|
||
7 years ago
|
|
||
|
NS_ASSUME_NONNULL_END
|