LNMineFunctionView.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // LNMineFunctionView.swift
  3. // Lanu
  4. //
  5. // Created by OneeChan on 2025/12/19.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNMineFunctionView: UIView {
  11. private let stackView = UIStackView()
  12. private var joinView: UIView?
  13. override init(frame: CGRect) {
  14. super.init(frame: frame)
  15. setupViews()
  16. LNEventDeliver.addObserver(self)
  17. onUserInfoChanged(userInfo: myUserInfo)
  18. }
  19. required init?(coder: NSCoder) {
  20. fatalError("init(coder:) has not been implemented")
  21. }
  22. }
  23. extension LNMineFunctionView: LNProfileManagerNotify {
  24. func onUserInfoChanged(userInfo: LNUserProfileVO) {
  25. guard userInfo.userNo.isMyUid else { return }
  26. joinView?.isHidden = userInfo.playmate
  27. if !userInfo.playmate {
  28. stackView.distribution = .equalCentering
  29. } else {
  30. stackView.distribution = .fillEqually
  31. }
  32. }
  33. }
  34. extension LNMineFunctionView {
  35. private func setupViews() {
  36. layer.cornerRadius = 12
  37. backgroundColor = .fill
  38. let titleLabel = UILabel()
  39. titleLabel.font = .heading_h3
  40. titleLabel.textColor = .text_5
  41. titleLabel.text = .init(key: "A00207")
  42. addSubview(titleLabel)
  43. titleLabel.snp.makeConstraints { make in
  44. make.leading.equalToSuperview().offset(16)
  45. make.top.equalToSuperview().offset(12)
  46. }
  47. stackView.axis = .horizontal
  48. stackView.distribution = .equalCentering
  49. stackView.alignment = .top
  50. addSubview(stackView)
  51. stackView.snp.makeConstraints { make in
  52. make.horizontalEdges.equalToSuperview().inset(16)
  53. make.top.equalTo(titleLabel.snp.bottom).offset(22)
  54. make.bottom.equalToSuperview().offset(-16)
  55. }
  56. let order = buildFunctionItemView(icon: .icProfileOrder, title: .init(key: "A00208"))
  57. order.onTap { [weak self] in
  58. guard let self else { return }
  59. pushToOrderList()
  60. }
  61. stackView.addArrangedSubview(order)
  62. let joinUs = buildFunctionItemView(icon: .icProfileJoinUs, title: .init(key: "B00063"))
  63. joinUs.onTap { [weak self] in
  64. guard let self else { return }
  65. showLoading()
  66. LNGameMateManager.shared.getJoinGameMateInfo { [weak self] res in
  67. dismissLoading()
  68. guard let self else { return }
  69. guard let res else { return }
  70. if res.step3Complete || res.underReview {
  71. pushToJoinUsReview(true)
  72. return
  73. }
  74. let config = LNJumpWebViewConfig(url: .joinUsUrl)
  75. pushToWebView(config)
  76. }
  77. }
  78. stackView.addArrangedSubview(joinUs)
  79. joinView = joinUs
  80. let help = buildFunctionItemView(icon: .icProfileHelp, title: .init(key: "A00210"))
  81. help.onTap { [weak self] in
  82. guard let self else { return }
  83. pushToHelpCenter()
  84. }
  85. stackView.addArrangedSubview(help)
  86. let settings = buildFunctionItemView(icon: .icProfileSettings, title: .init(key: "A00211"))
  87. settings.onTap { [weak self] in
  88. guard let self else { return }
  89. pushToSettings()
  90. }
  91. stackView.addArrangedSubview(settings)
  92. }
  93. private func buildFunctionItemView(icon: UIImage, title: String) -> UIView {
  94. let container = UIView()
  95. let imageView = UIImageView()
  96. imageView.isUserInteractionEnabled = false
  97. imageView.image = icon
  98. container.addSubview(imageView)
  99. imageView.snp.makeConstraints { make in
  100. make.centerX.equalToSuperview()
  101. make.top.equalToSuperview()
  102. }
  103. let titleLabel = UILabel()
  104. titleLabel.text = title
  105. titleLabel.font = .body_s
  106. titleLabel.textColor = .text_4
  107. titleLabel.textAlignment = .center
  108. titleLabel.numberOfLines = 0
  109. container.addSubview(titleLabel)
  110. titleLabel.snp.makeConstraints { make in
  111. make.horizontalEdges.equalToSuperview()
  112. make.top.equalTo(imageView.snp.bottom).offset(8)
  113. make.bottom.equalToSuperview()
  114. }
  115. return container
  116. }
  117. }