mirror of https://github.com/oxen-io/session-ios
parent
176c1f8724
commit
a155df161f
@ -0,0 +1,9 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface BlockListViewController : UITableViewController
|
||||
|
||||
@end
|
@ -0,0 +1,185 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BlockListViewController.h"
|
||||
#import "DebugLogger.h"
|
||||
#import "Environment.h"
|
||||
#import "Pastelog.h"
|
||||
#import "PropertyListPreferences.h"
|
||||
#import "PushManager.h"
|
||||
#import "Signal-Swift.h"
|
||||
#import "TSAccountManager.h"
|
||||
#import <PromiseKit/AnyPromise.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BlockListViewController ()
|
||||
|
||||
@property (nonatomic) UITableViewCell *enableLogCell;
|
||||
@property (nonatomic) UITableViewCell *submitLogCell;
|
||||
@property (nonatomic) UITableViewCell *registerPushCell;
|
||||
|
||||
@property (nonatomic) UISwitch *enableLogSwitch;
|
||||
@property (nonatomic, readonly) BOOL supportsCallKit;
|
||||
|
||||
@end
|
||||
|
||||
typedef NS_ENUM(NSInteger, BlockListViewControllerSection) {
|
||||
BlockListViewControllerSectionLogging,
|
||||
BlockListViewControllerSectionPushNotifications,
|
||||
BlockListViewControllerSection_Count // meta section
|
||||
};
|
||||
|
||||
@implementation BlockListViewController
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
[self.navigationController.navigationBar setTranslucent:NO];
|
||||
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
return [super initWithStyle:UITableViewStyleGrouped];
|
||||
}
|
||||
|
||||
- (void)loadView
|
||||
{
|
||||
[super loadView];
|
||||
|
||||
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 setOn:[PropertyListPreferences loggingIsEnabled]];
|
||||
[self.enableLogSwitch addTarget:self
|
||||
action:@selector(didToggleEnableLogSwitch:)
|
||||
forControlEvents:UIControlEventValueChanged];
|
||||
self.enableLogCell.accessoryView = self.enableLogSwitch;
|
||||
|
||||
// Send Log
|
||||
self.submitLogCell = [[UITableViewCell alloc] init];
|
||||
self.submitLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", @"");
|
||||
|
||||
self.registerPushCell = [[UITableViewCell alloc] init];
|
||||
self.registerPushCell.textLabel.text = NSLocalizedString(@"REREGISTER_FOR_PUSH", nil);
|
||||
}
|
||||
|
||||
#pragma mark - Table view data source
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||||
{
|
||||
return BlockListViewControllerSection_Count;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
|
||||
BlockListViewControllerSection settingsSection = (BlockListViewControllerSection)section;
|
||||
switch (settingsSection) {
|
||||
case BlockListViewControllerSectionLogging:
|
||||
return self.enableLogSwitch.isOn ? 2 : 1;
|
||||
case BlockListViewControllerSectionPushNotifications:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
BlockListViewControllerSection settingsSection = (BlockListViewControllerSection)section;
|
||||
switch (settingsSection) {
|
||||
case BlockListViewControllerSectionLogging:
|
||||
return NSLocalizedString(@"LOGGING_SECTION", nil);
|
||||
case BlockListViewControllerSectionPushNotifications:
|
||||
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
|
||||
{
|
||||
BlockListViewControllerSection settingsSection = (BlockListViewControllerSection)indexPath.section;
|
||||
switch (settingsSection) {
|
||||
case BlockListViewControllerSectionLogging:
|
||||
switch (indexPath.row) {
|
||||
case 0:
|
||||
return self.enableLogCell;
|
||||
case 1:
|
||||
OWSAssert(self.enableLogSwitch.isOn);
|
||||
return self.submitLogCell;
|
||||
}
|
||||
case BlockListViewControllerSectionPushNotifications:
|
||||
return self.registerPushCell;
|
||||
default:
|
||||
// Unknown section
|
||||
OWSAssert(NO);
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
|
||||
if ([tableView cellForRowAtIndexPath:indexPath] == self.submitLogCell) {
|
||||
DDLogInfo(@"%@ Submitting debug logs", self.tag);
|
||||
[DDLog flushLog];
|
||||
[Pastelog submitLogs];
|
||||
} else if ([tableView cellForRowAtIndexPath:indexPath] == self.registerPushCell) {
|
||||
OWSSyncPushTokensJob *syncJob =
|
||||
[[OWSSyncPushTokensJob alloc] initWithPushManager:[PushManager sharedManager]
|
||||
accountManager:[Environment getCurrent].accountManager
|
||||
preferences:[Environment preferences]];
|
||||
syncJob.uploadOnlyIfStale = NO;
|
||||
[syncJob run]
|
||||
.then(^{
|
||||
SignalAlertView(NSLocalizedString(@"PUSH_REGISTER_SUCCESS", @"Alert title"), nil);
|
||||
})
|
||||
.catch(^(NSError *error) {
|
||||
SignalAlertView(NSLocalizedString(@"REGISTRATION_BODY", @"Alert title"), error.localizedDescription);
|
||||
});
|
||||
|
||||
} else {
|
||||
DDLogDebug(@"%@ Ignoring cell selection at indexPath: %@", self.tag, indexPath);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Actions
|
||||
|
||||
- (void)didToggleEnableLogSwitch:(UISwitch *)sender
|
||||
{
|
||||
if (!sender.isOn) {
|
||||
[[DebugLogger sharedLogger] wipeLogs];
|
||||
[[DebugLogger sharedLogger] disableFileLogging];
|
||||
} else {
|
||||
[[DebugLogger sharedLogger] enableFileLogging];
|
||||
}
|
||||
|
||||
[PropertyListPreferences setLoggingEnabled:sender.isOn];
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
#pragma mark - Logging
|
||||
|
||||
+ (NSString *)tag
|
||||
{
|
||||
return [NSString stringWithFormat:@"[%@]", self.class];
|
||||
}
|
||||
|
||||
- (NSString *)tag
|
||||
{
|
||||
return self.class.tag;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,56 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class OWSTableItem;
|
||||
@class OWSTableSection;
|
||||
|
||||
@interface OWSTableContents : NSObject
|
||||
|
||||
@property (nonatomic) NSString *title;
|
||||
|
||||
- (void)addSection:(OWSTableSection *)section;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@interface OWSTableSection : NSObject
|
||||
|
||||
@property (nonatomic) NSString *title;
|
||||
|
||||
+ (OWSTableSection *)sectionWithTitle:(NSString *)title
|
||||
items:(NSArray *)items;
|
||||
|
||||
- (void)addItem:(OWSTableItem *)item;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
typedef NS_ENUM(NSInteger, OWSTableItemType) {
|
||||
OWSTableItemTypeAction,
|
||||
};
|
||||
|
||||
typedef void (^OWSTableActionBlock)();
|
||||
|
||||
@interface OWSTableItem : NSObject
|
||||
|
||||
+ (OWSTableItem *)actionWithTitle:(NSString *)title
|
||||
actionBlock:(OWSTableActionBlock)actionBlock;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@interface OWSTableViewController : UITableViewController
|
||||
|
||||
@property (nonatomic) OWSTableContents *contents;
|
||||
|
||||
#pragma mark - Presentation
|
||||
|
||||
- (void)presentFromViewController:(UIViewController *)fromViewController;
|
||||
|
||||
@end
|
@ -0,0 +1,226 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSTableViewController.h"
|
||||
//#import "Environment.h"
|
||||
//#import "Signal-Swift.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OWSTableContents ()
|
||||
|
||||
@property (nonatomic) NSMutableArray<OWSTableSection *> *sections;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation OWSTableContents
|
||||
|
||||
-(instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_sections = [NSMutableArray new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)addSection:(OWSTableSection *)section {
|
||||
OWSAssert(section);
|
||||
|
||||
[_sections addObject:section];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@interface OWSTableSection ()
|
||||
|
||||
@property (nonatomic) NSMutableArray<OWSTableItem *> *items;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation OWSTableSection
|
||||
|
||||
+ (OWSTableSection *)sectionWithTitle:(NSString *)title
|
||||
items:(NSArray *)items {
|
||||
OWSTableSection *section = [OWSTableSection new];
|
||||
section.title = title;
|
||||
section.items = [items mutableCopy];
|
||||
return section;
|
||||
}
|
||||
|
||||
-(instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_items = [NSMutableArray new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)addItem:(OWSTableItem *)item {
|
||||
OWSAssert(item);
|
||||
|
||||
if (!_items) {
|
||||
_items = [NSMutableArray new];
|
||||
}
|
||||
|
||||
[_items addObject:item];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@interface OWSTableItem ()
|
||||
|
||||
@property (nonatomic) OWSTableItemType itemType;
|
||||
@property (nonatomic) NSString *title;
|
||||
@property (nonatomic) OWSTableActionBlock actionBlock;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation OWSTableItem
|
||||
|
||||
+ (OWSTableItem *)actionWithTitle:(NSString *)title
|
||||
actionBlock:(OWSTableActionBlock)actionBlock {
|
||||
OWSAssert(title.length > 0);
|
||||
|
||||
OWSTableItem *item = [OWSTableItem new];
|
||||
item.itemType = OWSTableItemTypeAction;
|
||||
item.actionBlock = actionBlock;
|
||||
item.title = title;
|
||||
return item;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
NSString * const kOWSTableCellIdentifier = @"kOWSTableCellIdentifier";
|
||||
|
||||
@implementation OWSTableViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
[self.navigationController.navigationBar setTranslucent:NO];
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
return [super initWithStyle:UITableViewStyleGrouped];
|
||||
}
|
||||
|
||||
- (void)loadView
|
||||
{
|
||||
[super loadView];
|
||||
|
||||
OWSAssert(self.contents);
|
||||
|
||||
self.title = self.contents.title;
|
||||
|
||||
OWSAssert(self.tableView);
|
||||
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kOWSTableCellIdentifier];
|
||||
}
|
||||
|
||||
- (OWSTableSection *)sectionForIndex:(NSInteger)sectionIndex
|
||||
{
|
||||
OWSAssert(self.contents);
|
||||
OWSAssert(sectionIndex >= 0 && sectionIndex < (NSInteger) self.contents.sections.count);
|
||||
|
||||
OWSTableSection *section = self.contents.sections[(NSUInteger) sectionIndex];
|
||||
return section;
|
||||
}
|
||||
|
||||
- (OWSTableItem *)itemForIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
OWSAssert(self.contents);
|
||||
OWSAssert(indexPath.section >= 0 && indexPath.section < (NSInteger) self.contents.sections.count);
|
||||
|
||||
OWSTableSection *section = self.contents.sections[(NSUInteger) indexPath.section];
|
||||
OWSAssert(indexPath.item >= 0 && indexPath.item < (NSInteger) section.items.count);
|
||||
OWSTableItem *item = section.items[(NSUInteger) indexPath.item];
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
#pragma mark - Table view data source
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
||||
OWSAssert(self.contents);
|
||||
|
||||
OWSAssert(self.contents.sections.count > 0);
|
||||
return (NSInteger) self.contents.sections.count;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex {
|
||||
OWSTableSection *section = [self sectionForIndex:sectionIndex];
|
||||
OWSAssert(section.items.count > 0);
|
||||
return (NSInteger) section.items.count;
|
||||
}
|
||||
|
||||
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)sectionIndex
|
||||
{
|
||||
OWSTableSection *section = [self sectionForIndex:sectionIndex];
|
||||
return section.title;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
OWSTableItem *item = [self itemForIndexPath:indexPath];
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kOWSTableCellIdentifier];
|
||||
OWSAssert(cell);
|
||||
|
||||
cell.textLabel.text = item.title;
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
|
||||
OWSTableItem *item = [self itemForIndexPath:indexPath];
|
||||
if (item.itemType == OWSTableItemTypeAction) {
|
||||
OWSAssert(item.actionBlock);
|
||||
item.actionBlock();
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Logging
|
||||
|
||||
+ (NSString *)tag
|
||||
{
|
||||
return [NSString stringWithFormat:@"[%@]", self.class];
|
||||
}
|
||||
|
||||
- (NSString *)tag
|
||||
{
|
||||
return self.class.tag;
|
||||
}
|
||||
|
||||
#pragma mark - Presentation
|
||||
|
||||
- (void)presentFromViewController:(UIViewController *)fromViewController {
|
||||
OWSAssert(fromViewController);
|
||||
|
||||
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self];
|
||||
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop
|
||||
target:self
|
||||
action:@selector(donePressed:)];
|
||||
|
||||
[fromViewController presentViewController:navigationController
|
||||
animated:YES
|
||||
completion:nil];
|
||||
}
|
||||
|
||||
- (void)donePressed:(id)sender {
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
Loading…
Reference in New Issue