From eb5adfbd0f4931bd224d0f0fd16ad96b3a4f239b Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 29 May 2024 16:34:58 +0200 Subject: [PATCH] remove dead code --- deltachat-ios.xcodeproj/project.pbxproj | 4 - .../ProfileInfoViewController.swift | 158 ------------------ .../AccountSetup/WelcomeViewController.swift | 96 +---------- 3 files changed, 1 insertion(+), 257 deletions(-) delete mode 100644 deltachat-ios/Controller/AccountSetup/ProfileInfoViewController.swift diff --git a/deltachat-ios.xcodeproj/project.pbxproj b/deltachat-ios.xcodeproj/project.pbxproj index d5fd4b1a5..82bb84383 100644 --- a/deltachat-ios.xcodeproj/project.pbxproj +++ b/deltachat-ios.xcodeproj/project.pbxproj @@ -177,7 +177,6 @@ AE8F503524753DFE007FEE0B /* GalleryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8F503424753DFE007FEE0B /* GalleryViewController.swift */; }; AE9DAF0D22C1215D004C9591 /* EditContactController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE9DAF0C22C1215D004C9591 /* EditContactController.swift */; }; AE9DAF0F22C278C6004C9591 /* ChatTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE9DAF0E22C278C6004C9591 /* ChatTitleView.swift */; }; - AEA0F6A124474146009F887B /* ProfileInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEA0F6A024474146009F887B /* ProfileInfoViewController.swift */; }; AEACE2E31FB32B5C00DCDD78 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2E21FB32B5C00DCDD78 /* Constants.swift */; }; AEACE2E51FB32E1900DCDD78 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2E41FB32E1900DCDD78 /* Utils.swift */; }; AEC67A1C241CE9E4007DDBE1 /* AppStateRestorer.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC67A1B241CE9E4007DDBE1 /* AppStateRestorer.swift */; }; @@ -478,7 +477,6 @@ AE8F503424753DFE007FEE0B /* GalleryViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryViewController.swift; sourceTree = ""; }; AE9DAF0C22C1215D004C9591 /* EditContactController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditContactController.swift; sourceTree = ""; }; AE9DAF0E22C278C6004C9591 /* ChatTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatTitleView.swift; sourceTree = ""; }; - AEA0F6A024474146009F887B /* ProfileInfoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileInfoViewController.swift; sourceTree = ""; }; AEACE2E21FB32B5C00DCDD78 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; AEACE2E41FB32E1900DCDD78 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; AEC67A1B241CE9E4007DDBE1 /* AppStateRestorer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStateRestorer.swift; sourceTree = ""; }; @@ -909,7 +907,6 @@ AEE56D752253431E007DC082 /* AccountSetupController.swift */, 30C0D49C237C4908008E2A0E /* CertificateCheckController.swift */, AE18F293228C602A0007B1BE /* SecuritySettingsController.swift */, - AEA0F6A024474146009F887B /* ProfileInfoViewController.swift */, ); path = AccountSetup; sourceTree = ""; @@ -1612,7 +1609,6 @@ AE76E5EE242BF2EA003CF461 /* WelcomeViewController.swift in Sources */, 3052C60A253F082E007D13EA /* MessageLabelDelegate.swift in Sources */, AE0AA9562478191900D42A7F /* GridCollectionViewFlowLayout.swift in Sources */, - AEA0F6A124474146009F887B /* ProfileInfoViewController.swift in Sources */, 303492A5257546B400A523D0 /* DraftPreview.swift in Sources */, 305961D02346125100C80F33 /* NSAttributedString+Extensions.swift in Sources */, 21D6C941260623F500D0755A /* NotificationManager.swift in Sources */, diff --git a/deltachat-ios/Controller/AccountSetup/ProfileInfoViewController.swift b/deltachat-ios/Controller/AccountSetup/ProfileInfoViewController.swift deleted file mode 100644 index b5e734bfa..000000000 --- a/deltachat-ios/Controller/AccountSetup/ProfileInfoViewController.swift +++ /dev/null @@ -1,158 +0,0 @@ -import UIKit -import DcCore - -class ProfileInfoViewController: UITableViewController { - var onClose: VoidFunction? - private let dcContext: DcContext - private var displayName: String? - - private lazy var mediaPicker: MediaPicker? = { - let mediaPicker = MediaPicker(dcContext: dcContext, navigationController: navigationController) - mediaPicker.delegate = self - return mediaPicker - }() - - private lazy var doneButtonItem: UIBarButtonItem = { - let button = UIBarButtonItem( - title: String.localized("done"), - style: .done, - target: self, - action: #selector(doneButtonPressed(_:)) - ) - button.isEnabled = false - return button - }() - - private lazy var avatarCell: AvatarSelectionCell = { - let cell = AvatarSelectionCell(image: dcContext.getSelfAvatarImage()) - cell.onAvatarTapped = avatarTapped - return cell - }() - - private lazy var nameCell: TextFieldCell = { - let cell = TextFieldCell.makeNameCell(delegate: self) - cell.placeholder = String.localized("pref_your_name") - cell.setText(text: dcContext.displayname) - cell.onTextFieldChange = {[weak self] textField in - guard let self else { return } - self.displayName = textField.text - self.doneButtonItem.isEnabled = !(self.displayName?.isEmpty ?? true) - } - cell.textField.returnKeyType = .default - return cell - }() - - private lazy var cells = [nameCell, avatarCell] - - init(context: DcContext) { - self.dcContext = context - super.init(style: .grouped) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - // MARK: - lifecycle - override func viewDidLoad() { - super.viewDidLoad() - title = String.localized("pref_profile_info_headline") - navigationItem.rightBarButtonItem = doneButtonItem - tableView.rowHeight = UITableView.automaticDimension - } - - // MARK: - tableviewDelegate - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return cells.count - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - return cells[indexPath.row] - } - - override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { - return String.localized("set_name_and_avatar_explain") - } - - // MARK: - updates - private func updateAvatarCell() { - let avatarImage = dcContext.getSelfAvatarImage() - avatarCell.setAvatar(image: avatarImage) - } - - // MARK: - actions - private func avatarTapped() { - let sender = avatarCell.badge - let alert = UIAlertController( - title: String.localized("pref_profile_photo"), - message: nil, - preferredStyle: .actionSheet - ) - let galleryAction = PhotoPickerAlertAction( - title: String.localized("gallery"), - style: .default, - handler: galleryButtonPressed(_:) - ) - let cameraAction = PhotoPickerAlertAction( - title: String.localized("camera"), - style: .default, - handler: cameraButtonPressed(_:) - ) - alert.addAction(cameraAction) - alert.addAction(galleryAction) - - if dcContext.getSelfAvatarImage() != nil { - let deleteAction = UIAlertAction( - title: String.localized("delete"), - style: .destructive, - handler: deleteProfileIconPressed(_:) - ) - alert.addAction(deleteAction) - } - - alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil)) - if let popoverController = alert.popoverPresentationController { - popoverController.sourceView = self.avatarCell - popoverController.sourceRect = CGRect( - x: sender.frame.minX - 10, - y: sender.frame.minY, - width: sender.frame.width, - height: sender.frame.height - ) - } - self.present(alert, animated: true, completion: nil) - } - - @objc private func doneButtonPressed(_ sender: UIBarButtonItem) { - dcContext.displayname = displayName - onClose?() - } - - private func galleryButtonPressed(_ action: UIAlertAction) { - mediaPicker?.showPhotoGallery() - } - - private func cameraButtonPressed(_ action: UIAlertAction) { - mediaPicker?.showCamera(allowCropping: true, supportedMediaTypes: .photo) - } - - private func deleteProfileIconPressed(_ action: UIAlertAction) { - dcContext.selfavatar = nil - updateAvatarCell() - } -} - -extension ProfileInfoViewController: MediaPickerDelegate { - func onImageSelected(image: UIImage) { - AvatarHelper.saveSelfAvatarImage(dcContext: dcContext, image: image) - updateAvatarCell() - } -} - -extension ProfileInfoViewController: UITextFieldDelegate { - - func textFieldShouldReturn(_ textField: UITextField) -> Bool { - textField.resignFirstResponder() - return true - } -} diff --git a/deltachat-ios/Controller/AccountSetup/WelcomeViewController.swift b/deltachat-ios/Controller/AccountSetup/WelcomeViewController.swift index 08914c370..8b8640e25 100644 --- a/deltachat-ios/Controller/AccountSetup/WelcomeViewController.swift +++ b/deltachat-ios/Controller/AccountSetup/WelcomeViewController.swift @@ -7,7 +7,6 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler { private let accountCode: String? private var backupProgressObserver: NSObjectProtocol? var progressObserver: NSObjectProtocol? - var onProgressSuccess: VoidFunction? private var securityScopedResource: NSURL? private lazy var scrollView: UIScrollView = { @@ -59,16 +58,6 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler { self.accountCode = accountCode super.init(nibName: nil, bundle: nil) self.navigationItem.title = String.localized(canCancel ? "add_account" : "welcome_desktop") - onProgressSuccess = { [weak self] in - guard let self else { return } - let profileInfoController = ProfileInfoViewController(context: self.dcContext) - profileInfoController.onClose = { - if let appDelegate = UIApplication.shared.delegate as? AppDelegate { - appDelegate.reloadDcContext() - } - } - self.navigationController?.setViewControllers([profileInfoController], animated: true) - } } required init?(coder: NSCoder) { @@ -149,43 +138,6 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler { navigationController?.pushViewController(qrReader, animated: true) } - private func createAccountFromQRCode(qrCode: String) { - if dcAccounts.getSelected().isConfigured() { - UserDefaults.standard.setValue(dcAccounts.getSelected().id, forKey: Constants.Keys.lastSelectedAccountKey) - _ = dcAccounts.add() - } - let accountId = dcAccounts.getSelected().id - - if accountId != 0 { - dcContext = dcAccounts.get(id: accountId) - addProgressAlertListener(dcAccounts: self.dcAccounts, - progressName: eventConfigureProgress, - onSuccess: self.handleLoginSuccess) - showProgressAlert(title: String.localized("login_header"), dcContext: self.dcContext) - DispatchQueue.global().async { [weak self] in - guard let self else { return } - let success = self.dcContext.setConfigFromQR(qrCode: qrCode) - DispatchQueue.main.async { - if success { - self.dcAccounts.stopIo() - self.dcContext.configure() - } else { - self.updateProgressAlert(error: self.dcContext.lastErrorString, - completion: self.accountCode != nil ? self.cancelAccountCreation : nil) - } - } - } - } - } - - private func handleLoginSuccess() { - guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return } - if !UserDefaults.standard.bool(forKey: "notifications_disabled") { - appDelegate.registerForNotifications() - } - onProgressSuccess?() - } - private func handleBackupRestoreSuccess() { guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return } @@ -286,59 +238,13 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler { extension WelcomeViewController: QrCodeReaderDelegate { func handleQrCode(_ code: String) { let lot = dcContext.checkQR(qrCode: code) - if let domain = lot.text1, lot.state == DC_QR_ACCOUNT { - let title = String.localizedStringWithFormat( - String.localized(dcAccounts.getAll().count > 1 ? "qraccount_ask_create_and_login_another" : "qraccount_ask_create_and_login"), - domain) - confirmQrAccountAlert(title: title, qrCode: code) - } else if let email = lot.text1, lot.state == DC_QR_LOGIN { - let title = String.localizedStringWithFormat( - String.localized(dcAccounts.getAll().count > 1 ? "qrlogin_ask_login_another" : "qrlogin_ask_login"), - email) - confirmQrAccountAlert(title: title, qrCode: code) - } else if lot.state == DC_QR_BACKUP { + if lot.state == DC_QR_BACKUP { confirmSetupNewDevice(qrCode: code) } else { qrErrorAlert() } } - private func confirmQrAccountAlert(title: String, qrCode: String) { - let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert) - - let okAction = UIAlertAction( - title: String.localized("ok"), - style: .default, - handler: { [weak self] _ in - guard let self else { return } - self.dismissQRReader() - self.createAccountFromQRCode(qrCode: qrCode) - } - ) - - let qrCancelAction = UIAlertAction( - title: String.localized("cancel"), - style: .cancel, - handler: { [weak self] _ in - guard let self else { return } - self.dismissQRReader() - // if an injected accountCode exists, the WelcomeViewController was only opened to handle that - // cancelling the action should also dismiss the whole controller - if self.accountCode != nil { - self.cancelAccountCreation() - } - } - ) - - alert.addAction(okAction) - alert.addAction(qrCancelAction) - if qrCodeReader != nil { - qrCodeReader?.present(alert, animated: true) - } else { - self.present(alert, animated: true) - } - } - private func confirmSetupNewDevice(qrCode: String) { triggerLocalNetworkPrivacyAlert() let alert = UIAlertController(title: String.localized("multidevice_receiver_title"),