Commit d4bc80e4 authored by Alex朱枝文's avatar Alex朱枝文

直播优化相关

parent dc8d8474
......@@ -57,6 +57,12 @@
04307BA32D1E4CA600ED8E8D /* YHGCInformationFillTipsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04307BA22D1E4CA600ED8E8D /* YHGCInformationFillTipsCell.swift */; };
04307BA52D1E54BD00ED8E8D /* YHGCInformationFillTipsAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04307BA42D1E54BD00ED8E8D /* YHGCInformationFillTipsAlertView.swift */; };
04307BA82D1FDF5200ED8E8D /* YHGCPreviewIncomeTypeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04307BA72D1FDF5200ED8E8D /* YHGCPreviewIncomeTypeCell.swift */; };
04307BAA2D1FF74500ED8E8D /* YHRecommendLiveListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04307BA92D1FF74500ED8E8D /* YHRecommendLiveListModel.swift */; };
04307BAC2D1FFC1C00ED8E8D /* YHShareLiveInfoModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04307BAB2D1FFC1C00ED8E8D /* YHShareLiveInfoModel.swift */; };
04307BAE2D1FFEA200ED8E8D /* YHLiveAppointmentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04307BAD2D1FFEA200ED8E8D /* YHLiveAppointmentViewController.swift */; };
04307BB02D215D1C00ED8E8D /* YHRecommendedLiveHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04307BAF2D215D1C00ED8E8D /* YHRecommendedLiveHeader.swift */; };
04307BB42D21623300ED8E8D /* YHRecommendedAppointmentLiveView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04307BB32D21623300ED8E8D /* YHRecommendedAppointmentLiveView.swift */; };
04307BB62D2180C300ED8E8D /* YHRecommendedOnLiveView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04307BB52D2180C300ED8E8D /* YHRecommendedOnLiveView.swift */; };
045C0F7F2D12CA5F00BD2DC0 /* submit_page_scroll.gif in Resources */ = {isa = PBXBuildFile; fileRef = 045C0F4F2D12CA5E00BD2DC0 /* submit_page_scroll.gif */; };
045C0F802D12CA5F00BD2DC0 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 045C0F762D12CA5E00BD2DC0 /* Localizable.xcstrings */; };
045C0F812D12CA5F00BD2DC0 /* img_0.png in Resources */ = {isa = PBXBuildFile; fileRef = 045C0F5E2D12CA5E00BD2DC0 /* img_0.png */; };
......@@ -1266,6 +1272,12 @@
04307BA22D1E4CA600ED8E8D /* YHGCInformationFillTipsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHGCInformationFillTipsCell.swift; sourceTree = "<group>"; };
04307BA42D1E54BD00ED8E8D /* YHGCInformationFillTipsAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHGCInformationFillTipsAlertView.swift; sourceTree = "<group>"; };
04307BA72D1FDF5200ED8E8D /* YHGCPreviewIncomeTypeCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHGCPreviewIncomeTypeCell.swift; sourceTree = "<group>"; };
04307BA92D1FF74500ED8E8D /* YHRecommendLiveListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHRecommendLiveListModel.swift; sourceTree = "<group>"; };
04307BAB2D1FFC1C00ED8E8D /* YHShareLiveInfoModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHShareLiveInfoModel.swift; sourceTree = "<group>"; };
04307BAD2D1FFEA200ED8E8D /* YHLiveAppointmentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHLiveAppointmentViewController.swift; sourceTree = "<group>"; };
04307BAF2D215D1C00ED8E8D /* YHRecommendedLiveHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHRecommendedLiveHeader.swift; sourceTree = "<group>"; };
04307BB32D21623300ED8E8D /* YHRecommendedAppointmentLiveView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHRecommendedAppointmentLiveView.swift; sourceTree = "<group>"; };
04307BB52D2180C300ED8E8D /* YHRecommendedOnLiveView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHRecommendedOnLiveView.swift; sourceTree = "<group>"; };
045C09A12D12C2A800BD2DC0 /* YHGCMineSchemeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHGCMineSchemeViewController.swift; sourceTree = "<group>"; };
045C0A142D12CA5E00BD2DC0 /* YHBaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHBaseViewController.swift; sourceTree = "<group>"; };
045C0A152D12CA5E00BD2DC0 /* YHBaseViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHBaseViewModel.swift; sourceTree = "<group>"; };
......@@ -5403,6 +5415,7 @@
isa = PBXGroup;
children = (
045C0E7D2D12CA5E00BD2DC0 /* YHBasePlayerViewController.swift */,
04307BAD2D1FFEA200ED8E8D /* YHLiveAppointmentViewController.swift */,
045C0E7E2D12CA5E00BD2DC0 /* YHFloatingWindow.swift */,
045C0E7F2D12CA5E00BD2DC0 /* YHLivePlayerViewController.swift */,
045C0E802D12CA5E00BD2DC0 /* YHLivePlayerViewController+Api.swift */,
......@@ -5435,6 +5448,8 @@
045C0E912D12CA5E00BD2DC0 /* YHLivePeopleModel.swift */,
045C0E922D12CA5E00BD2DC0 /* YHMediaProtocolUtils.swift */,
045C0E932D12CA5E00BD2DC0 /* YHRecordedDetailModel.swift */,
04307BA92D1FF74500ED8E8D /* YHRecommendLiveListModel.swift */,
04307BAB2D1FFC1C00ED8E8D /* YHShareLiveInfoModel.swift */,
);
path = M;
sourceTree = "<group>";
......@@ -5454,6 +5469,9 @@
045C0E9E2D12CA5E00BD2DC0 /* YHPlayerTopBarView.swift */,
045C0E9F2D12CA5E00BD2DC0 /* YHShareAlertView.swift */,
045C0EA02D12CA5E00BD2DC0 /* YHVideoProgressControl.swift */,
04307BAF2D215D1C00ED8E8D /* YHRecommendedLiveHeader.swift */,
04307BB32D21623300ED8E8D /* YHRecommendedAppointmentLiveView.swift */,
04307BB52D2180C300ED8E8D /* YHRecommendedOnLiveView.swift */,
);
path = V;
sourceTree = "<group>";
......@@ -6916,6 +6934,7 @@
045C102D2D12CA5F00BD2DC0 /* YHHKEventModel.swift in Sources */,
045C102E2D12CA5F00BD2DC0 /* YHOfficailLetterColledtionCell.swift in Sources */,
045C102F2D12CA5F00BD2DC0 /* YHFormItemInputTextCell.swift in Sources */,
04307BAE2D1FFEA200ED8E8D /* YHLiveAppointmentViewController.swift in Sources */,
045C10302D12CA5F00BD2DC0 /* YHFamilyInfoWarmTipsView.swift in Sources */,
045C10312D12CA5F00BD2DC0 /* YHSpouseInfoContainerVC.swift in Sources */,
045C10322D12CA5F00BD2DC0 /* YHRecommendTextMessageCell.swift in Sources */,
......@@ -7155,6 +7174,7 @@
045C11082D12CA5F00BD2DC0 /* YHServerCenterHoldViewController.swift in Sources */,
045C11092D12CA5F00BD2DC0 /* YHResignCertificateListViewModel.swift in Sources */,
045C110A2D12CA5F00BD2DC0 /* YHResignDocumentListModel.swift in Sources */,
04307BB62D2180C300ED8E8D /* YHRecommendedOnLiveView.swift in Sources */,
045C110B2D12CA5F00BD2DC0 /* YHInformationPerfectCell.swift in Sources */,
045C110C2D12CA5F00BD2DC0 /* YHOrderTipsItemView.swift in Sources */,
045C110D2D12CA5F00BD2DC0 /* YHConfigModel.swift in Sources */,
......@@ -7176,6 +7196,7 @@
045C111D2D12CA5F00BD2DC0 /* YHResignInfoValidTimeItemView.swift in Sources */,
045C111E2D12CA5F00BD2DC0 /* YHPreviewAcademicAndProfessionalQualificationViewController.swift in Sources */,
045C111F2D12CA5F00BD2DC0 /* YHWorkExperienceTableViewCell.swift in Sources */,
04307BAA2D1FF74500ED8E8D /* YHRecommendLiveListModel.swift in Sources */,
0411CF182D1D502D00644D35 /* YHlifeCollectionReusableView.swift in Sources */,
045C11202D12CA5F00BD2DC0 /* UITextField+Extension.swift in Sources */,
045C11212D12CA5F00BD2DC0 /* YHPlayer.swift in Sources */,
......@@ -7241,11 +7262,13 @@
045C11572D12CA5F00BD2DC0 /* YHCountryHotView.swift in Sources */,
045C11582D12CA5F00BD2DC0 /* YHPreviewBaseViewController.swift in Sources */,
045C11592D12CA5F00BD2DC0 /* YHAITextMessageCell.swift in Sources */,
04307BB02D215D1C00ED8E8D /* YHRecommendedLiveHeader.swift in Sources */,
045C115A2D12CA5F00BD2DC0 /* YHScemeItemModel.swift in Sources */,
045C115B2D12CA5F00BD2DC0 /* YHHKRecordItemDetailType.swift in Sources */,
045C115C2D12CA5F00BD2DC0 /* YHHUDContainerView.swift in Sources */,
045C115D2D12CA5F00BD2DC0 /* YHOrderTipsView.swift in Sources */,
04AE203F2D13C36500891D24 /* YHGCQualificationDetailVC.swift in Sources */,
04307BAC2D1FFC1C00ED8E8D /* YHShareLiveInfoModel.swift in Sources */,
045C115E2D12CA5F00BD2DC0 /* YHInvitationWithGiftsSelectItemView.swift in Sources */,
045C115F2D12CA5F00BD2DC0 /* YHAITabIndicatorView.swift in Sources */,
0411CEEF2D151E5F00644D35 /* YHGCWorkListHasDocTableViewCell.swift in Sources */,
......@@ -7370,6 +7393,7 @@
045C11CF2D12CA5F00BD2DC0 /* YHSelectFileSheetView.swift in Sources */,
045C11D02D12CA5F00BD2DC0 /* YHIdentityCardCell.swift in Sources */,
045C11D12D12CA5F00BD2DC0 /* UINavigationController+Extension.swift in Sources */,
04307BB42D21623300ED8E8D /* YHRecommendedAppointmentLiveView.swift in Sources */,
045C11D22D12CA5F00BD2DC0 /* YHPrincipleWaitResultViewController.swift in Sources */,
045C11D32D12CA5F00BD2DC0 /* YHInvitationWithGiftsShareBottomView.swift in Sources */,
045C11D42D12CA5F00BD2DC0 /* YHPreviewInfoSingleLineTitleView.swift in Sources */,
......
......@@ -88,7 +88,13 @@ extension YHlifeCollectionReusableView: UITableViewDelegate, UITableViewDataSour
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
guard let dataSource = dataSource, dataSource.count > indexPath.row else {
return
}
let model = dataSource[indexPath.row]
let ctl = YHLiveAppointmentViewController(liveId: model.live_id)
UIViewController.current?.navigationController?.pushViewController(ctl)
}
}
......
//
// YHLiveAppointmentViewController.swift
// galaxy
//
// Created by alexzzw on 2024/12/28.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHLiveAppointmentViewController: YHBaseViewController {
private let viewModel = YHLiveSalesViewModel()
private lazy var topImageView: UIImageView = {
let view = UIImageView()
view.contentMode = .scaleAspectFit
return view
}()
private lazy var centerContainerView: YHBaseDynamicCornerRadiusView = {
let view = YHBaseDynamicCornerRadiusView(cornerRadius: 6, corner: .allCorners)
view.backgroundColor = .white
return view
}()
private lazy var flagLabel: YHPaddedLabel = {
let label = YHPaddedLabel(padding: UIEdgeInsets(top: 2, left: 4, bottom: 2, right: 4))
label.text = "预告"
label.font = .PFSC_R(ofSize: 10)
label.backgroundColor = .brandMainColor
label.textColor = .white
return label
}()
private lazy var liveNameLabel: UILabel = {
let label = UILabel()
label.font = .PFSC_B(ofSize: 16)
label.textColor = .mainTextColor
return label
}()
private lazy var avatarImageView: UIImageView = {
let view = UIImageView()
view.contentMode = .scaleAspectFit
view.clipsToBounds = true
view.layer.cornerRadius = 10
return view
}()
private lazy var anchorLabel: UILabel = {
let label = UILabel()
label.font = .PFSC_R(ofSize: 12)
label.textColor = UIColor(hexString: "#435163")
return label
}()
private lazy var subContainerView: UIView = {
let view = UIView()
view.backgroundColor = .contentBkgColor
return view
}()
private lazy var infoContentLabel: UILabel = {
let label = UILabel()
label.font = .PFSC_R(ofSize: 12)
label.textColor = UIColor(hexString: "#435163")
label.numberOfLines = 0
label.lineBreakMode = .byCharWrapping
return label
}()
private lazy var infoTimeLabel: UILabel = {
let label = UILabel()
label.font = .PFSC_B(ofSize: 14)
label.textColor = UIColor.brandMainColor
return label
}()
private lazy var appointmentButton: UIButton = {
let button = UIButton(type: .custom)
button.titleLabel?.font = UIFont.PFSC_M(ofSize: 16)
button.setTitle("立即预约", for: .normal)
button.setTitle("立即预约", for: .highlighted)
button.setTitleColor(UIColor(hex: 0xFFFFFF), for: .normal)
button.setTitleColor(UIColor(hex: 0xFFFFFF), for: .highlighted)
button.addTarget(self, action: #selector(clickAppointmentButton), for: .touchUpInside)
button.layer.cornerRadius = kCornerRadius3
button.clipsToBounds = true
button.backgroundColor = .brandMainColor
return button
}()
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
getLiveInfo()
}
private let liveId: Int
init(liveId: Int) {
self.liveId = liveId
super.init(nibName: nil, bundle: nil)
}
@MainActor required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI() {
gk_navTitle = "直播预约"
gk_navBarAlpha = 1.0
gk_navBackgroundColor = .white
view.backgroundColor = UIColor.contentBkgColor
view.addSubview(topImageView)
view.addSubview(centerContainerView)
centerContainerView.addSubview(flagLabel)
centerContainerView.addSubview(liveNameLabel)
centerContainerView.addSubview(avatarImageView)
centerContainerView.addSubview(anchorLabel)
centerContainerView.addSubview(subContainerView)
subContainerView.addSubview(infoContentLabel)
centerContainerView.addSubview(infoTimeLabel)
centerContainerView.addSubview(appointmentButton)
topImageView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(k_Height_NavigationtBarAndStatuBar)
make.width.equalTo(topImageView.snp.height)
}
centerContainerView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16)
make.right.equalToSuperview().offset(-16)
make.top.equalTo(topImageView.snp.bottom).offset(-74)
}
flagLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
liveNameLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
flagLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16)
make.top.equalToSuperview().offset(18)
}
liveNameLabel.snp.makeConstraints { make in
make.left.equalTo(flagLabel.snp.right).offset(8)
make.centerY.equalTo(flagLabel)
make.right.lessThanOrEqualToSuperview().offset(-16)
}
avatarImageView.snp.makeConstraints { make in
make.left.equalTo(flagLabel)
make.top.equalTo(flagLabel.snp.bottom).offset(10)
make.width.height.equalTo(20)
}
anchorLabel.snp.makeConstraints { make in
make.left.equalTo(avatarImageView.snp.right).offset(4)
make.centerY.equalTo(avatarImageView)
make.right.lessThanOrEqualToSuperview().offset(-16)
}
subContainerView.snp.makeConstraints { make in
make.left.equalTo(flagLabel)
make.right.equalToSuperview().offset(-16)
make.top.equalTo(avatarImageView.snp.bottom).offset(8)
}
infoContentLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(12)
make.left.equalToSuperview().offset(12)
make.right.lessThanOrEqualToSuperview().offset(-12)
make.bottom.equalToSuperview().offset(-12)
}
infoTimeLabel.snp.makeConstraints { make in
make.left.equalTo(flagLabel)
make.top.equalTo(subContainerView.snp.bottom).offset(12)
make.right.lessThanOrEqualToSuperview().offset(-16)
}
appointmentButton.snp.makeConstraints { make in
make.left.equalTo(flagLabel)
make.top.equalTo(infoTimeLabel.snp.bottom).offset(16)
make.right.equalToSuperview().offset(-16)
make.height.equalTo(46)
make.bottom.equalToSuperview().offset(-16)
}
}
private func updateViews(_ liveInfo: YHShareLiveInfoModel) {
if let url = URL(string: liveInfo.image) {
topImageView.kf.setImage(with: url, placeholder: UIImage(named: "global_default_image"))
} else {
topImageView.image = UIImage(named: "global_default_image")
}
if let url = URL(string: liveInfo.avatar) {
avatarImageView.kf.setImage(with: url, placeholder: UIImage(named: "global_default_image"))
} else {
avatarImageView.image = UIImage(named: "global_default_image")
}
liveNameLabel.text = liveInfo.title
anchorLabel.text = liveInfo.account
let content = ""
infoContentLabel.text = content
if content.isEmpty {
infoContentLabel.snp.remakeConstraints { make in
make.top.equalToSuperview().offset(0)
make.left.equalToSuperview().offset(12)
make.right.lessThanOrEqualToSuperview().offset(-12)
make.bottom.equalToSuperview().offset(0)
}
} else {
infoContentLabel.snp.remakeConstraints { make in
make.top.equalToSuperview().offset(12)
make.left.equalToSuperview().offset(12)
make.right.lessThanOrEqualToSuperview().offset(-12)
make.bottom.equalToSuperview().offset(-12)
}
}
infoTimeLabel.text = "直播时间:" + liveInfo.start_time + "~" + liveInfo.end_time
updateAppointmentButton(!liveInfo.is_schedule_live)
}
private func updateAppointmentButton(_ isEnable: Bool) {
appointmentButton.isEnabled = isEnable
appointmentButton.backgroundColor = isEnable ? .brandMainColor : UIColor(hexString: "#B3C8E9")
appointmentButton.setTitle(isEnable ? "立即预约" : "已预约", for: .normal)
}
@objc private func clickAppointmentButton() {
bookLive()
}
private func getLiveInfo() {
YHHUD.show(.progress(message: "加载中..."))
viewModel.getShareLiveInfo(liveId: liveId, shareType: 1) { [weak self] liveInfo, error in
guard let self = self else {
return
}
YHHUD.hide()
guard let liveInfo = liveInfo else {
if let errorMsg = error?.errorMsg, errorMsg.count > 0 {
YHHUD.flash(message: errorMsg)
}
return
}
self.updateViews(liveInfo)
}
}
private func bookLive() {
YHHUD.show(.progress(message: "加载中..."))
viewModel.postLiveBook(id: liveId) { [weak self] success, error in
guard let self = self else {
return
}
YHHUD.hide()
if success {
self.updateAppointmentButton(false)
} else {
if let errorMsg = error?.errorMsg, errorMsg.count > 0 {
YHHUD.flash(message: errorMsg)
}
}
}
}
}
......@@ -71,6 +71,12 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
UIViewController.current?.navigationController?.popToRootViewController(animated: false)
goTabBarBy(tabType: .home)
}
vc.backHomeLivePage = { [weak self] in
self?.closeLive()
UIViewController.current?.navigationController?.popToRootViewController(animated: false)
goTabBarBy(tabType: .home)
NotificationCenter.default.post(name: YhConstant.YhNotification.didJumpToHomePageLifeTabNotification, object: nil)
}
return vc
}()
......
......@@ -30,9 +30,25 @@ class YHLiveStateViewController: YHBaseViewController {
var getCodeButton: UIButton!
var state: YHLiveState = .start
private lazy var bottomView: UIView = {
let view = UIView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: 260))
view.isHidden = true
return view
}()
private lazy var recommendHeader: YHRecommendedLiveHeader = {
let view = YHRecommendedLiveHeader(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: 20))
view.moreButtonEvent = { [weak self] in
self?.backHomeLivePage?()
}
return view
}()
var shareEvent: (() -> Void)?
var closeEvent: (() -> Void)?
var backHomeEvent: (() -> Void)?
var backHomeLivePage: (() -> Void)?
private let viewModel = YHLiveSalesViewModel()
override func viewDidLoad() {
super.viewDidLoad()
......@@ -204,6 +220,17 @@ class YHLiveStateViewController: YHBaseViewController {
make.top.equalTo(messageLabel.snp.bottom).offset(32)
make.height.equalTo(40)
}
view.addSubview(bottomView)
bottomView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(lineView.snp.bottom).offset(120)
make.bottom.lessThanOrEqualTo(view.safeAreaLayoutGuide.snp.bottom)
}
bottomView.addSubview(recommendHeader)
recommendHeader.snp.makeConstraints { make in
make.top.left.right.equalToSuperview()
make.height.equalTo(20)
}
}
@objc func share() {
......@@ -222,14 +249,17 @@ class YHLiveStateViewController: YHBaseViewController {
loginSubTitleLabel.text = "直播暂未开始"
messageLabel.text = "预计\(liveDetail.start_time)开始~"
getCodeButton.isHidden = true
bottomView.isHidden = true
case .stop:
loginSubTitleLabel.text = "主播离开了"
messageLabel.text = "主播暂时离开,请稍等片刻~"
getCodeButton.isHidden = true
bottomView.isHidden = true
case .end:
loginSubTitleLabel.text = "直播已结束"
messageLabel.text = "直播已结束,去首页逛逛吧~"
getCodeButton.isHidden = false
getRecommendLiveList()
case .onLive, .unknown:
break
}
......@@ -238,4 +268,97 @@ class YHLiveStateViewController: YHBaseViewController {
@objc func backHome() {
backHomeEvent?()
}
private func getRecommendLiveList() {
YHHUD.show(.progress(message: "加载中..."))
viewModel.getRecommendLiveList { [weak self] liveListInfo, error in
guard let self = self else {
return
}
YHHUD.hide()
guard let liveListInfo = liveListInfo, liveListInfo.live_list.count > 0 else {
bottomView.isHidden = true
messageLabel.isHidden = false
getCodeButton.isHidden = false
return
}
bottomView.isHidden = false
messageLabel.isHidden = true
getCodeButton.isHidden = true
bottomView.subviews.forEach { view in
if view != self.recommendHeader {
view.removeFromSuperview()
}
}
let arr = Array(liveListInfo.live_list.prefix(2))
let hOffset: CGFloat = 20
let midOffset: CGFloat = 10
let liveWidth = (KScreenWidth - 2 * hOffset - midOffset) / 2.0
arr.enumerated().forEach { index, model in
if model.status == 1 {
let view = YHRecommendedOnLiveView()
view.buttonClickEvent = {
let playbackInfo = YHPlayerManager.PlaybackInfo(id: model.live_id, url: nil, title: model.title, roomId: nil, uid: nil, isLive: true, scene: .fullscreen)
YHPlayerManager.shared.enterLive(from: nil, playbackInfo: playbackInfo)
}
self.bottomView.addSubview(view)
view.snp.makeConstraints { make in
if index == 0 {
make.left.equalToSuperview().offset(hOffset)
} else {
make.right.equalToSuperview().offset(-hOffset)
}
make.width.height.equalTo(liveWidth)
make.top.equalTo(self.recommendHeader.snp.bottom).offset(16)
make.bottom.equalToSuperview()
}
view.updateViews(avatar: model.avatarurl, anchorName: model.account, image: model.image)
} else if model.status == 2 {
let view = YHRecommendedAppointmentLiveView()
view.appointmentButtonEvent = { [weak self, weak view] in
guard let self = self else {
return
}
guard let view = view else {
return
}
self.bookLive(liveId: model.live_id, liveView: view)
}
view.buttonClickEvent = {
let ctl = YHLiveAppointmentViewController(liveId: model.live_id)
UIViewController.current?.navigationController?.pushViewController(ctl)
}
self.bottomView.addSubview(view)
view.snp.makeConstraints { make in
if index == 0 {
make.top.equalTo(self.recommendHeader.snp.bottom).offset(20)
} else {
make.top.equalTo(self.recommendHeader.snp.bottom).offset(20 + 103 + 12)
make.bottom.equalToSuperview()
}
make.left.right.equalToSuperview()
make.height.equalTo(103)
}
view.updateViews(liveTitle: model.title, fromTime: model.start_time, endTime: model.end_time, avatar: model.avatarurl, anchorName: model.account, isAppointmented: model.is_schedule_live)
}
}
}
}
private func bookLive(liveId: Int, liveView: YHRecommendedAppointmentLiveView) {
YHHUD.show(.progress(message: "加载中..."))
viewModel.postLiveBook(id: liveId) { [weak self] success, error in
guard let self = self else {
return
}
YHHUD.hide()
if success {
liveView.updateAppointmentButton(isAppointmented: true)
YHHUD.flash(message: "预约成功")
} else {
YHHUD.flash(message: "预约失败")
}
}
}
}
//
// YHRecommendLiveListModel.swift
// galaxy
//
// Created by alexzzw on 2024/12/28.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import Foundation
import SmartCodable
class YHRecommendLiveListModel: SmartCodable {
var live_list: [YHRecommendLiveItem] = []
required init() {
}
}
class YHRecommendLiveItem: SmartCodable {
var account: String = ""
var avatarurl: String = ""
var image: String = ""
var is_schedule_live: Bool = false
var live_id: Int = 0
var start_time: String = ""
var end_time: String = ""
var actual_start_time: String = ""
var actual_end_time: String = ""
var status: Int = 0
var title: String = ""
required init() {
}
}
//
// YHShareLiveInfoModel.swift
// galaxy
//
// Created by alexzzw on 2024/12/28.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import Foundation
import SmartCodable
class YHShareLiveInfoModel: SmartCodable {
var access_num: String = ""
var account: String = ""
var actual_end_time: String = ""
var actual_start_time: String = ""
var app_id: String = ""
var avatar: String = ""
var end_time: String = ""
var hx_token: String = ""
var hx_user_id: String = ""
var image: String = ""
var is_schedule_live: Bool = false
var room_id: String = ""
var rtmp_channel: String = ""
var start_time: String = ""
var status: Int = 0
var title: String = ""
var token: String = ""
var user_id: Int = 0
var watch: String = ""
required init() {
}
}
//
// YHRecommendedAppointmentLiveView.swift
// galaxy
//
// Created by alexzzw on 2024/12/29.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHRecommendedAppointmentLiveView: UIView {
var appointmentButtonEvent: (() -> Void)?
var buttonClickEvent: (() -> Void)?
private lazy var containerView: UIView = {
let view = UIView()
view.backgroundColor = .white.withAlphaComponent(0.08)
return view
}()
private lazy var liveTitleLabel: UILabel = {
let label = UILabel()
label.font = .PFSC_B(ofSize: 16)
label.textColor = .white
return label
}()
private lazy var timeLabel: UILabel = {
let label = UILabel()
label.font = .PFSC_R(ofSize: 12)
label.textColor = .white.withAlphaComponent(0.5)
return label
}()
private lazy var avatarImageView: UIImageView = {
let view = UIImageView()
view.contentMode = .scaleAspectFit
view.clipsToBounds = true
view.layer.cornerRadius = 9
return view
}()
private lazy var anchorLabel: UILabel = {
let label = UILabel()
label.font = .PFSC_R(ofSize: 12)
label.textColor = .white.withAlphaComponent(0.5)
return label
}()
private lazy var appointmentButton: UIButton = {
let button = UIButton(type: .custom)
button.setTitle("预约", for: .normal)
button.setTitle("已预约", for: .selected)
button.setTitleColor(UIColor.mainTextColor, for: .normal)
button.titleLabel?.font = UIFont.PFSC_M(ofSize: 12)
button.backgroundColor = .white
button.addTarget(self, action: #selector(appointmentButtonClicked), for: .touchUpInside)
return button
}()
@objc private func appointmentButtonClicked() {
appointmentButtonEvent?()
}
@objc private func tapButton(gestureRecognizer:UITapGestureRecognizer) {
buttonClickEvent?()
}
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI() {
addSubview(containerView)
containerView.addSubview(liveTitleLabel)
containerView.addSubview(timeLabel)
containerView.addSubview(avatarImageView)
containerView.addSubview(anchorLabel)
containerView.addSubview(appointmentButton)
containerView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(20)
make.right.equalToSuperview().offset(-20)
make.top.bottom.equalToSuperview()
}
liveTitleLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16)
make.top.equalToSuperview().offset(16)
make.right.lessThanOrEqualTo(appointmentButton.snp.left).offset(-16)
}
timeLabel.snp.makeConstraints { make in
make.left.equalTo(liveTitleLabel.snp.left)
make.top.equalTo(liveTitleLabel.snp.bottom).offset(6)
make.right.lessThanOrEqualTo(appointmentButton.snp.left).offset(-16)
}
avatarImageView.snp.makeConstraints { make in
make.left.equalTo(liveTitleLabel.snp.left)
make.top.equalTo(timeLabel.snp.bottom).offset(8)
make.width.height.equalTo(18)
make.bottom.equalToSuperview().offset(-16)
}
anchorLabel.snp.makeConstraints { make in
make.left.equalTo(avatarImageView.snp.right).offset(4)
make.centerY.equalTo(avatarImageView)
make.right.lessThanOrEqualTo(appointmentButton.snp.left).offset(-16)
}
appointmentButton.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-16)
make.centerY.equalToSuperview()
make.width.equalTo(77)
make.height.equalTo(32)
}
let tap = UITapGestureRecognizer(target: self, action: #selector(tapButton(gestureRecognizer:)))
addGestureRecognizer(tap)
}
func updateAppointmentButton(isAppointmented: Bool) {
if isAppointmented {
appointmentButton.isSelected = true
appointmentButton.isEnabled = false
} else {
appointmentButton.isSelected = false
appointmentButton.isEnabled = true
}
}
func updateViews(liveTitle: String, fromTime: String, endTime: String, avatar: String, anchorName: String, isAppointmented: Bool) {
liveTitleLabel.text = liveTitle
timeLabel.text = "直播时间:" + fromTime + "~" + endTime
if let url = URL(string: avatar) {
avatarImageView.kf.setImage(with: url, placeholder: UIImage(named: "global_default_image"))
} else {
avatarImageView.image = UIImage(named: "global_default_image")
}
anchorLabel.text = anchorName
updateAppointmentButton(isAppointmented: isAppointmented)
}
}
//
// YHRecommendedLiveHeader.swift
// galaxy
//
// Created by alexzzw on 2024/12/29.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHRecommendedLiveHeader: UIView {
var moreButtonEvent: (() -> Void)?
private lazy var tagView: UIView = {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 2, height: 12))
view.backgroundColor = UIColor.brandMainColor
return view
}()
private lazy var tagLabel: UILabel = {
let label = UILabel()
label.font = .PFSC_R(ofSize: 14)
label.textColor = .white
label.text = "推荐直播"
return label
}()
private lazy var moreButton: UIButton = {
let button = UIButton(type: .custom)
button.frame = CGRect(x: 0, y: 0, width: 42, height: 16)
button.setTitle("更多", for: .normal)
button.setTitleColor(UIColor.white.withAlphaComponent(0.5), for: .normal)
button.titleLabel?.font = UIFont.PFSC_R(ofSize: 12)
button.setImage(UIImage(named: "arrow_right_white_16"), for: .normal)
button.addTarget(self, action: #selector(moreButtonClicked), for: .touchUpInside)
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI() {
addSubview(tagView)
addSubview(tagLabel)
addSubview(moreButton)
tagView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(20)
make.centerY.equalToSuperview()
make.width.equalTo(2)
make.height.equalTo(12)
}
tagLabel.snp.makeConstraints { make in
make.left.equalTo(tagView.snp.right).offset(8)
make.centerY.equalToSuperview()
make.right.lessThanOrEqualTo(moreButton.snp.left).offset(-10)
}
moreButton.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-20)
make.centerY.equalToSuperview()
make.width.equalTo(42)
make.height.equalTo(20)
}
moreButton.iconInRight(with: 0)
}
@objc private func moreButtonClicked() {
moreButtonEvent?()
}
}
//
// YHRecommendedOnLiveView.swift
// galaxy
//
// Created by alexzzw on 2024/12/29.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import Lottie
import UIKit
class YHRecommendedOnLiveView: UIView {
var buttonClickEvent: (() -> Void)?
private lazy var flagImageView: LottieAnimationView = {
let view = LottieAnimationView(name: "live")
view.backgroundColor = UIColor.black.withAlphaComponent(0.6)
view.loopMode = .loop
return view
}()
private lazy var coverImageView: UIImageView = {
let view = UIImageView()
view.contentMode = .scaleAspectFit
view.isUserInteractionEnabled = true
return view
}()
private lazy var avatarImageView: UIImageView = {
let view = UIImageView()
view.isUserInteractionEnabled = true
view.contentMode = .scaleAspectFit
view.clipsToBounds = true
view.layer.cornerRadius = 10
view.layer.borderColor = UIColor.white.cgColor
view.layer.borderWidth = 0.5
return view
}()
private lazy var bottomLayerView: UIView = {
let view = UIView()
return view
}()
private lazy var anchorLabel: UILabel = {
let label = UILabel()
label.font = .PFSC_R(ofSize: 12)
label.textColor = .white
return label
}()
private lazy var gradientLayer: CAGradientLayer = {
let layer = CAGradientLayer()
layer.colors = [
UIColor.black.withAlphaComponent(0).cgColor,
UIColor.black.withAlphaComponent(0.9).cgColor,
]
layer.startPoint = CGPoint(x: 0.5, y: 0) // 上边中点
layer.endPoint = CGPoint(x: 0.5, y: 1) // 下边中点
return layer
}()
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
gradientLayer.frame = bottomLayerView.bounds
}
@objc private func tapButton(gestureRecognizer:UITapGestureRecognizer) {
buttonClickEvent?()
}
private func setupUI() {
addSubview(coverImageView)
addSubview(bottomLayerView)
addSubview(avatarImageView)
addSubview(anchorLabel)
addSubview(flagImageView)
sendSubviewToBack(coverImageView)
insertSubview(bottomLayerView, aboveSubview: coverImageView)
insertSubview(anchorLabel, aboveSubview: bottomLayerView)
insertSubview(avatarImageView, aboveSubview: bottomLayerView)
coverImageView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
flagImageView.snp.makeConstraints { make in
make.width.height.equalTo(16)
make.top.equalToSuperview().offset(8)
make.left.equalToSuperview().offset(8)
}
bottomLayerView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.height.equalTo(60)
}
avatarImageView.snp.makeConstraints { make in
make.width.height.equalTo(20)
make.bottom.equalToSuperview().offset(-12)
make.left.equalToSuperview().offset(8)
}
anchorLabel.snp.makeConstraints { make in
make.left.equalTo(avatarImageView.snp.right).offset(4)
make.centerY.equalTo(avatarImageView)
make.right.lessThanOrEqualToSuperview().offset(-8)
}
gradientLayer.frame = bottomLayerView.bounds
bottomLayerView.layer.mask = gradientLayer
flagImageView.play()
let tap = UITapGestureRecognizer(target: self, action: #selector(tapButton(gestureRecognizer:)))
addGestureRecognizer(tap)
}
func updateViews(avatar: String, anchorName: String, image: String) {
if let url = URL(string: image) {
coverImageView.kf.setImage(with: url, placeholder: UIImage(named: "global_default_image"))
} else {
coverImageView.image = UIImage(named: "global_default_image")
}
if let url = URL(string: avatar) {
avatarImageView.kf.setImage(with: url, placeholder: UIImage(named: "global_default_image"))
} else {
avatarImageView.image = UIImage(named: "global_default_image")
}
anchorLabel.text = anchorName
}
}
......@@ -235,7 +235,7 @@ extension YHLiveSalesViewModel {
}
}
func postLiveBook(id: Int, callback: @escaping (_ livePeople: Bool, _ error: YHErrorModel?) -> Void) {
func postLiveBook(id: Int, callback: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) {
let params: [String: Any] = ["live_id": id, "source_type": 1]
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.LiveSales.liveBook
_ = YHNetRequest.postRequest(url: strUrl, params: params) { [weak self] json, _ in
......@@ -252,6 +252,56 @@ extension YHLiveSalesViewModel {
callback(false, err)
}
}
func getRecommendLiveList(callback: @escaping (_ liveList: YHRecommendLiveListModel?, _ error: YHErrorModel?) -> Void) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.LiveSales.recommendLiveList
_ = YHNetRequest.getRequest(url: strUrl, params: [:]) { json, _ in
// 1. json字符串 转 对象
printLog("model 是 ==> \(json)")
if json.code == 200 {
guard let dic = json.data?.peel as? [String: Any], let resultModel = YHRecommendLiveListModel.deserialize(from: dic) else {
let err = YHErrorModel(errorCode: YHErrorCode.dictParseError.rawValue, errorMsg: YHErrorCode.dictParseError.description())
callback(nil, err)
return
}
callback(resultModel, nil)
} else {
let err = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg.isEmpty ? "" : json.msg)
callback(nil, err)
}
} failBlock: { err in
callback(nil, err)
}
}
func getShareLiveInfo(liveId: Int, shareType: Int, callback: @escaping (_ liveInfo: YHShareLiveInfoModel?, _ error: YHErrorModel?) -> Void) {
// 分享类型 1:直播 2录播
let param: [String: Any] = ["live_id": liveId, "share_type": shareType]
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.LiveSales.shareLive
_ = YHNetRequest.getRequest(url: strUrl, params: param) { json, _ in
// 1. json字符串 转 对象
printLog("model 是 ==> \(json)")
if json.code == 200 {
guard let dic = json.data?.peel as? [String: Any], let resultModel = YHShareLiveInfoModel.deserialize(from: dic) else {
let err = YHErrorModel(errorCode: YHErrorCode.dictParseError.rawValue, errorMsg: YHErrorCode.dictParseError.description())
callback(nil, err)
return
}
callback(resultModel, nil)
} else {
let err = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg.isEmpty ? "" : json.msg)
callback(nil, err)
}
} failBlock: { err in
callback(nil, err)
}
}
}
......
......@@ -722,8 +722,12 @@ class YHAllApiName {
// APP直播间人数
static let livePeople = "super-app/live/live-people"
static let schedulLiveList = "super-app/live/schedule-live-list"
// 预约直播
static let liveBook = "super-app/live/live-book"
// APP推荐直播
static let recommendLiveList = "super-app/live/recommend-live-list"
// APP分享直播间
static let shareLive = "super-app/live/share-live"
}
struct AIChat {
......
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "arrow_right_white_16@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "arrow_right_white_16@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