123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- //
- // RecommendBottomCommentView.swift
- // RainbowPlanet
- //
- // Created by Christopher on 2019/6/14.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- // 推荐图文内容--底部评论View
- import UIKit
- import RxSwift
- import Lottie
- enum BottomClickType {
- case typeComment
- case typeLike
- case typeCollect
- }
- class RecommendBottomCommentView: BaseView {
-
- typealias BottomClickClosure = (_ clickType: BottomClickType) -> Void
- var bottomClickClosure : BottomClickClosure?
-
- override func setupViews() {
- self.backgroundColor = kffffffColor
- addSubview(bgView)
- bgView.addSubview(commentView)
- commentView.addSubview(commentLabel)
- commentView.addSubview(textBtn)
- bgView.addSubview(likeBtn)
- bgView.addSubview(collectBtn)
- bgView.addSubview(commentBtn)
- collectBtn.imageView?.addSubview(collectAnimationView)
- likeBtn.imageView?.addSubview(praiseAnimationView)
- }
-
- override func setupLayouts() {
- bgView.snp_makeConstraints { (make) in
- make.top.left.right.equalToSuperview()
- make.height.equalTo(48)
- }
- commentBtn.snp.makeConstraints { (make) in
- make.right.equalToSuperview().offset(-14)
- make.centerY.equalToSuperview()
- make.height.equalTo(24)
- }
- commentBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
-
- collectBtn.snp.makeConstraints { (make) in
- make.right.equalTo(commentBtn.snp_left).offset(-15)
- make.centerY.equalToSuperview()
- make.height.equalTo(37)
- }
- collectBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
- collectAnimationView.snp.makeConstraints { (make) in
- make.edges.equalToSuperview()
- }
-
- likeBtn.snp.makeConstraints { (make) in
- make.right.equalTo(collectBtn.snp_left).offset(-15)
- make.centerY.equalToSuperview()
- make.height.equalTo(37)
- }
- likeBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
- praiseAnimationView.snp.makeConstraints { (make) in
- make.edges.equalToSuperview()
- }
-
- commentView.snp.makeConstraints { (make) in
- make.centerY.equalToSuperview()
- make.left.equalToSuperview().offset(14)
- make.right.equalTo(likeBtn.snp_left).offset(-10)
- make.height.equalTo(28)
- }
- commentLabel.snp.makeConstraints { (make) in
- make.left.equalTo(15)
- make.centerY.equalToSuperview()
- make.width.equalTo(70)
- make.height.equalTo(28)
- }
- textBtn.snp.makeConstraints { (make) in
- make.edges.equalToSuperview()
- }
-
- }
-
- lazy var bgView: UIView = {
- let bgView = UIView()
- return bgView
- }()
-
- private lazy var commentView: UIView = {
- let commentView = UIView()
- commentView.backgroundColor = kfafafaColor
- commentView.cornerRadius = 15
- commentView.masksToBounds = true
- return commentView
- }()
-
- private lazy var commentLabel: UILabel = {
- let commentLabel = UILabel()
- commentLabel.text = "添加评论..."
- commentLabel.textColor = k999999Color
- commentLabel.font = kRegularFont14
- return commentLabel
- }()
-
- private lazy var textBtn: UIButton = {
- let textBtn = UIButton(type: UIButton.ButtonType.custom)
- textBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
- if UserModel.isTokenNil() {
- kAppDelegate.setLogin()
- }else {
- if let bottomClickClosure = self?.bottomClickClosure {
- bottomClickClosure(BottomClickType.typeComment)
- }
- }
- }).disposed(by: disposeBag)
- return textBtn
- }()
-
- private lazy var collectAnimationView: AnimationView = {
- let collectAnimationView = AnimationView()
- let animation = Animation.named("collect")
- collectAnimationView.animation = animation
- collectAnimationView.contentMode = .scaleAspectFit
- collectAnimationView.loopMode = .playOnce
- collectAnimationView.isHidden = true
- return collectAnimationView
- }()
-
- private lazy var praiseAnimationView: AnimationView = {
- let praiseAnimationView = AnimationView()
- let animation = Animation.named("verywell")
- praiseAnimationView.animation = animation
- praiseAnimationView.contentMode = .scaleAspectFit
- praiseAnimationView.loopMode = .playOnce
- praiseAnimationView.isHidden = true
- return praiseAnimationView
- }()
-
- private lazy var likeBtn: UIButton = {
- let likeBtn = UIButton(type: UIButton.ButtonType.custom)
- likeBtn.setTitleColor(k313334Color, for: UIControl.State.normal)
- likeBtn.setImage(kImage(name: "btn_praise_black"), for: UIControl.State.normal)
- likeBtn.setImage(kImage(name: "btn_praise_pre"), for: UIControl.State.selected)
- likeBtn.titleLabel?.font = kRegularFont14
- likeBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
-
- if UserModel.isTokenNil() {
- kAppDelegate.setLogin()
- }else {
- likeBtn.isSelected = !likeBtn.isSelected
- if self?.communityPostDetailModel?.isLike == 0 {
- self?.praiseAnimationView.isHidden = false
- self?.praiseAnimationView.play(completion: {
- [weak self] (_) in
- self?.praiseAnimationView.isHidden = true
- })
- }
- if let bottomClickClosure = self?.bottomClickClosure {
- bottomClickClosure(BottomClickType.typeLike)
- }
- }
-
-
- }).disposed(by: disposeBag)
- return likeBtn
- }()
-
- private lazy var collectBtn: UIButton = {
- let collectBtn = UIButton(type: UIButton.ButtonType.custom)
- collectBtn.setTitleColor(k313334Color, for: UIControl.State.normal)
- collectBtn.setImage(kImage(name: "btn_collect_black"), for: .normal)
- collectBtn.setImage(kImage(name: "btn_collect_pre"), for: .selected)
- collectBtn.titleLabel?.font = kRegularFont14
- collectBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
-
- if UserModel.isTokenNil() {
- kAppDelegate.setLogin()
- }else {
- collectBtn.isSelected = !collectBtn.isSelected
- if self?.communityPostDetailModel?.isCollect == 0 {
- self?.collectAnimationView.isHidden = false
- self?.collectAnimationView.play(completion: {
- [weak self] (_) in
- self?.collectAnimationView.isHidden = true
- })
- }
- if let bottomClickClosure = self?.bottomClickClosure {
- bottomClickClosure(BottomClickType.typeCollect)
- }
- }
-
- }).disposed(by: disposeBag)
- return collectBtn
- }()
-
- private lazy var commentBtn: UIButton = {
- let commentBtn = UIButton(type: UIButton.ButtonType.custom)
- commentBtn.setTitleColor(k313334Color, for: UIControl.State.normal)
- commentBtn.setImage(kImage(name: "btn_note_black"), for: UIControl.State.normal)
- commentBtn.titleLabel?.font = kRegularFont14
- commentBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
- if UserModel.isTokenNil() {
- kAppDelegate.setLogin()
- }else {
- if let bottomClickClosure = self?.bottomClickClosure {
- bottomClickClosure(BottomClickType.typeComment)
- }
- }
- }).disposed(by: disposeBag)
- return commentBtn
- }()
-
- var communityPostDetailModel : CommunityPostDetailModel? {
- didSet {
- likeBtn.setTitle("\(communityPostDetailModel?.praiseCount ?? 0)", for: UIControl.State.normal)
- if communityPostDetailModel?.isLike == 1 {
- likeBtn.isSelected = true
- }else {
- likeBtn.isSelected = false
- }
- likeBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
-
- collectBtn.setTitle("\(communityPostDetailModel?.collectCount ?? 0)", for: UIControl.State.normal)
- if communityPostDetailModel?.isCollect == 1 {
- collectBtn.isSelected = true
- }else {
- collectBtn.isSelected = false
- }
- collectBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
-
- commentBtn.setTitle("\(communityPostDetailModel?.commentCount ?? 0)", for: UIControl.State.normal)
- commentBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
- }
- }
-
- }
|