LNSettingsViewController.swift 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // LNSettingsViewController.swift
  3. // Lanu
  4. //
  5. // Created by OneeChan on 2025/12/22.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. extension UIView {
  11. func pushToSettings() {
  12. let vc = LNSettingsViewController()
  13. navigationController?.pushViewController(vc, animated: true)
  14. }
  15. }
  16. class LNSettingsViewController: LNViewController {
  17. private let curLanguageLabel = UILabel()
  18. override func viewDidLoad() {
  19. super.viewDidLoad()
  20. setupViews()
  21. }
  22. }
  23. extension LNSettingsViewController {
  24. private func setupViews() {
  25. title = .init(key: "A00211")
  26. view.backgroundColor = .primary_1
  27. let functionView = UIView()
  28. functionView.backgroundColor = .fill
  29. functionView.layer.cornerRadius = 12
  30. view.addSubview(functionView)
  31. functionView.snp.makeConstraints { make in
  32. make.directionalHorizontalEdges.equalToSuperview().inset(16)
  33. make.top.equalToSuperview().offset(22)
  34. }
  35. let stackView = UIStackView()
  36. stackView.axis = .vertical
  37. stackView.spacing = 26
  38. functionView.addSubview(stackView)
  39. stackView.snp.makeConstraints { make in
  40. make.directionalEdges.equalToSuperview().inset(16)
  41. }
  42. let language = buildFunctionItem(icName: "ic_language_18", title: .init(key: "A00256"), infoView: curLanguageLabel)
  43. curLanguageLabel.font = .body_s
  44. curLanguageLabel.textColor = .text_5
  45. curLanguageLabel.text = LNAppConfig.shared.curLang.text
  46. language.onTap {
  47. let panel = LNLanguageSettingPanel()
  48. panel.showIn()
  49. }
  50. stackView.addArrangedSubview(language)
  51. let cleanCache = buildFunctionItem(icName: "ic_clean_cache", title: .init(key: "A00257"), infoView: nil)
  52. cleanCache.onTap {
  53. showToast(.init(key: "A00258"))
  54. }
  55. stackView.addArrangedSubview(cleanCache)
  56. let newVersionTag = LNNewVersionView()
  57. newVersionTag.isHidden = !LNAppConfig.shared.hasNewVersion
  58. let about = buildFunctionItem(icName: "ic_about", title: .init(key: "A00247"), infoView: newVersionTag)
  59. about.onTap { [weak self] in
  60. guard let self else { return }
  61. view.pushToAbout()
  62. }
  63. stackView.addArrangedSubview(about)
  64. let delete = buildFunctionItem(icName: "ic_delete", title: .init(key: "A00259"), infoView: nil)
  65. delete.onTap { [weak self] in
  66. guard let self else { return }
  67. view.pushToWebView(.init(url: .deleteAccountUrl))
  68. }
  69. stackView.addArrangedSubview(delete)
  70. let logoutView = UIView()
  71. logoutView.backgroundColor = .fill
  72. logoutView.layer.cornerRadius = 12
  73. view.addSubview(logoutView)
  74. logoutView.snp.makeConstraints { make in
  75. make.directionalHorizontalEdges.equalToSuperview().inset(16)
  76. make.top.equalTo(functionView.snp.bottom).offset(10)
  77. }
  78. let logout = buildFunctionItem(icName: "ic_logout", title: .init(key: "A00260"), infoView: nil)
  79. logout.onTap {
  80. LNCommonAlertView.showLogoutAlert()
  81. }
  82. logoutView.addSubview(logout)
  83. logout.snp.makeConstraints { make in
  84. make.directionalEdges.equalToSuperview().inset(16)
  85. }
  86. }
  87. private func buildFunctionItem(icName: String, title: String, infoView: UIView?) -> UIView {
  88. let container = UIView()
  89. let ic = UIImageView()
  90. ic.image = .init(named: icName)?.withRenderingMode(.alwaysTemplate)
  91. ic.tintColor = .text_4
  92. container.addSubview(ic)
  93. ic.snp.makeConstraints { make in
  94. make.leading.equalToSuperview()
  95. make.centerY.equalToSuperview()
  96. make.width.height.equalTo(18)
  97. }
  98. let arrow = UIImageView.arrowImageView(size: 14)
  99. arrow.tintColor = .text_4
  100. container.addSubview(arrow)
  101. arrow.snp.makeConstraints { make in
  102. make.centerY.equalToSuperview()
  103. make.trailing.equalToSuperview()
  104. }
  105. if let infoView {
  106. container.addSubview(infoView)
  107. infoView.snp.makeConstraints { make in
  108. make.centerY.equalToSuperview()
  109. make.trailing.equalTo(arrow.snp.leading).offset(-2)
  110. }
  111. }
  112. let titleLabel = UILabel()
  113. titleLabel.font = .body_m
  114. titleLabel.textColor = .text_5
  115. titleLabel.text = title
  116. container.addSubview(titleLabel)
  117. titleLabel.snp.makeConstraints { make in
  118. make.leading.equalTo(ic.snp.trailing).offset(2)
  119. make.verticalEdges.equalToSuperview()
  120. make.trailing.lessThanOrEqualTo((infoView ?? arrow).snp.leading)
  121. }
  122. return container
  123. }
  124. }