From b1c594d23d9038ef87f93882d2ac3a29d2350025 Mon Sep 17 00:00:00 2001 From: Bruno Muniz <bruno@elixxir.io> Date: Fri, 22 Jul 2022 19:17:35 +0000 Subject: [PATCH] Revert "Merge branch 'fix/mr-50' into 'master'" This reverts merge request !55 --- Sources/Integration/Client.swift | 2 + Sources/Integration/Session/Session.swift | 2 + Sources/ScanFeature/Views/ScanView.swift | 4 +- .../ViewModels/SearchLeftViewModel.swift | 14 +-- .../SearchFeature/Views/SearchRightView.swift | 118 ++++++------------ Sources/Shared/AutoGenerated/Strings.swift | 10 +- .../Resources/en.lproj/Localizable.strings | 6 +- 7 files changed, 51 insertions(+), 105 deletions(-) diff --git a/Sources/Integration/Client.swift b/Sources/Integration/Client.swift index 8fc201af..450c674e 100644 --- a/Sources/Integration/Client.swift +++ b/Sources/Integration/Client.swift @@ -93,6 +93,8 @@ public class Client { fatalError("Trying to add json parameters to backup but no backup manager created yet") } + print("^^^ Set params: \(string) to backup") + backupManager.addJson(string) } diff --git a/Sources/Integration/Session/Session.swift b/Sources/Integration/Session/Session.swift index fee3c76c..f85a6c6f 100644 --- a/Sources/Integration/Session/Session.swift +++ b/Sources/Integration/Session/Session.swift @@ -140,6 +140,8 @@ public final class Session: SessionType { } } + print("^^^ \(report.parameters)") + guard username!.isEmpty == false else { fatalError("Trying to restore an account that has no username") } diff --git a/Sources/ScanFeature/Views/ScanView.swift b/Sources/ScanFeature/Views/ScanView.swift index 540f68f5..7aff4cf2 100644 --- a/Sources/ScanFeature/Views/ScanView.swift +++ b/Sources/ScanFeature/Views/ScanView.swift @@ -80,12 +80,12 @@ final class ScanView: UIView { actionButton.isHidden = false case .alreadyFriends(let name): - text = Localized.Scan.Error.alreadyFriends(name) + text = Localized.Scan.Error.friends(name) actionButton.setTitle(Localized.Scan.contact, for: .normal) actionButton.isHidden = false case .cameraPermission: - text = Localized.Scan.Error.cameraPermissionNeeded + text = Localized.Scan.Error.denied actionButton.setTitle(Localized.Scan.settings, for: .normal) actionButton.isHidden = false diff --git a/Sources/SearchFeature/ViewModels/SearchLeftViewModel.swift b/Sources/SearchFeature/ViewModels/SearchLeftViewModel.swift index 6c0a8390..30f77b19 100644 --- a/Sources/SearchFeature/ViewModels/SearchLeftViewModel.swift +++ b/Sources/SearchFeature/ViewModels/SearchLeftViewModel.swift @@ -126,20 +126,12 @@ final class SearchLeftViewModel { let localsQuery = Contact.Query(text: stateSubject.value.input, authStatus: [.friend]) - if let locals = try? session.dbManager.fetchContacts(localsQuery), - let localsWithoutMe = removeMyself(from: locals), - localsWithoutMe.isEmpty == false { + if let locals = try? session.dbManager.fetchContacts(localsQuery), locals.count > 0 { + let localsWithoutMe = locals.filter { $0.id != session.myId } snapshot.appendSections([.connections]) - snapshot.appendItems( - localsWithoutMe.map(SearchItem.connection), - toSection: .connections - ) + snapshot.appendItems(localsWithoutMe.map(SearchItem.connection), toSection: .connections) } stateSubject.value.snapshot = snapshot } - - private func removeMyself(from collection: [Contact]) -> [Contact]? { - collection.filter { $0.id != session.myId } - } } diff --git a/Sources/SearchFeature/Views/SearchRightView.swift b/Sources/SearchFeature/Views/SearchRightView.swift index c2fd7476..36380875 100644 --- a/Sources/SearchFeature/Views/SearchRightView.swift +++ b/Sources/SearchFeature/Views/SearchRightView.swift @@ -39,39 +39,51 @@ final class SearchRightView: UIView { required init?(coder: NSCoder) { nil } func update(status: ScanningStatus) { - setupTitle(for: status) - setupImageView(for: status) - setupActionButton(for: status) - setupCornerColors(for: status) - setupAnimationView(for: status) - } - - private func setupTitle(for status: ScanningStatus) { - let title: String + var text: String switch status { + case .reading, .processing: + imageView.isHidden = true + actionButton.isHidden = true + text = Localized.Scan.Status.reading + overlayView.updateCornerColor(Asset.brandPrimary.color) + case .success: - title = Localized.Scan.Status.success - case .reading: - title = Localized.Scan.Status.reading - case .processing: - title = Localized.Scan.Status.processing - - case .failed(let scanningError): - switch scanningError { - case .unknown(let content): - title = content + animationView.isHidden = true + actionButton.isHidden = true + imageView.isHidden = false + imageView.image = Asset.sharedSuccess.image + text = Localized.Scan.Status.success + overlayView.updateCornerColor(Asset.accentSuccess.color) + + case .failed(let error): + animationView.isHidden = true + imageView.image = Asset.scanError.image + imageView.isHidden = false + overlayView.updateCornerColor(Asset.accentDanger.color) + switch error { case .requestOpened: - title = Localized.Scan.Error.requested + text = Localized.Scan.Error.requested + actionButton.setTitle(Localized.Scan.requests, for: .normal) + actionButton.isHidden = false + case .alreadyFriends(let name): - title = Localized.Scan.Error.alreadyFriends(name) + text = Localized.Scan.Error.friends(name) + actionButton.setTitle(Localized.Scan.contact, for: .normal) + actionButton.isHidden = false + case .cameraPermission: - title = Localized.Scan.Error.cameraPermissionNeeded + text = Localized.Scan.Error.denied + actionButton.setTitle(Localized.Scan.settings, for: .normal) + actionButton.isHidden = false + + case .unknown(let content): + text = content } } - let attString = NSMutableAttributedString(string: title) + let attString = NSMutableAttributedString(string: text) let paragraph = NSMutableParagraphStyle() paragraph.alignment = .center paragraph.lineHeightMultiple = 1.35 @@ -80,71 +92,13 @@ final class SearchRightView: UIView { attString.addAttribute(.foregroundColor, value: Asset.neutralWhite.color) attString.addAttribute(.font, value: Fonts.Mulish.regular.font(size: 14.0) as Any) - if title.contains("#") { + if text.contains("#") { attString.addAttribute(name: .foregroundColor, value: Asset.brandPrimary.color, betweenCharacters: "#") } statusLabel.attributedText = attString } - private func setupImageView(for status: ScanningStatus) { - let image: UIImage? - - switch status { - case .reading, .processing: - image = nil - case .success: - image = Asset.sharedSuccess.image - case .failed(_): - image = Asset.scanError.image - } - - imageView.image = image - imageView.isHidden = image == nil - } - - private func setupActionButton(for status: ScanningStatus) { - let buttonTitle: String? - - switch status { - case .failed(.requestOpened): - buttonTitle = Localized.Scan.requests - case .failed(.alreadyFriends(_)): - buttonTitle = Localized.Scan.contact - case .failed(.cameraPermission): - buttonTitle = Localized.Scan.settings - case .reading, .processing, .success, .failed(.unknown(_)): - buttonTitle = nil - } - - actionButton.setTitle(buttonTitle, for: .normal) - actionButton.isHidden = buttonTitle == nil - } - - private func setupCornerColors(for status: ScanningStatus) { - let color: UIColor - - switch status { - case .reading, .processing: - color = Asset.brandPrimary.color - case .success: - color = Asset.accentSuccess.color - case .failed(_): - color = Asset.accentDanger.color - } - - overlayView.updateCornerColor(color) - } - - private func setupAnimationView(for status: ScanningStatus) { - switch status { - case .reading, .processing: - animationView.isHidden = false - case .success, .failed(_): - animationView.isHidden = true - } - } - private func setupConstraints() { overlayView.snp.makeConstraints { $0.top.equalToSuperview() diff --git a/Sources/Shared/AutoGenerated/Strings.swift b/Sources/Shared/AutoGenerated/Strings.swift index 315babf8..ed861800 100644 --- a/Sources/Shared/AutoGenerated/Strings.swift +++ b/Sources/Shared/AutoGenerated/Strings.swift @@ -1010,13 +1010,13 @@ public enum Localized { } } public enum Error { + /// Camera needs permission to be used + public static let denied = Localized.tr("Localizable", "scan.error.denied") /// You've already added /// #%@# - public static func alreadyFriends(_ p1: Any) -> String { - return Localized.tr("Localizable", "scan.error.alreadyFriends", String(describing: p1)) + public static func friends(_ p1: Any) -> String { + return Localized.tr("Localizable", "scan.error.friends", String(describing: p1)) } - /// Camera needs permission to be used - public static let cameraPermissionNeeded = Localized.tr("Localizable", "scan.error.cameraPermissionNeeded") /// Something’s gone wrong. Please try again. public static let general = Localized.tr("Localizable", "scan.error.general") /// Invalid QR code @@ -1039,8 +1039,6 @@ public enum Localized { public static let `right` = Localized.tr("Localizable", "scan.segmentedControl.right") } public enum Status { - /// Processing... - public static let processing = Localized.tr("Localizable", "scan.status.processing") /// Place QR code inside frame to scan public static let reading = Localized.tr("Localizable", "scan.status.reading") /// Success diff --git a/Sources/Shared/Resources/en.lproj/Localizable.strings b/Sources/Shared/Resources/en.lproj/Localizable.strings index 2b726391..dd95d400 100644 --- a/Sources/Shared/Resources/en.lproj/Localizable.strings +++ b/Sources/Shared/Resources/en.lproj/Localizable.strings @@ -172,8 +172,6 @@ "scan.status.reading" = "Place QR code inside frame to scan"; -"scan.status.processing" -= "Processing..."; "scan.status.success" = "Success"; "scan.display.copied" @@ -199,7 +197,7 @@ = "Scan Code"; "scan.segmentedControl.right" = "My Code"; -"scan.error.cameraPermissionNeeded" +"scan.error.denied" = "Camera needs permission to be used"; "scan.error.invalid" = "Invalid QR code"; @@ -207,7 +205,7 @@ = "Something’s gone wrong. Please try again."; "scan.error.requested" = "You already have a request open with this contact."; -"scan.error.alreadyFriends" +"scan.error.friends" = "You've already added \n#%@#"; "scan.error.pending" = "This user is already pending in your contact list"; -- GitLab