diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 26f18ea80..d031ace56 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -73,7 +73,6 @@ 34B3F89C1E8DF3270035BE1A /* BlockListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F89B1E8DF3270035BE1A /* BlockListViewController.m */; }; 34B3F89F1E8DF5490035BE1A /* OWSTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F89E1E8DF5490035BE1A /* OWSTableViewController.m */; }; 34B3F8A21E8EA6040035BE1A /* ViewControllerUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8A11E8EA6040035BE1A /* ViewControllerUtils.m */; }; - 34B7F3691EF2DB2E0083AF1C /* DebugSettingsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B7F3681EF2DB2E0083AF1C /* DebugSettingsTableViewController.m */; }; 34D5CC961EA6AFAD005515DB /* OWSContactsSyncing.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */; }; 34D5CCA91EAE3D30005515DB /* GroupViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCA81EAE3D30005515DB /* GroupViewHelper.m */; }; 34D5CCB11EAE7E7F005515DB /* SelectRecipientViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCB01EAE7E7F005515DB /* SelectRecipientViewController.m */; }; @@ -82,6 +81,8 @@ 34D8C02B1ED3685800188D7C /* DebugUIContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D8C02A1ED3685800188D7C /* DebugUIContacts.m */; }; 34DFCB851E8E04B500053165 /* AddToBlockListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34DFCB841E8E04B500053165 /* AddToBlockListViewController.m */; }; 34E3E5681EC4B19400495BAC /* AudioProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34E3E5671EC4B19400495BAC /* AudioProgressView.swift */; }; + 34E3EF0D1EFC235B007F6822 /* DebugUIDiskUsage.m in Sources */ = {isa = PBXBuildFile; fileRef = 34E3EF0C1EFC235B007F6822 /* DebugUIDiskUsage.m */; }; + 34E3EF101EFC2684007F6822 /* DebugUIPage.m in Sources */ = {isa = PBXBuildFile; fileRef = 34E3EF0F1EFC2684007F6822 /* DebugUIPage.m */; }; 34E8BF381EE9E2FD00F5F4CA /* FingerprintViewScanController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34E8BF371EE9E2FD00F5F4CA /* FingerprintViewScanController.m */; }; 34E8BF3B1EEB208E00F5F4CA /* DebugUIVerification.m in Sources */ = {isa = PBXBuildFile; fileRef = 34E8BF3A1EEB208E00F5F4CA /* DebugUIVerification.m */; }; 34F3089C1ECA4CDB00BB7697 /* TSUnreadIndicatorInteraction.m in Sources */ = {isa = PBXBuildFile; fileRef = 34F3089B1ECA4CDB00BB7697 /* TSUnreadIndicatorInteraction.m */; }; @@ -479,8 +480,6 @@ 34B3F89E1E8DF5490035BE1A /* OWSTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSTableViewController.m; sourceTree = ""; }; 34B3F8A01E8EA6040035BE1A /* ViewControllerUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewControllerUtils.h; sourceTree = ""; }; 34B3F8A11E8EA6040035BE1A /* ViewControllerUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewControllerUtils.m; sourceTree = ""; }; - 34B7F3671EF2DB2E0083AF1C /* DebugSettingsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugSettingsTableViewController.h; sourceTree = ""; }; - 34B7F3681EF2DB2E0083AF1C /* DebugSettingsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugSettingsTableViewController.m; sourceTree = ""; }; 34D5CC941EA6AFAD005515DB /* OWSContactsSyncing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSContactsSyncing.h; sourceTree = ""; }; 34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSContactsSyncing.m; sourceTree = ""; }; 34D5CC981EA6EB79005515DB /* OWSMessageCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessageCollectionViewCell.h; sourceTree = ""; }; @@ -499,6 +498,10 @@ 34DFCB831E8E04B400053165 /* AddToBlockListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddToBlockListViewController.h; sourceTree = ""; }; 34DFCB841E8E04B500053165 /* AddToBlockListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddToBlockListViewController.m; sourceTree = ""; }; 34E3E5671EC4B19400495BAC /* AudioProgressView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AudioProgressView.swift; sourceTree = ""; }; + 34E3EF0B1EFC235B007F6822 /* DebugUIDiskUsage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUIDiskUsage.h; sourceTree = ""; }; + 34E3EF0C1EFC235B007F6822 /* DebugUIDiskUsage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugUIDiskUsage.m; sourceTree = ""; }; + 34E3EF0E1EFC2684007F6822 /* DebugUIPage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUIPage.h; sourceTree = ""; }; + 34E3EF0F1EFC2684007F6822 /* DebugUIPage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugUIPage.m; sourceTree = ""; }; 34E8BF361EE9E2FD00F5F4CA /* FingerprintViewScanController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FingerprintViewScanController.h; sourceTree = ""; }; 34E8BF371EE9E2FD00F5F4CA /* FingerprintViewScanController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FingerprintViewScanController.m; sourceTree = ""; }; 34E8BF391EEB208E00F5F4CA /* DebugUIVerification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUIVerification.h; sourceTree = ""; }; @@ -933,8 +936,6 @@ 3448BFC01EDF0EA7005B2D69 /* ConversationView */, 34B3F8401E8DF1700035BE1A /* CountryCodeViewController.h */, 34B3F8411E8DF1700035BE1A /* CountryCodeViewController.m */, - 34B7F3671EF2DB2E0083AF1C /* DebugSettingsTableViewController.h */, - 34B7F3681EF2DB2E0083AF1C /* DebugSettingsTableViewController.m */, 34D8C0221ED3673300188D7C /* DebugUI */, 3497DBED1ECE2E4700DB2605 /* DomainFrontingCountryViewController.h */, 3497DBEE1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m */, @@ -1039,8 +1040,12 @@ children = ( 34D8C0291ED3685800188D7C /* DebugUIContacts.h */, 34D8C02A1ED3685800188D7C /* DebugUIContacts.m */, + 34E3EF0B1EFC235B007F6822 /* DebugUIDiskUsage.h */, + 34E3EF0C1EFC235B007F6822 /* DebugUIDiskUsage.m */, 34D8C0231ED3673300188D7C /* DebugUIMessages.h */, 34D8C0241ED3673300188D7C /* DebugUIMessages.m */, + 34E3EF0E1EFC2684007F6822 /* DebugUIPage.h */, + 34E3EF0F1EFC2684007F6822 /* DebugUIPage.m */, 452037CF1EE84975004E4CDF /* DebugUISessionState.h */, 452037D01EE84975004E4CDF /* DebugUISessionState.m */, 34D8C0251ED3673300188D7C /* DebugUITableViewController.h */, @@ -2076,6 +2081,7 @@ 45C9DEB81DF4E35A0065CA84 /* WebRTCCallMessageHandler.swift in Sources */, 34B3F88E1E8DF1700035BE1A /* PrivacySettingsTableViewController.m in Sources */, 4505C2C21E648F7A00CEBF41 /* ExperienceUpgradeFinder.swift in Sources */, + 34E3EF0D1EFC235B007F6822 /* DebugUIDiskUsage.m in Sources */, 344F2F671E57A932000D9322 /* UIViewController+OWS.m in Sources */, B6DA6B071B8A2F9A00CA6F98 /* AppStoreRating.m in Sources */, 451A13B11E13DED2000A50FD /* CallNotificationsAdapter.swift in Sources */, @@ -2089,7 +2095,6 @@ 34B3F8791E8DF1700035BE1A /* CountryCodeViewController.m in Sources */, 4CE0E3771B954546007210CF /* TSAnimatedAdapter.m in Sources */, 4531C9C41DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m in Sources */, - 34B7F3691EF2DB2E0083AF1C /* DebugSettingsTableViewController.m in Sources */, 4542F0961EBB9E9A00C7EE92 /* Promise+retainUntilComplete.swift in Sources */, 4516E3FF1DD2193B00DC4206 /* OWS101ExistingUsersBlockOnIdentityChange.m in Sources */, 4505C2BF1E648EA300CEBF41 /* ExperienceUpgrade.swift in Sources */, @@ -2115,6 +2120,7 @@ 34B3F8931E8DF1710035BE1A /* SignalsNavigationController.m in Sources */, 76EB063A18170B33006006FC /* FunctionalUtil.m in Sources */, 34F308A21ECB469700BB7697 /* OWSBezierPathView.m in Sources */, + 34E3EF101EFC2684007F6822 /* DebugUIPage.m in Sources */, 34E8BF3B1EEB208E00F5F4CA /* DebugUIVerification.m in Sources */, 76EB058A18170B33006006FC /* Release.m in Sources */, 45D231771DC7E8F10034FA89 /* SessionResetJob.swift in Sources */, diff --git a/Signal/src/ViewControllers/AboutTableViewController.h b/Signal/src/ViewControllers/AboutTableViewController.h index 226aa9030..f0cb0a2c7 100644 --- a/Signal/src/ViewControllers/AboutTableViewController.h +++ b/Signal/src/ViewControllers/AboutTableViewController.h @@ -1,13 +1,9 @@ // -// AboutTableViewController.h -// Signal -// -// Created by Dylan Bourgeois on 05/01/15. -// Copyright (c) 2015 Open Whisper Systems. All rights reserved. +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import +#import "OWSTableViewController.h" -@interface AboutTableViewController : UITableViewController +@interface AboutTableViewController : OWSTableViewController @end diff --git a/Signal/src/ViewControllers/AboutTableViewController.m b/Signal/src/ViewControllers/AboutTableViewController.m index 574a101fb..13aeaa1c8 100644 --- a/Signal/src/ViewControllers/AboutTableViewController.m +++ b/Signal/src/ViewControllers/AboutTableViewController.m @@ -2,129 +2,72 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import #import "AboutTableViewController.h" #import "UIUtil.h" - -@interface AboutTableViewController () - -@property (strong, nonatomic) UITableViewCell *versionCell; -@property (strong, nonatomic) UITableViewCell *supportCell; -@property (strong, nonatomic) UITableViewCell *twitterInviteCell; - -@property (strong, nonatomic) UILabel *versionLabel; - -@property (strong, nonatomic) UILabel *footerView; - -@end - -typedef NS_ENUM(NSUInteger, AboutTableViewControllerSection) { - AboutTableViewControllerSectionInformation, - AboutTableViewControllerSectionHelp -}; +#import "UIView+OWS.h" +#import +#import @implementation AboutTableViewController -- (instancetype)init { - return [super initWithStyle:UITableViewStyleGrouped]; -} - -- (void)viewDidLoad { +- (void)viewDidLoad +{ [super viewDidLoad]; - [self.navigationController.navigationBar setTranslucent:NO]; - self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; -} - -- (void)loadView { - [super loadView]; self.title = NSLocalizedString(@"SETTINGS_ABOUT", @"Navbar title"); - // Version - self.versionCell = [[UITableViewCell alloc] init]; - self.versionCell.textLabel.text = NSLocalizedString(@"SETTINGS_VERSION", @""); - - self.versionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 75, 30)]; - self.versionLabel.text = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; - self.versionLabel.textColor = [UIColor lightGrayColor]; - self.versionLabel.font = [UIFont ows_regularFontWithSize:16.0f]; - self.versionLabel.textAlignment = NSTextAlignmentRight; - - self.versionCell.accessoryView = self.versionLabel; - self.versionCell.userInteractionEnabled = NO; - - // Support - self.supportCell = [[UITableViewCell alloc] init]; - self.supportCell.textLabel.text = NSLocalizedString(@"SETTINGS_SUPPORT", @""); - self.supportCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; - - // Footer - self.footerView = [[UILabel alloc] init]; - self.footerView.text = NSLocalizedString(@"SETTINGS_COPYRIGHT", @""); - self.footerView.textColor = [UIColor ows_darkGrayColor]; - self.footerView.font = [UIFont ows_regularFontWithSize:15.0f]; - self.footerView.numberOfLines = 2; - self.footerView.textAlignment = NSTextAlignmentCenter; -} - -#pragma mark - Table view data source - -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 2; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - switch (section) { - case AboutTableViewControllerSectionInformation: - return 1; - case AboutTableViewControllerSectionHelp: - return 1; - default: - return 0; - } -} - -- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { - switch (section) { - case AboutTableViewControllerSectionInformation: - return NSLocalizedString(@"SETTINGS_INFORMATION_HEADER", @""); - case AboutTableViewControllerSectionHelp: - return NSLocalizedString(@"SETTINGS_HELP_HEADER", @""); - default: - return nil; - } -} - -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - switch (indexPath.section) { - case AboutTableViewControllerSectionInformation: - return self.versionCell; - case AboutTableViewControllerSectionHelp: - return self.supportCell; - } - - return nil; -} - -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - [tableView deselectRowAtIndexPath:indexPath animated:YES]; - - switch (indexPath.section) { - case AboutTableViewControllerSectionHelp: - [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://support.whispersystems.org"]]; - break; - - default: - break; - } -} - -- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { - return section == AboutTableViewControllerSectionHelp ? self.footerView : nil; + [self updateTableContents]; } -- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { - return section == AboutTableViewControllerSectionHelp ? 60.0f : 0; +#pragma mark - Table Contents + +- (void)updateTableContents +{ + OWSTableContents *contents = [OWSTableContents new]; + + OWSTableSection *informationSection = [OWSTableSection new]; + informationSection.headerTitle = NSLocalizedString(@"SETTINGS_INFORMATION_HEADER", @""); + [informationSection addItem:[OWSTableItem labelItemWithText:NSLocalizedString(@"SETTINGS_VERSION", @"") + accessoryText:[[[NSBundle mainBundle] infoDictionary] + objectForKey:@"CFBundleVersion"]]]; + [contents addSection:informationSection]; + + OWSTableSection *helpSection = [OWSTableSection new]; + helpSection.headerTitle = NSLocalizedString(@"SETTINGS_HELP_HEADER", @""); + [helpSection + addItem:[OWSTableItem disclosureItemWithText:NSLocalizedString(@"SETTINGS_SUPPORT", @"") + actionBlock:^{ + [[UIApplication sharedApplication] + openURL:[NSURL URLWithString:@"http://support.whispersystems.org"]]; + }]]; + [contents addSection:helpSection]; + + UILabel *copyrightLabel = [UILabel new]; + copyrightLabel.text = NSLocalizedString(@"SETTINGS_COPYRIGHT", @""); + copyrightLabel.textColor = [UIColor ows_darkGrayColor]; + copyrightLabel.font = [UIFont ows_regularFontWithSize:15.0f]; + copyrightLabel.numberOfLines = 2; + copyrightLabel.lineBreakMode = NSLineBreakByWordWrapping; + copyrightLabel.textAlignment = NSTextAlignmentCenter; + helpSection.customFooterView = copyrightLabel; + helpSection.customFooterHeight = @(60.f); + +#ifdef DEBUG + __block NSUInteger threadCount; + __block NSUInteger messageCount; + [TSStorageManager.sharedManager.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { + threadCount = [[transaction ext:TSThreadDatabaseViewExtensionName] numberOfItemsInAllGroups]; + messageCount = [[transaction ext:TSMessageDatabaseViewExtensionName] numberOfItemsInAllGroups]; + }]; + + OWSTableSection *debugSection = [OWSTableSection new]; + debugSection.headerTitle = @"Debug"; + [debugSection addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Threads: %zd", threadCount]]]; + [debugSection addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Messages: %zd", messageCount]]]; + [contents addSection:debugSection]; +#endif + + self.contents = contents; } @end diff --git a/Signal/src/ViewControllers/DebugSettingsTableViewController.h b/Signal/src/ViewControllers/DebugSettingsTableViewController.h deleted file mode 100644 index 6d8edd916..000000000 --- a/Signal/src/ViewControllers/DebugSettingsTableViewController.h +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. -// - -#import "OWSTableViewController.h" - -@interface DebugSettingsTableViewController : OWSTableViewController - -@end diff --git a/Signal/src/ViewControllers/DebugSettingsTableViewController.m b/Signal/src/ViewControllers/DebugSettingsTableViewController.m deleted file mode 100644 index 4d86a4f76..000000000 --- a/Signal/src/ViewControllers/DebugSettingsTableViewController.m +++ /dev/null @@ -1,75 +0,0 @@ -// -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. -// - -#import "DebugSettingsTableViewController.h" -#import "UIFont+OWS.h" -#import -#import - -@implementation DebugSettingsTableViewController - -- (void)loadView -{ - self.tableViewStyle = UITableViewStylePlain; - [super loadView]; -} - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - [self.navigationController.navigationBar setTranslucent:NO]; - - self.title = @"Debugging"; - - [self updateTableContents]; -} - -- (void)viewWillAppear:(BOOL)animated -{ - [super viewWillAppear:animated]; - - [self updateTableContents]; -} - -- (void)dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self]; -} - -#pragma mark - Table Contents - -- (void)updateTableContents -{ - OWSTableContents *contents = [OWSTableContents new]; - OWSTableSection *section = [OWSTableSection new]; - - __block NSUInteger threadCount; - __block NSUInteger messageCount; - [TSStorageManager.sharedManager.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - threadCount = [[transaction ext:TSThreadDatabaseViewExtensionName] numberOfItemsInAllGroups]; - messageCount = [[transaction ext:TSMessageDatabaseViewExtensionName] numberOfItemsInAllGroups]; - }]; - - [section addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Threads: %zd", threadCount]]]; - [section addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Messages: %zd", messageCount]]]; - - [contents addSection:section]; - - self.contents = contents; -} - -#pragma mark - Logging - -+ (NSString *)tag -{ - return [NSString stringWithFormat:@"[%@]", self.class]; -} - -- (NSString *)tag -{ - return self.class.tag; -} - -@end diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIContacts.h b/Signal/src/ViewControllers/DebugUI/DebugUIContacts.h index d38584520..2c82ad7d5 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIContacts.h +++ b/Signal/src/ViewControllers/DebugUI/DebugUIContacts.h @@ -2,13 +2,13 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import "OWSTableViewController.h" +#import "DebugUIPage.h" NS_ASSUME_NONNULL_BEGIN -@interface DebugUIContacts : NSObject +@class OWSTableSection; -+ (OWSTableSection *)section; +@interface DebugUIContacts : DebugUIPage @end diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIContacts.m b/Signal/src/ViewControllers/DebugUI/DebugUIContacts.m index 6f865769e..20333e451 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIContacts.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIContacts.m @@ -3,7 +3,7 @@ // #import "DebugUIContacts.h" -#import "DebugUIMessages.h" +#import "OWSTableViewController.h" #import "Signal-Swift.h" #import @@ -25,10 +25,14 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Factory Methods -+ (OWSTableSection *)section +- (NSString *)name { + return @"Contacts"; +} - return [OWSTableSection sectionWithTitle:@"Contacts" +- (nullable OWSTableSection *)sectionForThread:(nullable TSThread *)thread +{ + return [OWSTableSection sectionWithTitle:self.name items:@[ [OWSTableItem itemWithTitle:@"Create 1 Random Contact" actionBlock:^{ diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIDiskUsage.h b/Signal/src/ViewControllers/DebugUI/DebugUIDiskUsage.h new file mode 100644 index 000000000..5cb1c5ff3 --- /dev/null +++ b/Signal/src/ViewControllers/DebugUI/DebugUIDiskUsage.h @@ -0,0 +1,13 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "DebugUIPage.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface DebugUIDiskUsage : DebugUIPage + +@end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIDiskUsage.m b/Signal/src/ViewControllers/DebugUI/DebugUIDiskUsage.m new file mode 100644 index 000000000..ed522fe89 --- /dev/null +++ b/Signal/src/ViewControllers/DebugUI/DebugUIDiskUsage.m @@ -0,0 +1,65 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "DebugUIDiskUsage.h" +#import "OWSTableViewController.h" +#import "Signal-Swift.h" +#import + +NS_ASSUME_NONNULL_BEGIN + +@implementation DebugUIDiskUsage + +#pragma mark - Logging + ++ (NSString *)tag +{ + return [NSString stringWithFormat:@"[%@]", self.class]; +} + +- (NSString *)tag +{ + return self.class.tag; +} + +#pragma mark - Factory Methods + +- (NSString *)name +{ + return @"Disk Usage"; +} + +- (nullable OWSTableSection *)sectionForThread:(nullable TSThread *)thread +{ + return [OWSTableSection sectionWithTitle:self.name + items:@[ + [OWSTableItem itemWithTitle:@"Log Disk Usage Stats" + actionBlock:^{ + [DebugUIDiskUsage logDiskUsageStats]; + }], + ]]; +} + ++ (void)logDiskUsageStats +{ + NSString *attachmentsFolder = [TSAttachmentStream attachmentsFolder]; + DDLogError(@"attachmentsFolder: %@", attachmentsFolder); + + // TSStorageManager *storageManager = [TSStorageManager sharedManager]; + // [storageManager.newDatabaseConnection + // readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { + // [transaction enumerateKeysAndObjectsInCollection:TSAttachmentStream.collection + // usingBlock:^(NSString *key, TSAttachment *attachment, BOOL *stop) { + // if (![attachment isKindOfClass:[TSAttachmentStream class]]) { + // return; + // } + // TSAttachmentStream *attachmentStream = (TSAttachmentStream + // *)attachment; [attachmentStreams addObject:attachmentStream]; + // }]; + // }]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.h b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.h index 118dda4a9..3c4a29725 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.h +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.h @@ -2,15 +2,13 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import "OWSTableViewController.h" +#import "DebugUIPage.h" NS_ASSUME_NONNULL_BEGIN @class TSThread; -@interface DebugUIMessages : NSObject - -+ (OWSTableSection *)sectionForThread:(TSThread *)thread; +@interface DebugUIMessages : DebugUIPage @end diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index 587e4b1e9..302b72fb1 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -4,6 +4,7 @@ #import "DebugUIMessages.h" #import "Environment.h" +#import "OWSTableViewController.h" #import "Signal-Swift.h" #import "ThreadUtil.h" #import @@ -34,12 +35,17 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Factory Methods -+ (OWSTableSection *)sectionForThread:(TSThread *)thread +- (NSString *)name +{ + return @"Messages"; +} + +- (nullable OWSTableSection *)sectionForThread:(nullable TSThread *)thread { OWSAssert(thread); return [OWSTableSection - sectionWithTitle:@"Messages" + sectionWithTitle:self.name items:@[ [OWSTableItem itemWithTitle:@"Send 10 messages (1/sec.)" actionBlock:^{ diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIPage.h b/Signal/src/ViewControllers/DebugUI/DebugUIPage.h new file mode 100644 index 000000000..4ae463272 --- /dev/null +++ b/Signal/src/ViewControllers/DebugUI/DebugUIPage.h @@ -0,0 +1,20 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "DebugUIPage.h" + +NS_ASSUME_NONNULL_BEGIN + +@class OWSTableSection; +@class TSThread; + +@interface DebugUIPage : NSObject + +- (NSString *)name; + +- (nullable OWSTableSection *)sectionForThread:(nullable TSThread *)thread; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIPage.m b/Signal/src/ViewControllers/DebugUI/DebugUIPage.m new file mode 100644 index 000000000..332d7248b --- /dev/null +++ b/Signal/src/ViewControllers/DebugUI/DebugUIPage.m @@ -0,0 +1,42 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "DebugUIPage.h" +#import "OWSTableViewController.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation DebugUIPage + +#pragma mark - Logging + ++ (NSString *)tag +{ + return [NSString stringWithFormat:@"[%@]", self.class]; +} + +- (NSString *)tag +{ + return self.class.tag; +} + +#pragma mark - Factory Methods + +- (NSString *)name +{ + OWSFail(@"This method should be overriden in subclasses."); + + return nil; +} + +- (nullable OWSTableSection *)sectionForThread:(nullable TSThread *)thread +{ + OWSFail(@"This method should be overriden in subclasses."); + + return nil; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/DebugUI/DebugUISessionState.h b/Signal/src/ViewControllers/DebugUI/DebugUISessionState.h index b315d1afd..5c7e257d5 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUISessionState.h +++ b/Signal/src/ViewControllers/DebugUI/DebugUISessionState.h @@ -2,14 +2,13 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // +#import "DebugUIPage.h" + NS_ASSUME_NONNULL_BEGIN @class TSContactThread; -@class OWSTableSection; - -@interface DebugUISessionState : NSObject -+ (OWSTableSection *)sectionForContactThread:(TSContactThread *)contactThread; +@interface DebugUISessionState : DebugUIPage @end diff --git a/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m b/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m index 2a5fb9001..7f9d133db 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m @@ -13,10 +13,19 @@ NS_ASSUME_NONNULL_BEGIN @implementation DebugUISessionState -+ (OWSTableSection *)sectionForContactThread:(TSContactThread *)contactThread +- (NSString *)name { + return @"Session State"; +} + +- (nullable OWSTableSection *)sectionForThread:(nullable TSThread *)threadParameter +{ + OWSAssert([threadParameter isKindOfClass:[TSContactThread class]]); + + TSContactThread *thread = (TSContactThread *)threadParameter; + return [OWSTableSection - sectionWithTitle:@"Session State" + sectionWithTitle:self.name items:@[ [OWSTableItem itemWithTitle:@"Log All Recipient Identities" actionBlock:^{ @@ -33,7 +42,7 @@ NS_ASSUME_NONNULL_BEGIN DDLogError(@"Flipping identity Key. Flip again to return."); OWSIdentityManager *identityManager = [OWSIdentityManager sharedManager]; - NSString *recipientId = [contactThread contactIdentifier]; + NSString *recipientId = [thread contactIdentifier]; NSData *currentKey = [identityManager identityKeyForRecipientId:recipientId]; NSMutableData *flippedKey = [NSMutableData new]; @@ -47,26 +56,26 @@ NS_ASSUME_NONNULL_BEGIN }], [OWSTableItem itemWithTitle:@"Set Verification State" actionBlock:^{ - [self presentVerificationStatePickerForContactThread:contactThread]; + [DebugUISessionState presentVerificationStatePickerForContactThread:thread]; }], [OWSTableItem itemWithTitle:@"Delete all sessions" actionBlock:^{ dispatch_async([OWSDispatch sessionStoreQueue], ^{ [[TSStorageManager sharedManager] - deleteAllSessionsForContact:contactThread.contactIdentifier]; + deleteAllSessionsForContact:thread.contactIdentifier]; }); }], [OWSTableItem itemWithTitle:@"Archive all sessions" actionBlock:^{ dispatch_async([OWSDispatch sessionStoreQueue], ^{ [[TSStorageManager sharedManager] - archiveAllSessionsForContact:contactThread.contactIdentifier]; + archiveAllSessionsForContact:thread.contactIdentifier]; }); }], [OWSTableItem itemWithTitle:@"Send session reset" actionBlock:^{ [OWSSessionResetJob - runWithContactThread:contactThread + runWithContactThread:thread messageSender:[Environment getCurrent].messageSender storageManager:[TSStorageManager sharedManager]]; }] diff --git a/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.h b/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.h index b44a189ce..096866ca7 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.h +++ b/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.h @@ -10,6 +10,8 @@ NS_ASSUME_NONNULL_BEGIN @interface DebugUITableViewController : OWSTableViewController ++ (void)presentDebugUIFromViewController:(UIViewController *)fromViewController; + + (void)presentDebugUIForThread:(TSThread *)thread fromViewController:(UIViewController *)fromViewController; @end diff --git a/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.m b/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.m index 9ed3c5e8c..5ba7bef9e 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.m @@ -4,6 +4,7 @@ #import "DebugUITableViewController.h" #import "DebugUIContacts.h" +#import "DebugUIDiskUsage.h" #import "DebugUIMessages.h" #import "DebugUISessionState.h" #import "DebugUIVerification.h" @@ -39,15 +40,17 @@ NS_ASSUME_NONNULL_BEGIN [self.navigationController pushViewController:viewController animated:YES]; } -+ (OWSTableItem *)itemForSubsection:(OWSTableSection *)section ++ (OWSTableItem *)itemForSubsection:(DebugUIPage *)page viewController:(DebugUITableViewController *)viewController + thread:(nullable TSThread *)thread { - OWSAssert(section); + OWSAssert(page); + OWSAssert(viewController); __weak DebugUITableViewController *weakSelf = viewController; - return [OWSTableItem disclosureItemWithText:section.headerTitle + return [OWSTableItem disclosureItemWithText:page.name actionBlock:^{ - [weakSelf pushPageWithSection:section]; + [weakSelf pushPageWithSection:[page sectionForThread:thread]]; }]; } @@ -63,16 +66,18 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray *subsectionItems = [NSMutableArray new]; [subsectionItems - addObject:[self itemForSubsection:[DebugUIMessages sectionForThread:thread] viewController:viewController]]; - [subsectionItems addObject:[self itemForSubsection:[DebugUIContacts section] viewController:viewController]]; + addObject:[self itemForSubsection:[DebugUIMessages new] viewController:viewController thread:thread]]; + [subsectionItems + addObject:[self itemForSubsection:[DebugUIContacts new] viewController:viewController thread:thread]]; + [subsectionItems + addObject:[self itemForSubsection:[DebugUIDiskUsage new] viewController:viewController thread:thread]]; if ([thread isKindOfClass:[TSContactThread class]]) { - TSContactThread *contactThread = (TSContactThread *)thread; - - [subsectionItems addObject:[self itemForSubsection:[DebugUISessionState sectionForContactThread:contactThread] - viewController:viewController]]; - [subsectionItems addObject:[self itemForSubsection:[DebugUIVerification sectionForThread:contactThread] - viewController:viewController]]; + [subsectionItems + addObject:[self itemForSubsection:[DebugUISessionState new] viewController:viewController thread:thread]]; + [subsectionItems + addObject:[self itemForSubsection:[DebugUIVerification new] viewController:viewController thread:thread]]; } + [contents addSection:[OWSTableSection sectionWithTitle:@"Sections" items:subsectionItems]]; if ([thread isKindOfClass:[TSContactThread class]]) { @@ -145,6 +150,25 @@ NS_ASSUME_NONNULL_BEGIN [viewController presentFromViewController:fromViewController]; } ++ (void)presentDebugUIFromViewController:(UIViewController *)fromViewController +{ + OWSAssert(fromViewController); + + DebugUITableViewController *viewController = [DebugUITableViewController new]; + + OWSTableContents *contents = [OWSTableContents new]; + contents.title = @"Debug UI"; + + NSMutableArray *subsectionItems = [NSMutableArray new]; + [subsectionItems addObject:[self itemForSubsection:[DebugUIContacts new] viewController:viewController thread:nil]]; + [subsectionItems + addObject:[self itemForSubsection:[DebugUIDiskUsage new] viewController:viewController thread:nil]]; + [contents addSection:[OWSTableSection sectionWithTitle:@"Sections" items:subsectionItems]]; + + viewController.contents = contents; + [viewController presentFromViewController:fromViewController]; +} + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIVerification.h b/Signal/src/ViewControllers/DebugUI/DebugUIVerification.h index 609755b1f..3af2c99f1 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIVerification.h +++ b/Signal/src/ViewControllers/DebugUI/DebugUIVerification.h @@ -2,15 +2,13 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import "OWSTableViewController.h" +#import "DebugUIPage.h" NS_ASSUME_NONNULL_BEGIN @class TSContactThread; -@interface DebugUIVerification : NSObject - -+ (OWSTableSection *)sectionForThread:(TSContactThread *)thread; +@interface DebugUIVerification : DebugUIPage @end diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIVerification.m b/Signal/src/ViewControllers/DebugUI/DebugUIVerification.m index 1529a5512..b3cbb2785 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIVerification.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIVerification.m @@ -4,6 +4,7 @@ #import "DebugUIVerification.h" #import "DebugUIMessages.h" +#import "OWSTableViewController.h" #import "Signal-Swift.h" #import @@ -25,15 +26,22 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Factory Methods -+ (OWSTableSection *)sectionForThread:(TSContactThread *)thread +- (NSString *)name { - OWSAssert(thread); + return @"Verification"; +} + +- (nullable OWSTableSection *)sectionForThread:(nullable TSThread *)threadParameter +{ + OWSAssert([threadParameter isKindOfClass:[TSContactThread class]]); + + TSContactThread *thread = (TSContactThread *)threadParameter; NSString *recipientId = thread.contactIdentifier; OWSAssert(recipientId.length > 0); return [OWSTableSection - sectionWithTitle:@"Verification" + sectionWithTitle:self.name items:@[ [OWSTableItem itemWithTitle:@"Default" actionBlock:^{ diff --git a/Signal/src/ViewControllers/OWSTableViewController.h b/Signal/src/ViewControllers/OWSTableViewController.h index bb6218b52..645d73545 100644 --- a/Signal/src/ViewControllers/OWSTableViewController.h +++ b/Signal/src/ViewControllers/OWSTableViewController.h @@ -74,6 +74,8 @@ typedef UITableViewCell *_Nonnull (^OWSTableCustomCellBlock)(); + (OWSTableItem *)labelItemWithText:(NSString *)text; ++ (OWSTableItem *)labelItemWithText:(NSString *)text accessoryText:(NSString *)accessoryText; + - (nullable UITableViewCell *)customCell; - (NSNumber *)customRowHeight; diff --git a/Signal/src/ViewControllers/OWSTableViewController.m b/Signal/src/ViewControllers/OWSTableViewController.m index 578071160..4bd6e546d 100644 --- a/Signal/src/ViewControllers/OWSTableViewController.m +++ b/Signal/src/ViewControllers/OWSTableViewController.m @@ -207,6 +207,34 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f; cell.textLabel.text = text; cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f]; cell.textLabel.textColor = [UIColor blackColor]; + cell.userInteractionEnabled = NO; + return cell; + }; + return item; +} + ++ (OWSTableItem *)labelItemWithText:(NSString *)text accessoryText:(NSString *)accessoryText +{ + OWSAssert(text.length > 0); + OWSAssert(accessoryText.length > 0); + + OWSTableItem *item = [OWSTableItem new]; + item.itemType = OWSTableItemTypeAction; + item.customCellBlock = ^{ + UITableViewCell *cell = [UITableViewCell new]; + cell.textLabel.text = text; + cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f]; + cell.textLabel.textColor = [UIColor blackColor]; + + UILabel *accessoryLabel = [UILabel new]; + accessoryLabel.text = accessoryText; + accessoryLabel.textColor = [UIColor lightGrayColor]; + accessoryLabel.font = [UIFont ows_regularFontWithSize:16.0f]; + accessoryLabel.textAlignment = NSTextAlignmentRight; + [accessoryLabel sizeToFit]; + cell.accessoryView = accessoryLabel; + + cell.userInteractionEnabled = NO; return cell; }; return item; diff --git a/Signal/src/ViewControllers/SettingsTableViewController.m b/Signal/src/ViewControllers/SettingsTableViewController.m index 6987d0096..a09413367 100644 --- a/Signal/src/ViewControllers/SettingsTableViewController.m +++ b/Signal/src/ViewControllers/SettingsTableViewController.m @@ -5,7 +5,7 @@ #import "SettingsTableViewController.h" #import "AboutTableViewController.h" #import "AdvancedSettingsTableViewController.h" -#import "DebugSettingsTableViewController.h" +#import "DebugUITableViewController.h" #import "Environment.h" #import "NotificationSettingsViewController.h" #import "OWSContactsManager.h" @@ -195,9 +195,9 @@ }]]; #ifdef DEBUG - [section addItem:[OWSTableItem disclosureItemWithText:@"Debugging" + [section addItem:[OWSTableItem disclosureItemWithText:@"Debug UI" actionBlock:^{ - [weakSelf showDebugging]; + [weakSelf showDebugUI]; }]]; #endif @@ -272,10 +272,9 @@ [self.navigationController pushViewController:vc animated:YES]; } -- (void)showDebugging +- (void)showDebugUI { - DebugSettingsTableViewController *vc = [[DebugSettingsTableViewController alloc] init]; - [self.navigationController pushViewController:vc animated:YES]; + [DebugUITableViewController presentDebugUIFromViewController:self]; } - (void)dismissWasPressed:(id)sender