EstuLogPhotoCollReactor.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // EstuLogPhotoCollReactor.swift
  3. // JiaPeiManage
  4. //
  5. // Created by Ning.ge on 2023/9/1.
  6. //
  7. import ReactorKit
  8. import RxSwift
  9. final class DramaRcmdCellReactor: Reactor {
  10. enum Action {
  11. case follow(season_id:String, season_type:String)
  12. case unFollow(season_id:String, season_type:String)
  13. }
  14. struct State {
  15. var coverURL: URL?
  16. var favourites: String?
  17. var badge: String?
  18. var title: String
  19. var latestUpdate: String
  20. var latestUpdateColor: UIColor
  21. var watchProgress: String?
  22. var tagDesc: String?
  23. var season_id:String?
  24. var season_type:String?
  25. var isRcmd: Bool
  26. var isHiddenLine: Bool
  27. }
  28. let initialState: State
  29. private let service: HomeServiceType
  30. init(recommend: DramaRecommendModel, service: HomeServiceType, isLast:Bool) {
  31. self.service = service
  32. let coverURL = URL(string: recommend.cover)
  33. let favourites = "\(recommend.favorites ?? "")人追番"
  34. let latestUpdate = "更新至第\(recommend.newest_ep_index)话"
  35. var tagDesc: String = ""
  36. if let tags = recommend.tags {
  37. for tag in tags {
  38. tagDesc += ",\(tag.tag_name)"
  39. }
  40. }
  41. if !tagDesc.isEmpty {
  42. tagDesc.remove(at: String.Index(utf16Offset: 0, in: tagDesc))
  43. }
  44. self.initialState = State(coverURL: coverURL,
  45. favourites: favourites,
  46. badge: recommend.badge,
  47. title: recommend.title,
  48. latestUpdate: latestUpdate,
  49. latestUpdateColor:UIColor.db_pink,
  50. watchProgress: nil,
  51. tagDesc: tagDesc,
  52. season_id:recommend.season_id!,
  53. season_type:"\(recommend.season_type!)",
  54. isRcmd:true,
  55. isHiddenLine: false)
  56. _ = self.state
  57. }
  58. init(like: DramaLikeModel, service: HomeServiceType, isLast:Bool) {
  59. self.service = service
  60. let coverURL = URL(string: like.cover)
  61. let latestUpdate = "更新至第\(like.newest_ep_index)话"
  62. var watchProgress: String?
  63. if like.user_season.last_ep_index.isEmpty {
  64. watchProgress = "尚未观看"
  65. }else{
  66. if let num = Int(like.user_season.last_ep_index) {
  67. watchProgress = "看到第\(num)话"
  68. }else{
  69. watchProgress = "看到\(like.user_season.last_ep_index)"
  70. }
  71. }
  72. self.initialState = State(coverURL: coverURL,
  73. favourites: nil,
  74. badge: like.badge,
  75. title: like.title,
  76. latestUpdate: latestUpdate,
  77. latestUpdateColor:UIColor.db_darkGray,
  78. watchProgress:watchProgress,
  79. tagDesc: nil,
  80. season_id:nil,
  81. season_type:nil,
  82. isRcmd:false,
  83. isHiddenLine: isLast)
  84. _ = self.state
  85. }
  86. //只需调用接口,其他不用处理
  87. func mutate(action: Action) -> Observable<Void> {
  88. switch action {
  89. case .follow(let season_id, let season_type):
  90. BilibiliToaster.show("由于接口加密,所以需要看到类似B站的效果必须用自己手机抓包,将请求参数替换")
  91. _ = service.dramaFollow(season_id: season_id, season_type: season_type).asObservable().subscribe()
  92. return .empty()
  93. case .unFollow(let season_id, let season_type):
  94. _ = service.dramaUnFollow(season_id: season_id, season_type: season_type).subscribe()
  95. return .empty()
  96. }
  97. }
  98. }