|
|
@ -15,134 +15,111 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
|
|
@interface AdvancedSettingsTableViewController ()
|
|
|
|
@interface AdvancedSettingsTableViewController ()
|
|
|
|
|
|
|
|
|
|
|
|
@property (nonatomic) UITableViewCell *enableLogCell;
|
|
|
|
|
|
|
|
@property (nonatomic) UITableViewCell *submitLogCell;
|
|
|
|
|
|
|
|
@property (nonatomic) UITableViewCell *registerPushCell;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property (nonatomic) UISwitch *enableLogSwitch;
|
|
|
|
@property (nonatomic) UISwitch *enableLogSwitch;
|
|
|
|
@property (nonatomic, readonly) BOOL supportsCallKit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) {
|
|
|
|
#pragma mark -
|
|
|
|
AdvancedSettingsTableViewControllerSectionLogging,
|
|
|
|
|
|
|
|
AdvancedSettingsTableViewControllerSectionPushNotifications,
|
|
|
|
|
|
|
|
AdvancedSettingsTableViewControllerSection_Count // meta section
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation AdvancedSettingsTableViewController
|
|
|
|
@implementation AdvancedSettingsTableViewController
|
|
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
|
|
|
[self.navigationController.navigationBar setTranslucent:NO];
|
|
|
|
|
|
|
|
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (instancetype)init
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return [super initWithStyle:UITableViewStyleGrouped];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)loadView
|
|
|
|
- (void)loadView
|
|
|
|
{
|
|
|
|
{
|
|
|
|
[super loadView];
|
|
|
|
[super loadView];
|
|
|
|
|
|
|
|
|
|
|
|
self.title = NSLocalizedString(@"SETTINGS_ADVANCED_TITLE", @"");
|
|
|
|
self.title = NSLocalizedString(@"SETTINGS_ADVANCED_TITLE", @"");
|
|
|
|
|
|
|
|
|
|
|
|
// Enable Log
|
|
|
|
|
|
|
|
self.enableLogCell = [[UITableViewCell alloc] init];
|
|
|
|
|
|
|
|
self.enableLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @"");
|
|
|
|
|
|
|
|
self.enableLogCell.userInteractionEnabled = YES;
|
|
|
|
|
|
|
|
self.enableLogSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
|
|
|
|
self.enableLogSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
|
|
|
|
[self.enableLogSwitch setOn:[PropertyListPreferences loggingIsEnabled]];
|
|
|
|
[self.enableLogSwitch setOn:[PropertyListPreferences loggingIsEnabled]];
|
|
|
|
[self.enableLogSwitch addTarget:self
|
|
|
|
[self.enableLogSwitch addTarget:self
|
|
|
|
action:@selector(didToggleEnableLogSwitch:)
|
|
|
|
action:@selector(didToggleEnableLogSwitch:)
|
|
|
|
forControlEvents:UIControlEventValueChanged];
|
|
|
|
forControlEvents:UIControlEventValueChanged];
|
|
|
|
self.enableLogCell.accessoryView = self.enableLogSwitch;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send Log
|
|
|
|
[self observeNotifications];
|
|
|
|
self.submitLogCell = [[UITableViewCell alloc] init];
|
|
|
|
|
|
|
|
self.submitLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", @"");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.registerPushCell = [[UITableViewCell alloc] init];
|
|
|
|
[self updateTableContents];
|
|
|
|
self.registerPushCell.textLabel.text = NSLocalizedString(@"REREGISTER_FOR_PUSH", nil);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
- (void)observeNotifications
|
|
|
|
|
|
|
|
{
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
return AdvancedSettingsTableViewControllerSection_Count;
|
|
|
|
selector:@selector(socketStateDidChange)
|
|
|
|
|
|
|
|
name:kNSNotification_SocketManagerStateDidChange
|
|
|
|
|
|
|
|
object:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
- (void)dealloc
|
|
|
|
|
|
|
|
{
|
|
|
|
AdvancedSettingsTableViewControllerSection settingsSection = (AdvancedSettingsTableViewControllerSection)section;
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
switch (settingsSection) {
|
|
|
|
|
|
|
|
case AdvancedSettingsTableViewControllerSectionLogging:
|
|
|
|
|
|
|
|
return self.enableLogSwitch.isOn ? 2 : 1;
|
|
|
|
|
|
|
|
case AdvancedSettingsTableViewControllerSectionPushNotifications:
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
|
|
|
- (void)socketStateDidChange
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AdvancedSettingsTableViewControllerSection settingsSection = (AdvancedSettingsTableViewControllerSection)section;
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
switch (settingsSection) {
|
|
|
|
|
|
|
|
case AdvancedSettingsTableViewControllerSectionLogging:
|
|
|
|
[self updateTableContents];
|
|
|
|
return NSLocalizedString(@"LOGGING_SECTION", nil);
|
|
|
|
|
|
|
|
case AdvancedSettingsTableViewControllerSectionPushNotifications:
|
|
|
|
|
|
|
|
return NSLocalizedString(@"PUSH_REGISTER_TITLE", @"Used in table section header and alert view title contexts");
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
#pragma mark - Table Contents
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)updateTableContents
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AdvancedSettingsTableViewControllerSection settingsSection = (AdvancedSettingsTableViewControllerSection)indexPath.section;
|
|
|
|
OWSTableContents *contents = [OWSTableContents new];
|
|
|
|
switch (settingsSection) {
|
|
|
|
|
|
|
|
case AdvancedSettingsTableViewControllerSectionLogging:
|
|
|
|
|
|
|
|
switch (indexPath.row) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
return self.enableLogCell;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
OWSAssert(self.enableLogSwitch.isOn);
|
|
|
|
|
|
|
|
return self.submitLogCell;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case AdvancedSettingsTableViewControllerSectionPushNotifications:
|
|
|
|
|
|
|
|
return self.registerPushCell;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
// Unknown section
|
|
|
|
|
|
|
|
OWSAssert(NO);
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
__weak AdvancedSettingsTableViewController *weakSelf = self;
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
|
|
|
|
|
|
|
|
|
|
OWSTableSection *loggingSection = [OWSTableSection new];
|
|
|
|
if ([tableView cellForRowAtIndexPath:indexPath] == self.submitLogCell) {
|
|
|
|
loggingSection.headerTitle = NSLocalizedString(@"LOGGING_SECTION", nil);
|
|
|
|
DDLogInfo(@"%@ Submitting debug logs", self.tag);
|
|
|
|
[loggingSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
|
|
|
[DDLog flushLog];
|
|
|
|
UITableViewCell *cell = [UITableViewCell new];
|
|
|
|
[Pastelog submitLogs];
|
|
|
|
cell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @"");
|
|
|
|
} else if ([tableView cellForRowAtIndexPath:indexPath] == self.registerPushCell) {
|
|
|
|
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f];
|
|
|
|
OWSSyncPushTokensJob *job =
|
|
|
|
cell.textLabel.textColor = [UIColor blackColor];
|
|
|
|
[[OWSSyncPushTokensJob alloc] initWithPushManager:[PushManager sharedManager]
|
|
|
|
|
|
|
|
accountManager:[Environment getCurrent].accountManager
|
|
|
|
cell.accessoryView = self.enableLogSwitch;
|
|
|
|
preferences:[Environment preferences]
|
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
showAlerts:YES];
|
|
|
|
return cell;
|
|
|
|
job.uploadOnlyIfStale = NO;
|
|
|
|
|
|
|
|
[job run];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
DDLogDebug(@"%@ Ignoring cell selection at indexPath: %@", self.tag, indexPath);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
actionBlock:nil]];
|
|
|
|
|
|
|
|
if (self.enableLogSwitch.isOn) {
|
|
|
|
|
|
|
|
[loggingSection
|
|
|
|
|
|
|
|
addItem:[OWSTableItem actionItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", @"")
|
|
|
|
|
|
|
|
actionBlock:^{
|
|
|
|
|
|
|
|
DDLogInfo(@"%@ Submitting debug logs", self.tag);
|
|
|
|
|
|
|
|
[DDLog flushLog];
|
|
|
|
|
|
|
|
[Pastelog submitLogs];
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[contents addSection:loggingSection];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OWSTableSection *pushNotificationsSection = [OWSTableSection new];
|
|
|
|
|
|
|
|
pushNotificationsSection.headerTitle
|
|
|
|
|
|
|
|
= NSLocalizedString(@"PUSH_REGISTER_TITLE", @"Used in table section header and alert view title contexts");
|
|
|
|
|
|
|
|
[pushNotificationsSection addItem:[OWSTableItem actionItemWithText:NSLocalizedString(@"REREGISTER_FOR_PUSH", nil)
|
|
|
|
|
|
|
|
actionBlock:^{
|
|
|
|
|
|
|
|
[weakSelf syncPushTokens];
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[contents addSection:pushNotificationsSection];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.contents = contents;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Actions
|
|
|
|
#pragma mark - Actions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)syncPushTokens
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
OWSSyncPushTokensJob *job =
|
|
|
|
|
|
|
|
[[OWSSyncPushTokensJob alloc] initWithPushManager:[PushManager sharedManager]
|
|
|
|
|
|
|
|
accountManager:[Environment getCurrent].accountManager
|
|
|
|
|
|
|
|
preferences:[Environment preferences]
|
|
|
|
|
|
|
|
showAlerts:YES];
|
|
|
|
|
|
|
|
job.uploadOnlyIfStale = NO;
|
|
|
|
|
|
|
|
[job run];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)didToggleEnableLogSwitch:(UISwitch *)sender {
|
|
|
|
- (void)didToggleEnableLogSwitch:(UISwitch *)sender {
|
|
|
|
if (!sender.isOn) {
|
|
|
|
if (!sender.isOn) {
|
|
|
|
[[DebugLogger sharedLogger] wipeLogs];
|
|
|
|
[[DebugLogger sharedLogger] wipeLogs];
|
|
|
@ -152,7 +129,8 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[PropertyListPreferences setLoggingEnabled:sender.isOn];
|
|
|
|
[PropertyListPreferences setLoggingEnabled:sender.isOn];
|
|
|
|
[self.tableView reloadData];
|
|
|
|
|
|
|
|
|
|
|
|
[self updateTableContents];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Logging
|
|
|
|
#pragma mark - Logging
|
|
|
|