QrViewController.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import Foundation
  2. import UIKit
  3. import DcCore
  4. class QrViewController: UIViewController {
  5. private let dcContext: DcContext
  6. private var contact: DcContact? {
  7. // This is nil if we do not have an account setup yet
  8. if !dcContext.isConfigured() {
  9. return nil
  10. }
  11. return DcContact(id: Int(DC_CONTACT_ID_SELF))
  12. }
  13. init(dcContext: DcContext) {
  14. self.dcContext = dcContext
  15. super.init(nibName: nil, bundle: nil)
  16. }
  17. required init?(coder _: NSCoder) {
  18. fatalError("init(coder:) has not been implemented")
  19. }
  20. override func viewDidLoad() {
  21. super.viewDidLoad()
  22. title = String.localized("qr_code")
  23. }
  24. private func displayNewChat(contactId: Int) {
  25. let chatId = dcContext.createChatByContactId(contactId: contactId)
  26. let chatVC = ChatViewController(dcContext: dcContext, chatId: Int(chatId))
  27. chatVC.hidesBottomBarWhenPushed = true
  28. navigationController?.pushViewController(chatVC, animated: true)
  29. }
  30. }
  31. class QrViewContentView: UIView {
  32. }
  33. /*
  34. private func createQRCodeCell() -> UITableViewCell {
  35. let cell = UITableViewCell(style: .default, reuseIdentifier: "qrCodeCell")
  36. let qrCode = createQRCodeView()
  37. let infolabel = createInfoLabel()
  38. cell.contentView.addSubview(qrCode)
  39. cell.contentView.addSubview(infolabel)
  40. cell.selectionStyle = .none
  41. let qrCodeConstraints = [qrCode.constraintAlignTopTo(cell.contentView, paddingTop: 25),
  42. qrCode.constraintCenterXTo(cell.contentView)]
  43. let infoLabelConstraints = [infolabel.constraintToBottomOf(qrCode, paddingTop: 25),
  44. infolabel.constraintAlignLeadingTo(cell.contentView, paddingLeading: 8),
  45. infolabel.constraintAlignTrailingTo(cell.contentView, paddingTrailing: 8)]
  46. cell.contentView.addConstraints(qrCodeConstraints)
  47. cell.contentView.addConstraints(infoLabelConstraints)
  48. return cell
  49. }
  50. private func createInfoLabel() -> UIView {
  51. let label = UILabel.init()
  52. label.translatesAutoresizingMaskIntoConstraints = false
  53. if let contact = contact {
  54. label.text = String.localizedStringWithFormat(String.localized("qrshow_join_contact_hint"), contact.email)
  55. }
  56. label.lineBreakMode = .byWordWrapping
  57. label.numberOfLines = 0
  58. label.textAlignment = .center
  59. label.font = UIFont.systemFont(ofSize: 14)
  60. return label
  61. }
  62. private func createQRCodeView() -> UIView {
  63. let width: CGFloat = 230
  64. let frame = CGRect(origin: .zero, size: .init(width: width, height: width))
  65. let imageView = QRCodeView(frame: frame)
  66. if let qrCode = dcContext.getSecurejoinQr(chatId: 0) {
  67. imageView.generateCode(
  68. qrCode,
  69. foregroundColor: .darkText,
  70. backgroundColor: .white
  71. )
  72. }
  73. imageView.translatesAutoresizingMaskIntoConstraints = false
  74. imageView.widthAnchor.constraint(equalToConstant: width).isActive = true
  75. imageView.heightAnchor.constraint(equalToConstant: width).isActive = true
  76. return imageView
  77. }
  78. */