MJRefreshManager.swift 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // File.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/7/26.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import Foundation
  9. class MJRefreshManager: NSObject {
  10. //MARK: - tableView
  11. class func hiddenHeaderWithFooter(tableView : UITableView?) {
  12. if tableView?.mj_footer != nil {
  13. tableView?.endFooterRefresh()
  14. }
  15. if tableView?.mj_header != nil {
  16. tableView?.endHeaderRefresh()
  17. }
  18. tableView?.ly_endLoading()
  19. }
  20. class func hiddenHeaderWithFooterNONetWork(tableView : UITableView?) {
  21. DIYEmptyView.emptyNoDataActionTableView(tableView: tableView, btnClickBlock: {
  22. [weak tableView] in
  23. tableView?.mj_header.beginRefreshing()
  24. })
  25. if tableView?.mj_footer != nil {
  26. tableView?.endFooterRefresh()
  27. }
  28. if tableView?.mj_header != nil {
  29. tableView?.endHeaderRefresh()
  30. }
  31. tableView?.ly_endLoading()
  32. }
  33. class func hiddenHeaderWithFooterNOData(tableView : UITableView?) {
  34. DIYEmptyView.emptyNoDataTableView(tableView: tableView,imageStr: .one,detailStr: .one)
  35. if tableView?.mj_footer != nil {
  36. tableView?.endFooterRefresh()
  37. }
  38. if tableView?.mj_header != nil {
  39. tableView?.endHeaderRefresh()
  40. }
  41. tableView?.ly_endLoading()
  42. }
  43. class func hiddenHeaderWithFooter(tableView:UITableView?,loadingStatus:SwiftMoyaNetWorkManagerLoadingStatus) {
  44. if tableView?.mj_footer != nil {
  45. tableView?.isHiddenFooter(true)
  46. }
  47. if loadingStatus == .noData {
  48. MJRefreshManager.hiddenHeaderWithFooterNOData(tableView: tableView)
  49. }else if loadingStatus == .noNetwork {
  50. MJRefreshManager.hiddenHeaderWithFooterNONetWork(tableView: tableView)
  51. }
  52. }
  53. class func hiddenHeaderWithFooter(tableView : UITableView?,pagination : PaginationModel?) {
  54. if tableView?.mj_header != nil {
  55. tableView?.endHeaderRefresh()
  56. }
  57. if tableView?.mj_footer != nil {
  58. tableView?.endFooterRefresh()
  59. }
  60. if pagination?.total == 0 {
  61. if tableView?.mj_footer != nil {
  62. tableView?.isHiddenFooter(true)
  63. }
  64. }else {
  65. if pagination?.currentPage ?? 1 >= pagination?.totalPages ?? 1 {
  66. tableView?.mj_footer.isHidden = false
  67. if tableView?.mj_footer != nil {
  68. tableView?.endFooterNoMoreData()
  69. tableView?.mj_footer.pullingPercent = 1
  70. }
  71. }
  72. }
  73. tableView?.ly_endLoading()
  74. }
  75. //MARK: - collectionView
  76. class func hiddenHeaderWithFooter(collectionView : UICollectionView?) {
  77. if collectionView?.mj_header != nil {
  78. collectionView?.endHeaderRefresh()
  79. }
  80. if collectionView?.mj_footer != nil {
  81. collectionView?.endFooterRefresh()
  82. }
  83. collectionView?.ly_endLoading()
  84. }
  85. class func hiddenHeaderWithFooterNONetWork(collectionView : UICollectionView?) {
  86. DIYEmptyView.emptyNoDataActionCollectionView(collectionView: collectionView, btnClickBlock: {
  87. [weak collectionView] in
  88. collectionView?.mj_header.beginRefreshing()
  89. })
  90. if collectionView?.mj_header != nil {
  91. collectionView?.endHeaderRefresh()
  92. }
  93. if collectionView?.mj_footer != nil {
  94. collectionView?.endFooterRefresh()
  95. }
  96. collectionView?.ly_endLoading()
  97. }
  98. class func hiddenHeaderWithFooterNOData(collectionView : UICollectionView?) {
  99. DIYEmptyView.emptyNoDataCollectionView(collectionView: collectionView)
  100. if collectionView?.mj_header != nil {
  101. collectionView?.endHeaderRefresh()
  102. }
  103. if collectionView?.mj_footer != nil {
  104. collectionView?.endFooterRefresh()
  105. }
  106. collectionView?.ly_endLoading()
  107. }
  108. class func hiddenHeaderWithFooter(collectionView:UICollectionView?,loadingStatus:SwiftMoyaNetWorkManagerLoadingStatus) {
  109. if collectionView?.mj_footer != nil {
  110. collectionView?.isHiddenFooter(true)
  111. }
  112. if loadingStatus == .noData {
  113. MJRefreshManager.hiddenHeaderWithFooterNOData(collectionView: collectionView)
  114. }else if loadingStatus == .noNetwork {
  115. MJRefreshManager.hiddenHeaderWithFooterNONetWork(collectionView: collectionView)
  116. }
  117. }
  118. class func hiddenHeaderWithFooter(collectionView : UICollectionView?,pagination : PaginationModel?) {
  119. if collectionView?.mj_header != nil {
  120. collectionView?.endHeaderRefresh()
  121. }
  122. if collectionView?.mj_footer != nil {
  123. collectionView?.endFooterRefresh()
  124. }
  125. if pagination?.total == 0 {
  126. if collectionView?.mj_footer != nil {
  127. collectionView?.isHiddenFooter(true)
  128. }
  129. }else {
  130. if pagination?.currentPage ?? 1 >= pagination?.totalPages ?? 1 {
  131. collectionView?.mj_footer.isHidden = false
  132. if collectionView?.mj_footer != nil {
  133. collectionView?.endFooterNoMoreData()
  134. collectionView?.mj_footer.pullingPercent = 1
  135. }
  136. }
  137. }
  138. collectionView?.ly_endLoading()
  139. }
  140. }