Skip to content
Snippets Groups Projects
Commit b1c594d2 authored by Bruno Muniz's avatar Bruno Muniz :apple:
Browse files

Revert "Merge branch 'fix/mr-50' into 'master'"

This reverts merge request !55
parent 3bcc5b37
No related branches found
No related tags found
1 merge request!56Revert "Merge branch 'fix/mr-50' into 'master'"
...@@ -93,6 +93,8 @@ public class Client { ...@@ -93,6 +93,8 @@ public class Client {
fatalError("Trying to add json parameters to backup but no backup manager created yet") fatalError("Trying to add json parameters to backup but no backup manager created yet")
} }
print("^^^ Set params: \(string) to backup")
backupManager.addJson(string) backupManager.addJson(string)
} }
......
...@@ -140,6 +140,8 @@ public final class Session: SessionType { ...@@ -140,6 +140,8 @@ public final class Session: SessionType {
} }
} }
print("^^^ \(report.parameters)")
guard username!.isEmpty == false else { guard username!.isEmpty == false else {
fatalError("Trying to restore an account that has no username") fatalError("Trying to restore an account that has no username")
} }
......
...@@ -80,12 +80,12 @@ final class ScanView: UIView { ...@@ -80,12 +80,12 @@ final class ScanView: UIView {
actionButton.isHidden = false actionButton.isHidden = false
case .alreadyFriends(let name): case .alreadyFriends(let name):
text = Localized.Scan.Error.alreadyFriends(name) text = Localized.Scan.Error.friends(name)
actionButton.setTitle(Localized.Scan.contact, for: .normal) actionButton.setTitle(Localized.Scan.contact, for: .normal)
actionButton.isHidden = false actionButton.isHidden = false
case .cameraPermission: case .cameraPermission:
text = Localized.Scan.Error.cameraPermissionNeeded text = Localized.Scan.Error.denied
actionButton.setTitle(Localized.Scan.settings, for: .normal) actionButton.setTitle(Localized.Scan.settings, for: .normal)
actionButton.isHidden = false actionButton.isHidden = false
......
...@@ -126,20 +126,12 @@ final class SearchLeftViewModel { ...@@ -126,20 +126,12 @@ final class SearchLeftViewModel {
let localsQuery = Contact.Query(text: stateSubject.value.input, authStatus: [.friend]) let localsQuery = Contact.Query(text: stateSubject.value.input, authStatus: [.friend])
if let locals = try? session.dbManager.fetchContacts(localsQuery), if let locals = try? session.dbManager.fetchContacts(localsQuery), locals.count > 0 {
let localsWithoutMe = removeMyself(from: locals), let localsWithoutMe = locals.filter { $0.id != session.myId }
localsWithoutMe.isEmpty == false {
snapshot.appendSections([.connections]) snapshot.appendSections([.connections])
snapshot.appendItems( snapshot.appendItems(localsWithoutMe.map(SearchItem.connection), toSection: .connections)
localsWithoutMe.map(SearchItem.connection),
toSection: .connections
)
} }
stateSubject.value.snapshot = snapshot stateSubject.value.snapshot = snapshot
} }
private func removeMyself(from collection: [Contact]) -> [Contact]? {
collection.filter { $0.id != session.myId }
}
} }
...@@ -39,39 +39,51 @@ final class SearchRightView: UIView { ...@@ -39,39 +39,51 @@ final class SearchRightView: UIView {
required init?(coder: NSCoder) { nil } required init?(coder: NSCoder) { nil }
func update(status: ScanningStatus) { func update(status: ScanningStatus) {
setupTitle(for: status) var text: String
setupImageView(for: status)
setupActionButton(for: status)
setupCornerColors(for: status)
setupAnimationView(for: status)
}
private func setupTitle(for status: ScanningStatus) {
let title: String
switch status { switch status {
case .reading, .processing:
imageView.isHidden = true
actionButton.isHidden = true
text = Localized.Scan.Status.reading
overlayView.updateCornerColor(Asset.brandPrimary.color)
case .success: case .success:
title = Localized.Scan.Status.success animationView.isHidden = true
case .reading: actionButton.isHidden = true
title = Localized.Scan.Status.reading imageView.isHidden = false
case .processing: imageView.image = Asset.sharedSuccess.image
title = Localized.Scan.Status.processing text = Localized.Scan.Status.success
overlayView.updateCornerColor(Asset.accentSuccess.color)
case .failed(let scanningError):
switch scanningError { case .failed(let error):
case .unknown(let content): animationView.isHidden = true
title = content imageView.image = Asset.scanError.image
imageView.isHidden = false
overlayView.updateCornerColor(Asset.accentDanger.color)
switch error {
case .requestOpened: 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): 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: 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() let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .center paragraph.alignment = .center
paragraph.lineHeightMultiple = 1.35 paragraph.lineHeightMultiple = 1.35
...@@ -80,71 +92,13 @@ final class SearchRightView: UIView { ...@@ -80,71 +92,13 @@ final class SearchRightView: UIView {
attString.addAttribute(.foregroundColor, value: Asset.neutralWhite.color) attString.addAttribute(.foregroundColor, value: Asset.neutralWhite.color)
attString.addAttribute(.font, value: Fonts.Mulish.regular.font(size: 14.0) as Any) 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: "#") attString.addAttribute(name: .foregroundColor, value: Asset.brandPrimary.color, betweenCharacters: "#")
} }
statusLabel.attributedText = attString 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() { private func setupConstraints() {
overlayView.snp.makeConstraints { overlayView.snp.makeConstraints {
$0.top.equalToSuperview() $0.top.equalToSuperview()
......
...@@ -1010,13 +1010,13 @@ public enum Localized { ...@@ -1010,13 +1010,13 @@ public enum Localized {
} }
} }
public enum Error { public enum Error {
/// Camera needs permission to be used
public static let denied = Localized.tr("Localizable", "scan.error.denied")
/// You've already added /// You've already added
/// #%@# /// #%@#
public static func alreadyFriends(_ p1: Any) -> String { public static func friends(_ p1: Any) -> String {
return Localized.tr("Localizable", "scan.error.alreadyFriends", String(describing: p1)) 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. /// Something’s gone wrong. Please try again.
public static let general = Localized.tr("Localizable", "scan.error.general") public static let general = Localized.tr("Localizable", "scan.error.general")
/// Invalid QR code /// Invalid QR code
...@@ -1039,8 +1039,6 @@ public enum Localized { ...@@ -1039,8 +1039,6 @@ public enum Localized {
public static let `right` = Localized.tr("Localizable", "scan.segmentedControl.right") public static let `right` = Localized.tr("Localizable", "scan.segmentedControl.right")
} }
public enum Status { public enum Status {
/// Processing...
public static let processing = Localized.tr("Localizable", "scan.status.processing")
/// Place QR code inside frame to scan /// Place QR code inside frame to scan
public static let reading = Localized.tr("Localizable", "scan.status.reading") public static let reading = Localized.tr("Localizable", "scan.status.reading")
/// Success /// Success
......
...@@ -172,8 +172,6 @@ ...@@ -172,8 +172,6 @@
"scan.status.reading" "scan.status.reading"
= "Place QR code inside frame to scan"; = "Place QR code inside frame to scan";
"scan.status.processing"
= "Processing...";
"scan.status.success" "scan.status.success"
= "Success"; = "Success";
"scan.display.copied" "scan.display.copied"
...@@ -199,7 +197,7 @@ ...@@ -199,7 +197,7 @@
= "Scan Code"; = "Scan Code";
"scan.segmentedControl.right" "scan.segmentedControl.right"
= "My Code"; = "My Code";
"scan.error.cameraPermissionNeeded" "scan.error.denied"
= "Camera needs permission to be used"; = "Camera needs permission to be used";
"scan.error.invalid" "scan.error.invalid"
= "Invalid QR code"; = "Invalid QR code";
...@@ -207,7 +205,7 @@ ...@@ -207,7 +205,7 @@
= "Something’s gone wrong. Please try again."; = "Something’s gone wrong. Please try again.";
"scan.error.requested" "scan.error.requested"
= "You already have a request open with this contact."; = "You already have a request open with this contact.";
"scan.error.alreadyFriends" "scan.error.friends"
= "You've already added \n#%@#"; = "You've already added \n#%@#";
"scan.error.pending" "scan.error.pending"
= "This user is already pending in your contact list"; = "This user is already pending in your contact list";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment