From 80eca1d1d362b77accb70f5b00946bbc4a021895 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 24 Sep 2019 16:36:00 +1000 Subject: [PATCH] Fix inconsistent modal usage --- Signal.xcodeproj/project.pbxproj | 4 ++ Signal/src/Loki/Settings/NukeDataModal.swift | 57 +++++++++++++++++++ Signal/src/Signal-Bridging-Header.h | 1 + .../AppSettings/AppSettingsViewController.m | 20 +------ 4 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 Signal/src/Loki/Settings/NukeDataModal.swift diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 5574af731..a998b22ad 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -576,6 +576,7 @@ B891105E2320872800F15FCC /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B891105B2320872800F15FCC /* GoogleService-Info.plist */; }; B891105F2320872800F15FCC /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B891105B2320872800F15FCC /* GoogleService-Info.plist */; }; B894D0712339D6F300B4D94D /* DeviceLinkingModalDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B894D0702339D6F300B4D94D /* DeviceLinkingModalDelegate.swift */; }; + B894D0752339EDCF00B4D94D /* NukeDataModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B894D0742339EDCF00B4D94D /* NukeDataModal.swift */; }; B89841E322B7579F00B1BDC6 /* NewConversationVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B89841E222B7579F00B1BDC6 /* NewConversationVC.swift */; }; B90418E6183E9DD40038554A /* DateUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = B90418E5183E9DD40038554A /* DateUtil.m */; }; B9EB5ABD1884C002007CBB57 /* MessageUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B9EB5ABC1884C002007CBB57 /* MessageUI.framework */; }; @@ -1382,6 +1383,7 @@ B885D5F52334A32100EE0D8E /* UIView+Constraint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Constraint.swift"; sourceTree = ""; }; B891105B2320872800F15FCC /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; B894D0702339D6F300B4D94D /* DeviceLinkingModalDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceLinkingModalDelegate.swift; sourceTree = ""; }; + B894D0742339EDCF00B4D94D /* NukeDataModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NukeDataModal.swift; sourceTree = ""; }; B89841E222B7579F00B1BDC6 /* NewConversationVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewConversationVC.swift; sourceTree = ""; }; B90418E4183E9DD40038554A /* DateUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DateUtil.h; sourceTree = ""; }; B90418E5183E9DD40038554A /* DateUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DateUtil.m; sourceTree = ""; }; @@ -2671,6 +2673,7 @@ B894D0702339D6F300B4D94D /* DeviceLinkingModalDelegate.swift */, B86BD08023399883000F5AE3 /* QRCodeModal.swift */, B86BD08523399CEF000F5AE3 /* SeedModal.swift */, + B894D0742339EDCF00B4D94D /* NukeDataModal.swift */, ); path = Settings; sourceTree = ""; @@ -3909,6 +3912,7 @@ 3496957321A301A100DCFE74 /* OWSBackupJob.m in Sources */, 340FC8B3204DAC8D007AEB0F /* AppSettingsViewController.m in Sources */, 34C4E2572118957600BEA353 /* OWSWebRTCDataProtos.pb.swift in Sources */, + B894D0752339EDCF00B4D94D /* NukeDataModal.swift in Sources */, 346B66311F4E29B200E5122F /* CropScaleImageViewController.swift in Sources */, 45E5A6991F61E6DE001E4A8A /* MarqueeLabel.swift in Sources */, 34D1F0B01F867BFC0066283D /* OWSSystemMessageCell.m in Sources */, diff --git a/Signal/src/Loki/Settings/NukeDataModal.swift b/Signal/src/Loki/Settings/NukeDataModal.swift new file mode 100644 index 000000000..e23cb0ec2 --- /dev/null +++ b/Signal/src/Loki/Settings/NukeDataModal.swift @@ -0,0 +1,57 @@ +import NVActivityIndicatorView + +@objc(LKNukeDataModal) +final class NukeDataModal : Modal { + + // MARK: Lifecycle + override func populateContentView() { + // Label + let titleLabel = UILabel() + titleLabel.textColor = Theme.primaryColor + titleLabel.font = UIFont.ows_dynamicTypeHeadlineClamped + titleLabel.text = NSLocalizedString("Clear All Data", comment: "") + titleLabel.numberOfLines = 0 + titleLabel.lineBreakMode = .byWordWrapping + titleLabel.textAlignment = .center + // Explanation label + let explanationLabel = UILabel() + explanationLabel.font = UIFont.ows_dynamicTypeCaption1Clamped + explanationLabel.text = NSLocalizedString("Are you sure you want to clear all your data? This will delete your entire account, including all conversations and your personal key pair.", comment: "") + explanationLabel.numberOfLines = 0 + explanationLabel.textAlignment = .center + explanationLabel.lineBreakMode = .byWordWrapping + explanationLabel.textColor = UIColor.ows_white + // Button stack view + let nukeButton = OWSFlatButton.button(title: NSLocalizedString("OK", comment: ""), font: .ows_dynamicTypeBodyClamped, titleColor: .white, backgroundColor: .clear, target: self, selector: #selector(nuke)) + nukeButton.setBackgroundColors(upColor: .clear, downColor: .clear) + let buttonStackView = UIStackView(arrangedSubviews: [ nukeButton, cancelButton ]) + buttonStackView.axis = .horizontal + buttonStackView.distribution = .fillEqually + let buttonHeight = cancelButton.button.titleLabel!.font.pointSize * 48 / 17 + nukeButton.set(.height, to: buttonHeight) + cancelButton.set(.height, to: buttonHeight) + // Stack view + let stackView = UIStackView(arrangedSubviews: [ UIView.spacer(withHeight: 2), titleLabel, explanationLabel, buttonStackView ]) + stackView.axis = .vertical + stackView.spacing = 16 + contentView.addSubview(stackView) + stackView.pin(.leading, to: .leading, of: contentView, withInset: 16) + stackView.pin(.top, to: .top, of: contentView, withInset: 16) + contentView.pin(.trailing, to: .trailing, of: stackView, withInset: 16) + contentView.pin(.bottom, to: .bottom, of: stackView, withInset: 16) + } + + // MARK: Interaction + @objc private func nuke() { + ThreadUtil.deleteAllContent() + SSKEnvironment.shared.identityManager.clearIdentityKey() + LokiAPI.clearRandomSnodePool() + let appDelegate = UIApplication.shared.delegate as! AppDelegate + appDelegate.stopLongPollerIfNeeded() + SSKEnvironment.shared.tsAccountManager.resetForReregistration() + let rootViewController = OnboardingController().initialViewController() + let navigationController = OWSNavigationController(rootViewController: rootViewController) + navigationController.isNavigationBarHidden = true + UIApplication.shared.keyWindow!.rootViewController = navigationController + } +} diff --git a/Signal/src/Signal-Bridging-Header.h b/Signal/src/Signal-Bridging-Header.h index 9d2eefc2a..d314ddbdb 100644 --- a/Signal/src/Signal-Bridging-Header.h +++ b/Signal/src/Signal-Bridging-Header.h @@ -6,6 +6,7 @@ #import // Separate iOS Frameworks from other imports. +#import "AppDelegate.h" #import "AVAudioSession+OWS.h" #import "AppSettingsViewController.h" #import "AttachmentUploadView.h" diff --git a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m index ecc163777..5ba9a9101 100644 --- a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m @@ -529,23 +529,9 @@ - (void)clearAllData { - NSString *title = NSLocalizedString(@"Clear All Data", @""); - NSString *message = NSLocalizedString(@"Are you sure you want to clear all your data? This will delete your entire account, including all conversations and your personal key pair.", @""); - UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; - [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { - [ThreadUtil deleteAllContent]; - [SSKEnvironment.shared.identityManager clearIdentityKey]; - [LKAPI clearRandomSnodePool]; - AppDelegate *appDelegate = (AppDelegate *)UIApplication.sharedApplication.delegate; - [appDelegate stopLongPollerIfNeeded]; - [SSKEnvironment.shared.tsAccountManager resetForReregistration]; - UIViewController *rootViewController = [[OnboardingController new] initialViewController]; - OWSNavigationController *navigationController = [[OWSNavigationController alloc] initWithRootViewController:rootViewController]; - navigationController.navigationBarHidden = YES; - UIApplication.sharedApplication.keyWindow.rootViewController = navigationController; - }]]; - [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { /* Do nothing */ }]]; - [self presentAlert:alert]; + LKNukeDataModal *nukeDataModal = [LKNukeDataModal new]; + nukeDataModal.modalPresentationStyle = UIModalPresentationOverFullScreen; + [self presentViewController:nukeDataModal animated:YES completion:nil]; } - (void)reregisterUser