CommunityMyFollowTopicController.swift 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // CommunityMyFollowTopicController.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/6/12.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import SwiftyMediator
  10. class CommunityMyFollowTopicController: BaseViewController {
  11. var communityMemberFollowTopicListDataModels = Array<CommunityMemberFollowTopicListDataModel>()
  12. override func viewDidLoad() {
  13. super.viewDidLoad()
  14. setupViews()
  15. setupLayouts()
  16. setupData()
  17. }
  18. override func setupViews() {
  19. navigationBar.title = "我的关注话题"
  20. view.backgroundColor = kf7f8faColor
  21. view.addSubview(tableView)
  22. }
  23. override func setupLayouts() {
  24. tableView.snp.makeConstraints { (make) in
  25. make.top.equalToSuperview().offset(kNavBarTotalHeight)
  26. make.left.right.bottom.equalTo(0)
  27. }
  28. if #available(iOS 11.0, *) {
  29. tableView.contentInsetAdjustmentBehavior = .never
  30. }
  31. }
  32. override func setupData() {
  33. let emptyView = DIYEmptyView.emptyActionView(withImageStr: "default_page_topic", titleStr: nil, detailStr: "暂无关注,去发现好玩的话题吧", btnTitleStr: "去首页") {
  34. [weak self] in
  35. self?.tabBarController?.selectedIndex = 0
  36. self?.navigationController?.popToClass(type: CommunityViewController.self)
  37. }
  38. emptyView?.actionBtnHorizontalMargin = 58
  39. emptyView?.contentViewY = kScaleValue(value: 164)
  40. emptyView?.subViewMargin = 20
  41. emptyView?.actionBtnFont = kBoldFont16
  42. emptyView?.actionBtnHeight = 32
  43. emptyView?.actionBtnCornerRadius = 32/2
  44. emptyView?.actionBtnTitleColor = kffffffColor
  45. emptyView?.actionBtnBackGroundColor = kThemeColor
  46. emptyView?.detailLabFont = kRegularFont14
  47. tableView.ly_emptyView = emptyView
  48. tableView.ly_startLoading()
  49. tableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) {
  50. [weak self] (page) in
  51. self?.communityMemberFollowTopicListApi(page: page)
  52. }
  53. tableView.addFooterWithWithHeader(withAutomaticallyRefresh: false) {
  54. [weak self] (page) in
  55. self?.communityMemberFollowTopicListApi(page: page)
  56. }
  57. }
  58. lazy var tableView: UITableView = {
  59. let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
  60. tableView.separatorStyle = .none
  61. tableView.backgroundColor = kf7f8faColor
  62. tableView.dataSource = self
  63. tableView.delegate = self
  64. tableView.rowHeight = 60
  65. return tableView
  66. }()
  67. }
  68. extension CommunityMyFollowTopicController {
  69. //我的关注话题
  70. func communityMemberFollowTopicListApi(page:Int) {
  71. SwiftMoyaNetWorkServiceCommunity.shared().communityMemberFollowTopicListApi(page: page) {
  72. [weak self] (communityMemberFollowTopicListModel) -> (Void) in
  73. let communityMemberFollowTopicListModel = communityMemberFollowTopicListModel as? CommunityMemberFollowTopicListModel
  74. if communityMemberFollowTopicListModel?.pagination?.currentPage ?? 1 <= communityMemberFollowTopicListModel?.pagination?.totalPages ?? 1 {
  75. if communityMemberFollowTopicListModel?.pagination?.currentPage == 1{
  76. self?.communityMemberFollowTopicListDataModels.removeAll()
  77. }
  78. self?.communityMemberFollowTopicListDataModels = (self?.communityMemberFollowTopicListDataModels)! + (communityMemberFollowTopicListModel?.data!)!
  79. self?.tableView.reloadData()
  80. if self?.communityMemberFollowTopicListDataModels.count ?? 0 >= communityMemberFollowTopicListModel?.pagination?.total ?? 0 {
  81. self?.tableView.endFooterNoMoreData()
  82. }
  83. }else {
  84. self?.tableView.endFooterNoMoreData()
  85. }
  86. }
  87. }
  88. }
  89. // MARK: - tableView dataSource && delegate
  90. extension CommunityMyFollowTopicController: UITableViewDataSource, UITableViewDelegate {
  91. func numberOfSections(in tableView: UITableView) -> Int {
  92. return 1
  93. }
  94. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  95. return communityMemberFollowTopicListDataModels.isEmpty ? 0 : communityMemberFollowTopicListDataModels.count
  96. }
  97. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  98. let cell = CommunityMyFollowTopicCell.cellWith(tableView: tableView, indexPath: indexPath)
  99. cell.communityMemberFollowTopicListDataModel = communityMemberFollowTopicListDataModels[indexPath.row]
  100. return cell
  101. }
  102. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  103. tableView.deselectRow(at: indexPath, animated: true)
  104. Mediator.push(CommunityRouterModuleType.pushFeaturedTopics(id: communityMemberFollowTopicListDataModels[indexPath.row].topicId ?? 0))
  105. }
  106. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  107. return 60
  108. }
  109. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  110. return 10
  111. }
  112. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  113. return 0
  114. }
  115. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  116. return nil
  117. }
  118. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  119. return nil
  120. }
  121. }