RecommendBottomCommentView.swift 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. //
  2. // RecommendBottomCommentView.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/6/14.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. // 推荐图文内容--底部评论View
  8. import UIKit
  9. import RxSwift
  10. import Lottie
  11. enum BottomClickType {
  12. case typeComment
  13. case typeLike
  14. case typeCollect
  15. }
  16. class RecommendBottomCommentView: BaseView {
  17. typealias BottomClickClosure = (_ clickType: BottomClickType) -> Void
  18. var bottomClickClosure : BottomClickClosure?
  19. override func setupViews() {
  20. self.backgroundColor = kffffffColor
  21. addSubview(bgView)
  22. bgView.addSubview(commentView)
  23. commentView.addSubview(commentLabel)
  24. commentView.addSubview(textBtn)
  25. bgView.addSubview(likeBtn)
  26. bgView.addSubview(collectBtn)
  27. bgView.addSubview(commentBtn)
  28. collectBtn.imageView?.addSubview(collectAnimationView)
  29. likeBtn.imageView?.addSubview(praiseAnimationView)
  30. }
  31. override func setupLayouts() {
  32. bgView.snp_makeConstraints { (make) in
  33. make.top.left.right.equalToSuperview()
  34. make.height.equalTo(48)
  35. }
  36. commentBtn.snp.makeConstraints { (make) in
  37. make.right.equalToSuperview().offset(-14)
  38. make.centerY.equalToSuperview()
  39. make.height.equalTo(24)
  40. }
  41. commentBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
  42. collectBtn.snp.makeConstraints { (make) in
  43. make.right.equalTo(commentBtn.snp_left).offset(-15)
  44. make.centerY.equalToSuperview()
  45. make.height.equalTo(37)
  46. }
  47. collectBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
  48. collectAnimationView.snp.makeConstraints { (make) in
  49. make.edges.equalToSuperview()
  50. }
  51. likeBtn.snp.makeConstraints { (make) in
  52. make.right.equalTo(collectBtn.snp_left).offset(-15)
  53. make.centerY.equalToSuperview()
  54. make.height.equalTo(37)
  55. }
  56. likeBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
  57. praiseAnimationView.snp.makeConstraints { (make) in
  58. make.edges.equalToSuperview()
  59. }
  60. commentView.snp.makeConstraints { (make) in
  61. make.centerY.equalToSuperview()
  62. make.left.equalToSuperview().offset(14)
  63. make.right.equalTo(likeBtn.snp_left).offset(-10)
  64. make.height.equalTo(28)
  65. }
  66. commentLabel.snp.makeConstraints { (make) in
  67. make.left.equalTo(15)
  68. make.centerY.equalToSuperview()
  69. make.width.equalTo(70)
  70. make.height.equalTo(28)
  71. }
  72. textBtn.snp.makeConstraints { (make) in
  73. make.edges.equalToSuperview()
  74. }
  75. }
  76. lazy var bgView: UIView = {
  77. let bgView = UIView()
  78. return bgView
  79. }()
  80. private lazy var commentView: UIView = {
  81. let commentView = UIView()
  82. commentView.backgroundColor = kfafafaColor
  83. commentView.cornerRadius = 15
  84. commentView.masksToBounds = true
  85. return commentView
  86. }()
  87. private lazy var commentLabel: UILabel = {
  88. let commentLabel = UILabel()
  89. commentLabel.text = "添加评论..."
  90. commentLabel.textColor = k999999Color
  91. commentLabel.font = kRegularFont14
  92. return commentLabel
  93. }()
  94. private lazy var textBtn: UIButton = {
  95. let textBtn = UIButton(type: UIButton.ButtonType.custom)
  96. textBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
  97. if UserModel.isTokenNil() {
  98. kAppDelegate.setLogin()
  99. }else {
  100. if let bottomClickClosure = self?.bottomClickClosure {
  101. bottomClickClosure(BottomClickType.typeComment)
  102. }
  103. }
  104. }).disposed(by: disposeBag)
  105. return textBtn
  106. }()
  107. private lazy var collectAnimationView: AnimationView = {
  108. let collectAnimationView = AnimationView()
  109. let animation = Animation.named("collect")
  110. collectAnimationView.animation = animation
  111. collectAnimationView.contentMode = .scaleAspectFit
  112. collectAnimationView.loopMode = .playOnce
  113. collectAnimationView.isHidden = true
  114. return collectAnimationView
  115. }()
  116. private lazy var praiseAnimationView: AnimationView = {
  117. let praiseAnimationView = AnimationView()
  118. let animation = Animation.named("verywell")
  119. praiseAnimationView.animation = animation
  120. praiseAnimationView.contentMode = .scaleAspectFit
  121. praiseAnimationView.loopMode = .playOnce
  122. praiseAnimationView.isHidden = true
  123. return praiseAnimationView
  124. }()
  125. private lazy var likeBtn: UIButton = {
  126. let likeBtn = UIButton(type: UIButton.ButtonType.custom)
  127. likeBtn.setTitleColor(k313334Color, for: UIControl.State.normal)
  128. likeBtn.setImage(kImage(name: "btn_praise_black"), for: UIControl.State.normal)
  129. likeBtn.setImage(kImage(name: "btn_praise_pre"), for: UIControl.State.selected)
  130. likeBtn.titleLabel?.font = kRegularFont14
  131. likeBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
  132. if UserModel.isTokenNil() {
  133. kAppDelegate.setLogin()
  134. }else {
  135. likeBtn.isSelected = !likeBtn.isSelected
  136. if self?.communityPostDetailModel?.isLike == 0 {
  137. self?.praiseAnimationView.isHidden = false
  138. self?.praiseAnimationView.play(completion: {
  139. [weak self] (_) in
  140. self?.praiseAnimationView.isHidden = true
  141. })
  142. }
  143. if let bottomClickClosure = self?.bottomClickClosure {
  144. bottomClickClosure(BottomClickType.typeLike)
  145. }
  146. }
  147. }).disposed(by: disposeBag)
  148. return likeBtn
  149. }()
  150. private lazy var collectBtn: UIButton = {
  151. let collectBtn = UIButton(type: UIButton.ButtonType.custom)
  152. collectBtn.setTitleColor(k313334Color, for: UIControl.State.normal)
  153. collectBtn.setImage(kImage(name: "btn_collect_black"), for: .normal)
  154. collectBtn.setImage(kImage(name: "btn_collect_pre"), for: .selected)
  155. collectBtn.titleLabel?.font = kRegularFont14
  156. collectBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
  157. if UserModel.isTokenNil() {
  158. kAppDelegate.setLogin()
  159. }else {
  160. collectBtn.isSelected = !collectBtn.isSelected
  161. if self?.communityPostDetailModel?.isCollect == 0 {
  162. self?.collectAnimationView.isHidden = false
  163. self?.collectAnimationView.play(completion: {
  164. [weak self] (_) in
  165. self?.collectAnimationView.isHidden = true
  166. })
  167. }
  168. if let bottomClickClosure = self?.bottomClickClosure {
  169. bottomClickClosure(BottomClickType.typeCollect)
  170. }
  171. }
  172. }).disposed(by: disposeBag)
  173. return collectBtn
  174. }()
  175. private lazy var commentBtn: UIButton = {
  176. let commentBtn = UIButton(type: UIButton.ButtonType.custom)
  177. commentBtn.setTitleColor(k313334Color, for: UIControl.State.normal)
  178. commentBtn.setImage(kImage(name: "btn_note_black"), for: UIControl.State.normal)
  179. commentBtn.titleLabel?.font = kRegularFont14
  180. commentBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
  181. if UserModel.isTokenNil() {
  182. kAppDelegate.setLogin()
  183. }else {
  184. if let bottomClickClosure = self?.bottomClickClosure {
  185. bottomClickClosure(BottomClickType.typeComment)
  186. }
  187. }
  188. }).disposed(by: disposeBag)
  189. return commentBtn
  190. }()
  191. var communityPostDetailModel : CommunityPostDetailModel? {
  192. didSet {
  193. likeBtn.setTitle("\(communityPostDetailModel?.praiseCount ?? 0)", for: UIControl.State.normal)
  194. if communityPostDetailModel?.isLike == 1 {
  195. likeBtn.isSelected = true
  196. }else {
  197. likeBtn.isSelected = false
  198. }
  199. likeBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
  200. collectBtn.setTitle("\(communityPostDetailModel?.collectCount ?? 0)", for: UIControl.State.normal)
  201. if communityPostDetailModel?.isCollect == 1 {
  202. collectBtn.isSelected = true
  203. }else {
  204. collectBtn.isSelected = false
  205. }
  206. collectBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
  207. commentBtn.setTitle("\(communityPostDetailModel?.commentCount ?? 0)", for: UIControl.State.normal)
  208. commentBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
  209. }
  210. }
  211. }