Commit 2f7814f2 authored by Alex朱枝文's avatar Alex朱枝文

社区列表增加点赞按钮、分享bug修复

parent 3fef7ab7
...@@ -219,8 +219,8 @@ extension YHCircleViewController: UICollectionViewDelegate, UICollectionViewData ...@@ -219,8 +219,8 @@ extension YHCircleViewController: UICollectionViewDelegate, UICollectionViewData
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHCircleCollectionViewCell.cellReuseIdentifier, for: indexPath) as? YHCircleCollectionViewCell else { guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHCircleCollectionViewCell.cellReuseIdentifier, for: indexPath) as? YHCircleCollectionViewCell else {
return UICollectionViewCell() return UICollectionViewCell()
} }
let model = arr[indexPath.row]
cell.listModel = arr[indexPath.row] cell.listModel = model
cell.onImageHeightChanged = { [weak self] in cell.onImageHeightChanged = { [weak self] in
guard let self = self else { guard let self = self else {
return return
...@@ -229,6 +229,27 @@ extension YHCircleViewController: UICollectionViewDelegate, UICollectionViewData ...@@ -229,6 +229,27 @@ extension YHCircleViewController: UICollectionViewDelegate, UICollectionViewData
self.circleCollectView.reloadData() self.circleCollectView.reloadData()
} }
} }
cell.clickHeartEvent = { [weak self, weak cell] in
guard let self = self else {
return
}
if !YHLoginManager.shared.isLogin() {
YHOneKeyLoginManager.shared.oneKeyLogin()
return
}
let operation = model.like_self ? 2 : 1
self.viewModel.getLike(model.id, operation) { success, _ in
if success {
model.like_self = !model.like_self
if model.like_self {
model.like_count += 1
} else {
model.like_count -= 1
}
cell?.updateLikeState(isLike: model.like_self, currentModel: model)
}
}
}
return cell return cell
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
import UIKit import UIKit
import Kingfisher import Kingfisher
import Lottie
class YHCircleCollectionViewCell: UICollectionViewCell { class YHCircleCollectionViewCell: UICollectionViewCell {
...@@ -20,6 +21,7 @@ class YHCircleCollectionViewCell: UICollectionViewCell { ...@@ -20,6 +21,7 @@ class YHCircleCollectionViewCell: UICollectionViewCell {
} }
var onImageHeightChanged: (() -> Void)? var onImageHeightChanged: (() -> Void)?
var clickHeartEvent: (() -> Void)?
// MARK: - UI Components // MARK: - UI Components
...@@ -64,6 +66,27 @@ class YHCircleCollectionViewCell: UICollectionViewCell { ...@@ -64,6 +66,27 @@ class YHCircleCollectionViewCell: UICollectionViewCell {
return view return view
}() }()
lazy var heartImageViewBtn: UIButton = {
let btn: UIButton = UIButton(type: .custom)
btn.setImage(UIImage(named: "circle_grey_heart"), for: .normal)
btn.setImage(UIImage(named: "circle_red_heart"), for: .selected)
return btn
}()
lazy var numLable: UILabel = {
let label = UILabel()
label.text = ""
label.textColor = UIColor.brandGrayColor6
label.font = UIFont.PFSC_R(ofSize: 12)
return label
}()
lazy var animationView: LottieAnimationView = {
let view = LottieAnimationView(name: "shouye")
view.isHidden = true
return view
}()
// MARK: - Initialization // MARK: - Initialization
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
...@@ -101,24 +124,79 @@ class YHCircleCollectionViewCell: UICollectionViewCell { ...@@ -101,24 +124,79 @@ class YHCircleCollectionViewCell: UICollectionViewCell {
// 头像 // 头像
subHoldView.addSubview(avatarImageView) subHoldView.addSubview(avatarImageView)
// 昵称
subHoldView.addSubview(nameLabel)
subHoldView.addSubview(numLable)
subHoldView.addSubview(animationView)
subHoldView.addSubview(heartImageViewBtn)
avatarImageView.setContentCompressionResistancePriority(.required, for: .horizontal)
heartImageViewBtn.setContentCompressionResistancePriority(.required, for: .horizontal)
numLable.setContentCompressionResistancePriority(.required, for: .horizontal)
animationView.setContentCompressionResistancePriority(.required, for: .horizontal)
nameLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
avatarImageView.snp.makeConstraints { make in avatarImageView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(8) make.left.equalToSuperview().offset(8)
make.top.equalTo(contentLabel.snp.bottom).offset(12) make.top.equalTo(contentLabel.snp.bottom).offset(12)
make.width.height.equalTo(16) make.width.height.equalTo(16)
} }
// 昵称
subHoldView.addSubview(nameLabel)
nameLabel.snp.makeConstraints { make in nameLabel.snp.makeConstraints { make in
make.left.equalTo(avatarImageView.snp.right).offset(4) make.left.equalTo(avatarImageView.snp.right).offset(4)
make.centerY.equalTo(avatarImageView) make.centerY.equalTo(avatarImageView)
make.right.equalToSuperview().offset(-8) make.right.equalToSuperview().offset(-8)
} }
numLable.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-8)
make.top.equalTo(avatarImageView)
make.height.equalTo(16)
}
animationView.snp.makeConstraints { make in
make.right.equalTo(numLable.snp.left).offset(2.5)
make.height.width.equalTo(24)
make.centerY.equalTo(numLable).offset(-0.5)
}
heartImageViewBtn.snp.makeConstraints { make in
make.right.equalTo(numLable.snp.left).offset(-2)
make.height.width.equalTo(16)
make.centerY.equalTo(numLable)
}
heartImageViewBtn.addTarget(self, action: #selector(clickHeart), for: .touchUpInside)
heartImageViewBtn.YH_clickEdgeInsets = UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15)
}
// MARK: - Actions
@objc func clickHeart() {
clickHeartEvent?()
} }
// MARK: - Update UI // MARK: - Update UI
func updateLikeState(isLike: Bool, currentModel: YHDynamicItem) {
guard let model = listModel, currentModel.id == model.id else { return }
self.numLable.text = model.like_count > 9999 ? "9999+" : model.like_count.string
if isLike {
// self.heartImageViewBtn.setImage(UIImage(named: ""), for: .selected)
// self.heartImageViewBtn.setImage(UIImage(named: ""), for: .normal)
// self.animationView.isHidden = false
// self.animationView.loopMode = .playOnce
// self.animationView.play { [weak self] _ in
// guard let self = self else { return }
// self.animationView.isHidden = true
// self.heartImageViewBtn.setImage(UIImage(named: "circle_red_heart"), for: .normal)
// }
self.heartImageViewBtn.setImage(UIImage(named: "circle_red_heart"), for: .normal)
} else {
animationView.isHidden = true
self.heartImageViewBtn.setImage(UIImage(named: "circle_grey_heart"), for: .normal)
}
}
private func updateUI() { private func updateUI() {
guard let model = listModel else { return } guard let model = listModel else { return }
...@@ -189,5 +267,11 @@ class YHCircleCollectionViewCell: UICollectionViewCell { ...@@ -189,5 +267,11 @@ class YHCircleCollectionViewCell: UICollectionViewCell {
make.right.equalToSuperview().offset(-8) make.right.equalToSuperview().offset(-8)
make.height.equalTo(model.textH) make.height.equalTo(model.textH)
} }
numLable.text = model.like_count > 9999 ? "9999+" : model.like_count.string
if model.like_self {
heartImageViewBtn.setImage(UIImage(named: "circle_red_heart"), for: .normal)
} else {
heartImageViewBtn.setImage(UIImage(named: "circle_grey_heart"), for: .normal)
}
} }
} }
...@@ -433,9 +433,7 @@ private extension YHH5WebViewVC { ...@@ -433,9 +433,7 @@ private extension YHH5WebViewVC {
shareUrl = YHBaseUrlManager.shared.curH5URL() + "superAppBridge.html#/evaluation?channel=APP-share&customer_id=\(YHLoginManager.shared.userModel?.id ?? "")" shareUrl = YHBaseUrlManager.shared.curH5URL() + "superAppBridge.html#/evaluation?channel=APP-share&customer_id=\(YHLoginManager.shared.userModel?.id ?? "")"
} }
if !shareUrl.isEmpty && if !shareUrl.isEmpty {
!self.shareH5Title.isEmpty &&
!self.shareH5Describe.isEmpty {
if let shareImageUrl = shareImageUrl, !shareImageUrl.isEmpty { if let shareImageUrl = shareImageUrl, !shareImageUrl.isEmpty {
YHHUD.show(.progress(message: "")) YHHUD.show(.progress(message: ""))
YHKingfisherUtils.fetchImage(with: shareImageUrl) { image in YHKingfisherUtils.fetchImage(with: shareImageUrl) { image in
......
...@@ -239,7 +239,7 @@ extension YHJsApi { ...@@ -239,7 +239,7 @@ extension YHJsApi {
let shareH5Url: String = jsonObject["ShareH5Url"] as? String ?? "" let shareH5Url: String = jsonObject["ShareH5Url"] as? String ?? ""
let shareImageUrl: String? = jsonObject["ShareImgUrl"] as? String let shareImageUrl: String? = jsonObject["ShareImgUrl"] as? String
if !shareH5Title.isEmpty, !shareH5Describe.isEmpty, !shareH5Url.isEmpty { if !shareH5Url.isEmpty {
if let delegate = self.delegate as? YHH5WebViewVC { if let delegate = self.delegate as? YHH5WebViewVC {
delegate.shareH5Syn(title: shareH5Title, desc: shareH5Describe, url: shareH5Url, shareImageUrl: shareImageUrl) delegate.shareH5Syn(title: shareH5Title, desc: shareH5Describe, url: shareH5Url, shareImageUrl: shareImageUrl)
} }
......
...@@ -55,6 +55,7 @@ class YHDynamicItem: SmartCodable { ...@@ -55,6 +55,7 @@ class YHDynamicItem: SmartCodable {
var format_release_time: String = "" var format_release_time: String = ""
var created_at: String = "" var created_at: String = ""
var is_self_posts: Bool = false // 是否是自己的动态 var is_self_posts: Bool = false // 是否是自己的动态
var like_self: Bool = false
// MARK: - 高度计算相关属性 // MARK: - 高度计算相关属性
......
...@@ -81,10 +81,11 @@ extension YHDynamicViewModel { ...@@ -81,10 +81,11 @@ extension YHDynamicViewModel {
/// 点赞/取消点赞动态 /// 点赞/取消点赞动态
/// - Parameters: /// - Parameters:
/// - id: 动态ID /// - id: 动态ID
/// - operation: 操作类型 1-点赞 2-取消点赞 /// - type: 操作类型 1收藏2点赞
/// - operation: 操作类型 1增加 2取消
/// - callBackBlock: 回调 /// - callBackBlock: 回调
func getLike(_ id: String, _ operation: Int, callBackBlock: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) { func getLike(_ id: String, _ operation: Int, callBackBlock: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) {
let params: [String: Any] = ["id": id, "operation": operation] let params: [String: Any] = ["id": id, "operation": operation, "type": 2]
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Dynamic.like let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Dynamic.like
_ = YHNetRequest.postRequest(url: strUrl, params: params) { json, _ in _ = YHNetRequest.postRequest(url: strUrl, params: params) { json, _ in
......
...@@ -787,7 +787,7 @@ class YHAllApiName { ...@@ -787,7 +787,7 @@ class YHAllApiName {
// 动态 // 动态
struct Dynamic { struct Dynamic {
static let list = "super-app/content/posts/list" static let list = "super-app/content/posts/list"
static let like = "super-app/content/posts/message-like" static let like = "super-app/content/posts/like"
static let publishCircle = "super-app/content/posts/add" static let publishCircle = "super-app/content/posts/add"
} }
......
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "circle_grey_heart@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "circle_grey_heart@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "circle_red_heart@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "circle_red_heart@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment