TSMineVC.swift 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // TSSetingVC.swift
  3. // TSLiveWallpaper
  4. //
  5. // Created by 100Years on 2024/12/20.
  6. //
  7. class TSMineVC: TSBaseVC, UITableViewDataSource, UITableViewDelegate {
  8. lazy var dataArray:[TSBasicSectionModel] = {
  9. var dataArray = [TSBasicSectionModel]()
  10. let sectionModel = TSBasicSectionModel()
  11. dataArray.append(sectionModel)
  12. sectionModel.addSubItemModel(
  13. TSBasicItemModel.createItemModel(
  14. leftTitle: "Rate us".localized,
  15. rightViewStyle: 0,
  16. rightString: "",
  17. rightIsHave: true,
  18. height: 80,
  19. rectCorner:.allCorners,
  20. tapBlock: {[weak self] itemModel, index, view in
  21. guard let self = self else { return }
  22. let appStoreLink = "itms-apps://itunes.apple.com/app/id\(TSConfig.appid)"
  23. if let url = URL(string: appStoreLink + "?action=write-review"),
  24. UIApplication.shared.canOpenURL(url) {
  25. UIApplication.shared.open(url)
  26. }
  27. }))
  28. sectionModel.addSubItemModel(
  29. TSBasicItemModel.createItemModel(
  30. leftTitle: "Share us".localized,
  31. rightViewStyle: 0,
  32. rightString: "",
  33. rightIsHave: true,
  34. height: 80,
  35. rectCorner:.allCorners,
  36. tapBlock: {[weak self] itemModel, index, view in
  37. guard let self = self else { return }
  38. let httpAppStoreLink = "https://apps.apple.com/app/id\(TSConfig.appid)"
  39. let text = "I'm using Sweeter to decorate my phone, there are not only themes, wallpapers, widgets, but also dynamic island and super useful tools, come and try with me!".localized
  40. let url = URL(string: httpAppStoreLink)!
  41. let image = UIImage(named: "App-Icon")!
  42. let vc = UIActivityViewController(activityItems: [image, text, url], applicationActivities: nil)
  43. vc.completionWithItemsHandler = { activity, value, _, error in
  44. if let type = activity, type == .copyToPasteboard {
  45. UIPasteboard.general.string = httpAppStoreLink
  46. }
  47. }
  48. if UIDevice.isPad {
  49. vc.modalPresentationStyle = .popover
  50. }
  51. self.present(vc, animated: true)
  52. }))
  53. sectionModel.addSubItemModel(
  54. TSBasicItemModel.createItemModel(
  55. leftTitle: "Privacy Policy".localized,
  56. rightViewStyle: 0,
  57. rightString: "",
  58. rightIsHave: true,
  59. height: 80,
  60. rectCorner:.allCorners,
  61. tapBlock: {[weak self] itemModel, index, view in
  62. guard let self = self else { return }
  63. let vc = TSBusinessWebVC(urlType: .privacy)
  64. vc.hidesBottomBarWhenPushed = true
  65. navigationController?.pushViewController(vc, animated: true)
  66. }))
  67. sectionModel.addSubItemModel(
  68. TSBasicItemModel.createItemModel(
  69. leftTitle: "Terms of Service".localized,
  70. rightViewStyle: 0,
  71. rightString: "",
  72. rightIsHave: true,
  73. height: 80,
  74. rectCorner:.allCorners,
  75. tapBlock: {[weak self] itemModel, index, view in
  76. guard let self = self else { return }
  77. let vc = TSBusinessWebVC(urlType: .terms)
  78. vc.hidesBottomBarWhenPushed = true
  79. navigationController?.pushViewController(vc, animated: true)
  80. }))
  81. sectionModel.addSubItemModel(
  82. TSBasicItemModel.createItemModel(
  83. leftTitle: "About us".localized,
  84. rightViewStyle: 0,
  85. rightString: appVersion(),
  86. rightIsHave: false,
  87. height: 80,
  88. rectCorner:.allCorners,
  89. tapBlock: {[weak self] itemModel, index, view in
  90. guard let self = self else { return }
  91. let vc = TSAboutUsVC()
  92. vc.hidesBottomBarWhenPushed = true
  93. navigationController?.pushViewController(vc, animated: true)
  94. }))
  95. return dataArray
  96. }()
  97. lazy var tableView:UITableView = {
  98. let tableView = UITableView()
  99. tableView.initBaseTableView(reuseClass: ["TSMineCell"], isUseMJRefresh: false, delegate: self)
  100. return tableView
  101. }()
  102. lazy var navBarView: TSBaseNavContentBarView = {
  103. let navBarView = TSBaseNavContentBarView()
  104. let titleImageView = UIImageView.createImageView(imageName: "nav_title_setting",contentMode: .scaleToFill)
  105. navBarView.barView.addSubview(titleImageView)
  106. titleImageView.snp.makeConstraints { make in
  107. make.centerY.equalToSuperview()
  108. make.left.equalTo(16)
  109. make.width.equalTo(101)
  110. make.height.equalTo(24)
  111. }
  112. return navBarView
  113. }()
  114. override func createData() {
  115. }
  116. override func createView() {
  117. setViewBgImageNamed(named: "view_main_bg")
  118. navBarContentView.addSubview(navBarView)
  119. navBarView.snp.makeConstraints { make in
  120. make.edges.equalToSuperview()
  121. }
  122. contentView.addSubview(tableView)
  123. tableView.snp.makeConstraints { make in
  124. make.leading.equalTo(16)
  125. make.trailing.equalTo(-16)
  126. make.top.bottom.equalTo(0)
  127. }
  128. }
  129. }
  130. extension TSMineVC {
  131. func numberOfSections(in tableView: UITableView) -> Int {
  132. return dataArray.count
  133. }
  134. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  135. if let sectionModel = dataArray.safeObj(At: section){
  136. return sectionModel.itemsArray.count
  137. }
  138. return 0
  139. }
  140. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  141. if let sectionModel = dataArray.safeObj(At: indexPath.section),let itemModel = sectionModel.itemsArray.safeObj(At: indexPath.row){
  142. return itemModel.height
  143. }
  144. return 0
  145. }
  146. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  147. let cell = tableView.dequeueReusableCell(withIdentifier: "TSMineCell") as! TSMineCell
  148. if let sectionModel = dataArray.safeObj(At: indexPath.section),let itemModel = sectionModel.itemsArray.safeObj(At: indexPath.row){
  149. cell.itemModel = itemModel
  150. }
  151. return cell
  152. }
  153. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  154. if let sectionModel = dataArray.safeObj(At: indexPath.section),let itemModel = sectionModel.itemsArray.safeObj(At: indexPath.row){
  155. itemModel.tapBlock?(itemModel,indexPath.row,nil)
  156. }
  157. }
  158. }