456 lines
17 KiB
Swift
456 lines
17 KiB
Swift
//
|
|
// HomeVoiceUserInfoView.swift
|
|
// yinmeng-ios
|
|
//
|
|
// Created by yinmeng on 2024/2/29.
|
|
//
|
|
|
|
import UIKit
|
|
import Nuke
|
|
|
|
|
|
typealias ClickBtnBlock = (_ type: Int ,_ uid:String)->Void
|
|
|
|
|
|
class HomeVoiceUserInfoView: UIView {
|
|
var clickBtnBlock:ClickBtnBlock?
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
setUILayout()
|
|
self.dissView.addTarget(self, action: #selector(dissViewAction), for: .touchUpInside)
|
|
}
|
|
func setUILayout(){
|
|
backgroundColor = UIColor(white: 0, alpha: 0.8)
|
|
addSubview(dissView)
|
|
addSubview(backgroundView)
|
|
addSubview(avatarView)
|
|
addSubview(sexImageView)
|
|
backgroundView.addSubview(nameTextView)
|
|
backgroundView.addSubview(starView)
|
|
backgroundView.addSubview(bgSignatureView)
|
|
bgSignatureView.addSubview(signatureView)
|
|
bgSignatureView.addSubview(bgVoiceVeiw)
|
|
bgVoiceVeiw.addSubview(playBtn)
|
|
bgVoiceVeiw.addSubview(waveView)
|
|
bgVoiceVeiw.addSubview(playTimeView)
|
|
|
|
|
|
backgroundView.addSubview(lineView)
|
|
backgroundView.addSubview(tagStackView)
|
|
tagStackView.addArrangedSubview(attentionBtn)
|
|
tagStackView.addArrangedSubview(lineView1)
|
|
tagStackView.addArrangedSubview(sendGfitBtn)
|
|
tagStackView.addArrangedSubview(lineView2)
|
|
tagStackView.addArrangedSubview(chatBtn)
|
|
|
|
dissView.snp.makeConstraints { make in
|
|
make.edges.equalTo(self)
|
|
}
|
|
backgroundView.snp.makeConstraints { make in
|
|
make.center.equalTo(self)
|
|
make.width.equalTo(303)
|
|
make.height.equalTo(275)
|
|
}
|
|
|
|
avatarView.snp.makeConstraints { make in
|
|
make.top.equalTo(self.backgroundView.snp.top).offset(-6)
|
|
make.width.height.equalTo(68)
|
|
make.left.equalTo(64)
|
|
}
|
|
|
|
sexImageView.snp.makeConstraints { make in
|
|
make.width.height.equalTo(16)
|
|
make.bottom.right.equalTo(self.avatarView)
|
|
}
|
|
|
|
nameTextView.snp.makeConstraints { make in
|
|
make.left.equalTo(self.avatarView.snp.right).offset(12)
|
|
make.top.equalTo(16)
|
|
make.right.equalTo(-10)
|
|
make.height.equalTo(21)
|
|
}
|
|
starView.snp.makeConstraints { make in
|
|
make.width.equalTo(46)
|
|
make.height.equalTo(18)
|
|
make.left.equalTo(self.nameTextView)
|
|
make.top.equalTo(self.nameTextView.snp.bottom).offset(4)
|
|
}
|
|
|
|
bgSignatureView.snp.makeConstraints { make in
|
|
make.top.equalTo(self.avatarView.snp.bottom).offset(10)
|
|
make.left.equalTo(16)
|
|
make.width.equalTo(271)
|
|
make.height.equalTo(128)
|
|
}
|
|
signatureView.snp.makeConstraints { make in
|
|
make.left.top.right.equalTo(self.bgSignatureView).inset(16)
|
|
make.height.equalTo(54)
|
|
}
|
|
|
|
bgVoiceVeiw.snp.makeConstraints { make in
|
|
make.left.equalTo(16)
|
|
make.top.equalTo(82)
|
|
make.width.greaterThanOrEqualTo(130)
|
|
make.height.equalTo(28)
|
|
}
|
|
playBtn.snp.makeConstraints { make in
|
|
make.width.height.equalTo(20)
|
|
make.left.equalTo(12)
|
|
make.centerY.equalTo(self.bgVoiceVeiw)
|
|
}
|
|
waveView.snp.makeConstraints { make in
|
|
make.width.equalTo(54)
|
|
make.height.equalTo(16)
|
|
make.left.equalTo(38)
|
|
make.centerY.equalTo(self.bgVoiceVeiw)
|
|
}
|
|
playTimeView.snp.makeConstraints { make in
|
|
make.left.equalTo(98)
|
|
make.height.equalTo(18)
|
|
make.centerY.equalTo(self.bgVoiceVeiw)
|
|
make.right.equalTo(-10)
|
|
}
|
|
lineView.snp.makeConstraints { make in
|
|
make.left.right.equalTo(self.backgroundView)
|
|
make.height.equalTo(1)
|
|
make.top.equalTo(self.bgSignatureView.snp.bottom).offset(16)
|
|
|
|
}
|
|
|
|
tagStackView.snp.makeConstraints { make in
|
|
make.leading.bottom.trailing.equalTo(backgroundView)
|
|
make.top.equalTo(230)
|
|
}
|
|
lineView1.snp.makeConstraints { make in
|
|
make.width.equalTo(1)
|
|
make.height.equalTo(18)
|
|
|
|
}
|
|
lineView2.snp.makeConstraints { make in
|
|
make.width.equalTo(1)
|
|
make.height.equalTo(18)
|
|
|
|
}
|
|
|
|
let layer = CAShapeLayer()
|
|
let path = UIBezierPath.init(roundedRect: CGRect(x: 0, y: 0, width: 130, height: 28), byRoundingCorners: [.topRight , .bottomRight,.bottomLeft] , cornerRadii: CGSize(width: 14, height: 14))
|
|
layer.path = path.cgPath
|
|
bgVoiceVeiw.layer.mask = layer
|
|
}
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
@objc func sendGiftBtnAction(){
|
|
if let _clickBtnBlock = clickBtnBlock,let uid = self.user?.uid{
|
|
_clickBtnBlock(5,"\(uid)")
|
|
self.removeFromSuperview()
|
|
}
|
|
}
|
|
@objc func attentionBtnAction(){
|
|
if self.type == 1{
|
|
if let _clickBtnBlock = clickBtnBlock,let uid = self.model?.uid{
|
|
_clickBtnBlock(3,"\(uid)")
|
|
}
|
|
|
|
return
|
|
}
|
|
self.attentionBtn.isSelected = !self.attentionBtn.isSelected
|
|
let type = self.attentionBtn.isSelected ? "1" : "2"
|
|
let uid = self.model != nil ? self.model?.uid : self.user?.uid
|
|
guard let getUid = uid else{return}
|
|
let params = ["uid":"\(AuthManager.userUid)","ticket":AuthManager.ticket,"type":type,"likedUid":"\(getUid)"] as [String : Any]
|
|
|
|
RequestPost(path: "fans/like", parma: params) { data in
|
|
if(self.attentionBtn.isSelected){
|
|
HUDTool.show(with: "关注成功")
|
|
}else{
|
|
HUDTool.show(with: "取消关注成功")
|
|
}
|
|
} fail: { code, data in
|
|
|
|
}
|
|
}
|
|
@objc func chatBtnAction(){
|
|
if self.type == 1{
|
|
if let _clickBtnBlock = clickBtnBlock,let uid = self.model?.uid{
|
|
_clickBtnBlock(4,"\(uid)")
|
|
}
|
|
|
|
return
|
|
}
|
|
if let _clickBtnBlock = clickBtnBlock, let uid = self.model?.uid{
|
|
_clickBtnBlock(0,"\(uid)")
|
|
}
|
|
if let _clickBtnBlock = clickBtnBlock, let uid = self.user?.uid{
|
|
_clickBtnBlock(0,"\(uid)")
|
|
}
|
|
|
|
}
|
|
@objc func playVoiceAction(){
|
|
guard let userVoice = self.model?.userVoice else {
|
|
return
|
|
}
|
|
self.playBtn.isSelected = !self.playBtn.isSelected
|
|
if (self.playBtn.isSelected){
|
|
PlayVoiceManager.shared.downloadVoice(url: userVoice)
|
|
}else{
|
|
PlayVoiceManager.shared.stopPlayVoice()
|
|
}
|
|
|
|
}
|
|
var user:UserObject? = nil{
|
|
didSet{
|
|
guard let _user = user else { return }
|
|
Nuke.loadImage(with: _user.avatar, into: avatarView)
|
|
nameTextView.text = _user.nick
|
|
sexImageView.image = _user.gender == .Boy ? UIImage(named: "yin_plane_star_man") : UIImage(named: "yin_plane_star__woman")
|
|
|
|
|
|
signatureView.text = _user.userDesc.isEmpty ? "这个人很懒还没有签名" : _user.userDesc
|
|
bgVoiceVeiw.isHidden = true
|
|
guard let uid = _user.uid else{return}
|
|
let params = ["uid":uid]
|
|
RequestGet(path: "user/get", parma: params) { data in
|
|
if let info = Deserialized<UserObject>.toModel(with: data) {
|
|
self.signatureView.text = info.userDesc.isEmpty ? "这个人很懒还没有签名" : info.userDesc
|
|
let timeStamp = info.birth / 1000
|
|
|
|
let timeInterval:TimeInterval = TimeInterval(timeStamp)
|
|
|
|
let date = NSDate(timeIntervalSince1970: timeInterval) as Date
|
|
self.starView.text = Date.getCalculateWithDate(date: date)
|
|
self.starView.isHidden = false
|
|
}
|
|
} fail: { code, message in
|
|
|
|
}
|
|
RequestGet(path: "fans/islike", parma: ["uid":"\(AuthManager.userUid)","isLikeUid":"\(uid)"]) { data in
|
|
if let isLike = data as? Bool{
|
|
self.attentionBtn.isSelected = isLike
|
|
}
|
|
|
|
} fail: { code, data in
|
|
|
|
}
|
|
}
|
|
}
|
|
var model:HomeVoiceModel? = nil {
|
|
didSet{
|
|
guard let _model = model else {
|
|
return
|
|
}
|
|
Nuke.loadImage(with: _model.avatar, into: avatarView)
|
|
nameTextView.text = _model.nick
|
|
sexImageView.image = _model.gender == 1 ? UIImage(named: "yin_plane_star_man") : UIImage(named: "yin_plane_star__woman")
|
|
let timeStamp = _model.birth / 1000
|
|
|
|
let timeInterval:TimeInterval = TimeInterval(timeStamp)
|
|
|
|
let date = NSDate(timeIntervalSince1970: timeInterval) as Date
|
|
starView.text = Date.getCalculateWithDate(date: date)
|
|
|
|
|
|
|
|
starView.isHidden = false
|
|
signatureView.text = _model.userDesc.isEmpty ? "这个人很懒还没有签名" : _model.userDesc
|
|
bgVoiceVeiw.isHidden = _model.userVoice.isEmpty
|
|
playTimeView.text = "\(_model.voiceDura)\""
|
|
|
|
|
|
guard let uid = self.model?.uid else{return}
|
|
RequestGet(path: "fans/islike", parma: ["uid":"\(AuthManager.userUid)","isLikeUid":"\(uid)"]) { data in
|
|
if let isLike = data as? Bool{
|
|
self.attentionBtn.isSelected = isLike
|
|
}
|
|
|
|
} fail: { code, data in
|
|
|
|
}
|
|
}
|
|
}
|
|
@objc func dissViewAction(){
|
|
self.removeFromSuperview()
|
|
PlayVoiceManager.shared.stopPlayVoice()
|
|
}
|
|
var dissView:UIButton = {
|
|
let _dissView = UIButton()
|
|
|
|
return _dissView
|
|
}()
|
|
var backgroundView:UIView = {
|
|
let _backgroundView = UIView()
|
|
_backgroundView.backgroundColor = ThemeColor(hexStr: "#525566", alpha: 0.8)
|
|
_backgroundView.layer.cornerRadius = 16
|
|
_backgroundView.layer.masksToBounds = true
|
|
return _backgroundView
|
|
}()
|
|
|
|
var avatarView:UIImageView = {
|
|
let _avatarView = UIImageView()
|
|
|
|
_avatarView.isUserInteractionEnabled = true
|
|
_avatarView.layer.cornerRadius = 68/2;
|
|
_avatarView.layer.masksToBounds = true
|
|
_avatarView.layer.borderWidth = 2
|
|
_avatarView.layer.borderColor = UIColor.white.cgColor
|
|
return _avatarView
|
|
}()
|
|
var sexImageView:UIImageView = {
|
|
let _sexImageView = UIImageView()
|
|
|
|
return _sexImageView
|
|
}()
|
|
var nameTextView:UILabel = {
|
|
let _nameTextView = UILabel()
|
|
_nameTextView.textColor = .white
|
|
_nameTextView.font = UIFont.systemFont(ofSize: 15, weight: .medium)
|
|
return _nameTextView
|
|
}()
|
|
|
|
var starView:UILabel = {
|
|
let _starView = UILabel()
|
|
_starView.font = UIFont.systemFont(ofSize: 10, weight: .regular)
|
|
_starView.textColor = ThemeColor(hexStr: "#9168FA")
|
|
_starView.textAlignment = .center
|
|
_starView.backgroundColor = ThemeColor(hexStr: "#E9E1FF")
|
|
_starView.layer.cornerRadius = 9
|
|
_starView.layer.masksToBounds = true
|
|
_starView.isHidden = true
|
|
return _starView
|
|
}()
|
|
var bgSignatureView:UIView = {
|
|
let _bgSignatureView = UIView()
|
|
_bgSignatureView.backgroundColor = ThemeColor(hexStr: "#DCDDE0")
|
|
_bgSignatureView.layer.cornerRadius = 11
|
|
_bgSignatureView.layer.masksToBounds = true
|
|
return _bgSignatureView
|
|
}()
|
|
var signatureView:UILabel = {
|
|
let _signatureView = UILabel()
|
|
_signatureView.font = UIFont.systemFont(ofSize: 13, weight: .regular)
|
|
_signatureView.textColor = ThemeColor(hexStr: "#1F1B4F")
|
|
_signatureView.text = ""
|
|
|
|
_signatureView.numberOfLines = 0
|
|
return _signatureView
|
|
}()
|
|
|
|
|
|
var bgVoiceVeiw:UIView = {
|
|
let _bgVoiceVeiw = UIView()
|
|
_bgVoiceVeiw.backgroundColor = .white
|
|
return _bgVoiceVeiw
|
|
}()
|
|
var playBtn:UIButton = {
|
|
let _playBtn = UIButton()
|
|
_playBtn.setImage(UIImage(named: "yin_home_voice_no_play_voice"), for: .normal)
|
|
_playBtn.setImage(UIImage(named: "yin_home_voice_play_voice"), for: .selected)
|
|
_playBtn.addTarget(self, action: #selector(playVoiceAction), for: .touchUpInside)
|
|
return _playBtn
|
|
}()
|
|
var waveView:UIImageView = {
|
|
let _waveView = UIImageView()
|
|
_waveView.image = UIImage(named: "yin_home_voice_wave_icon")
|
|
return _waveView
|
|
}()
|
|
var playTimeView:UILabel = {
|
|
let _playTimeView = UILabel()
|
|
_playTimeView.text = "0\""
|
|
_playTimeView.textColor = ThemeColor(hexStr: "#1F1B4F")
|
|
_playTimeView.font = UIFont.systemFont(ofSize: 14, weight: .medium)
|
|
return _playTimeView
|
|
}()
|
|
|
|
var type:Int = 0 {
|
|
didSet{
|
|
lineView2.isHidden = true
|
|
sendGfitBtn.isHidden = true
|
|
if type == 0{
|
|
attentionBtn.setImage(UIImage(named: "yin_plane_star_no_attention_icon"), for: .normal)
|
|
attentionBtn.setTitle(" 关注", for: .normal)
|
|
chatBtn.setImage(UIImage(named: "yin_home_voice_chat_icon"), for: .normal)
|
|
chatBtn.setTitle(" 私聊", for: .normal)
|
|
}else if type == 1{
|
|
attentionBtn.setImage(UIImage(named: "yin_plane_star_pay_icon"), for: .normal)
|
|
attentionBtn.setTitle(" 充值", for: .normal)
|
|
chatBtn.setImage(UIImage(named: "yin_home_voice_collect_icon"), for: .normal)
|
|
chatBtn.setTitle(" 收藏", for: .normal)
|
|
}else{
|
|
attentionBtn.setImage(UIImage(named: "yin_plane_star_no_attention_icon"), for: .normal)
|
|
attentionBtn.setTitle(" 关注", for: .normal)
|
|
chatBtn.setImage(UIImage(named: "yin_home_voice_chat_icon"), for: .normal)
|
|
chatBtn.setTitle(" 私聊", for: .normal)
|
|
lineView2.isHidden = false
|
|
sendGfitBtn.isHidden = false
|
|
}
|
|
}
|
|
}
|
|
private lazy var tagStackView:UIStackView = {
|
|
let _tagStackView = UIStackView()
|
|
_tagStackView.axis = .horizontal
|
|
_tagStackView.distribution = .fillProportionally
|
|
_tagStackView.alignment = .center
|
|
_tagStackView.spacing = UIDevice.scaleWidth(width: 0)
|
|
return _tagStackView
|
|
}()
|
|
var attentionBtn:UIButton = {
|
|
let _attentionBtn = UIButton()
|
|
|
|
_attentionBtn.setImage(UIImage(named: "yin_plane_star_no_attention_icon"), for: .normal)
|
|
_attentionBtn.setTitle(" 关注", for: .normal)
|
|
_attentionBtn.setTitleColor(.white, for: .normal)
|
|
|
|
_attentionBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: .medium)
|
|
_attentionBtn.setImage(UIImage(named: "yin_plane_star_attention_icon"), for: .selected)
|
|
_attentionBtn.addTarget(self, action: #selector(attentionBtnAction), for: .touchUpInside)
|
|
return _attentionBtn
|
|
|
|
|
|
}()
|
|
var sendGfitBtn:UIButton = {
|
|
let _sendGfitBtn = UIButton()
|
|
|
|
_sendGfitBtn.setImage(UIImage(named: "yin_plane_star_send_gift_icon"), for: .normal)
|
|
_sendGfitBtn.setTitle(" 送礼", for: .normal)
|
|
_sendGfitBtn.setTitleColor(.white, for: .normal)
|
|
|
|
_sendGfitBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: .medium)
|
|
_sendGfitBtn.setImage(UIImage(named: "yin_plane_star_send_gift_icon"), for: .selected)
|
|
_sendGfitBtn.addTarget(self, action: #selector(sendGiftBtnAction), for: .touchUpInside)
|
|
return _sendGfitBtn
|
|
|
|
|
|
}()
|
|
var chatBtn:UIButton = {
|
|
let _chatBtn = UIButton()
|
|
|
|
_chatBtn.setImage(UIImage(named: "yin_home_voice_chat_icon"), for: .normal)
|
|
_chatBtn.setTitle(" 私聊", for: .normal)
|
|
_chatBtn.setTitleColor(.white, for: .normal)
|
|
_chatBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: .medium)
|
|
_chatBtn.addTarget(self, action: #selector(chatBtnAction), for: .touchUpInside)
|
|
return _chatBtn
|
|
}()
|
|
var lineView:UIView = {
|
|
let _lineView = UIView()
|
|
_lineView.backgroundColor = UIColor.init(white: 1, alpha: 0.2)
|
|
return _lineView
|
|
|
|
|
|
}()
|
|
var lineView1:UIView = {
|
|
let _lineView1 = UIView()
|
|
_lineView1.backgroundColor = UIColor.init(white: 1, alpha: 0.2)
|
|
return _lineView1
|
|
|
|
|
|
}()
|
|
var lineView2:UIView = {
|
|
let _lineView2 = UIView()
|
|
_lineView2.backgroundColor = UIColor.init(white: 1, alpha: 0.2)
|
|
return _lineView2
|
|
|
|
|
|
}()
|
|
}
|