diff --git a/MoviaBox/Base/Extension/NSNumber+SPAdd.swift b/MoviaBox/Base/Extension/NSNumber+SPAdd.swift new file mode 100644 index 0000000..0153f71 --- /dev/null +++ b/MoviaBox/Base/Extension/NSNumber+SPAdd.swift @@ -0,0 +1,25 @@ +// +// NSNumber+SPAdd.swift +// MoviaBox +// +// Created by 佳尔 on 2025/5/16. +// + +import UIKit + +extension NSNumber { + + func toString(maximumFractionDigits: Int = 10, minimumFractionDigits: Int? = nil, roundingMode: NumberFormatter.RoundingMode? = nil) -> String { + let formatter = NumberFormatter() + formatter.minimumIntegerDigits = 1 + formatter.maximumFractionDigits = maximumFractionDigits + if let minimumFractionDigits = minimumFractionDigits { + formatter.minimumFractionDigits = minimumFractionDigits + } + if let roundingMode = roundingMode { + formatter.roundingMode = roundingMode + } + formatter.numberStyle = .none + return formatter.string(from: self) ?? "0" + } +} diff --git a/MoviaBox/Base/Extension/UIColor+SPAdd.swift b/MoviaBox/Base/Extension/UIColor+SPAdd.swift index 6db3dfb..b08c4f7 100644 --- a/MoviaBox/Base/Extension/UIColor+SPAdd.swift +++ b/MoviaBox/Base/Extension/UIColor+SPAdd.swift @@ -488,5 +488,41 @@ extension UIColor { static func colorFFDD00(alpha: CGFloat = 1) -> UIColor { return color(hex: 0xFFDD00, alpha: alpha) } + + static func color3E23DE(alpha: CGFloat = 1) -> UIColor { + return color(hex: 0x3E23DE, alpha: alpha) + } + + static func color4629F1(alpha: CGFloat = 1) -> UIColor { + return color(hex: 0x4629F1, alpha: alpha) + } + + static func color3D1DFF(alpha: CGFloat = 1) -> UIColor { + return color(hex: 0x3D1DFF, alpha: alpha) + } + + static func colorDE2326(alpha: CGFloat = 1) -> UIColor { + return color(hex: 0xDE2326, alpha: alpha) + } + + static func colorF1298A(alpha: CGFloat = 1) -> UIColor { + return color(hex: 0xF1298A, alpha: alpha) + } + + static func colorFF1DE8(alpha: CGFloat = 1) -> UIColor { + return color(hex: 0xFF1DE8, alpha: alpha) + } + + static func colorD93845(alpha: CGFloat = 1) -> UIColor { + return color(hex: 0xD93845, alpha: alpha) + } + + static func colorFF5528(alpha: CGFloat = 1) -> UIColor { + return color(hex: 0xFF5528, alpha: alpha) + } + + static func colorFF9924(alpha: CGFloat = 1) -> UIColor { + return color(hex: 0xFF9924, alpha: alpha) + } } diff --git a/MoviaBox/Base/Extension/UIImageView+SPAdd.swift b/MoviaBox/Base/Extension/UIImageView+SPAdd.swift index 7393711..687ed53 100644 --- a/MoviaBox/Base/Extension/UIImageView+SPAdd.swift +++ b/MoviaBox/Base/Extension/UIImageView+SPAdd.swift @@ -7,10 +7,12 @@ import UIKit import Kingfisher +//import KingfisherWebP extension UIImageView { func sp_setImage(url: String?, placeholder: UIImage? = nil, completer: ((_ image: UIImage?, _ url: URL?) -> Void)? = nil) { +// self.kf.setImage(with: URL(string: url ?? ""), placeholder: placeholder, options: [.processor(WebPProcessor.default)]) { result in self.kf.setImage(with: URL(string: url ?? ""), placeholder: placeholder, options: nil) { result in switch result { case .success(let value): diff --git a/MoviaBox/Class/Home/View/SPHomeExploreCell.swift b/MoviaBox/Class/Home/View/SPHomeExploreCell.swift index c7eaf99..909dfd8 100644 --- a/MoviaBox/Class/Home/View/SPHomeExploreCell.swift +++ b/MoviaBox/Class/Home/View/SPHomeExploreCell.swift @@ -13,6 +13,18 @@ class SPHomeExploreCell: SPCollectionViewCell { didSet { coverImageView.sp_setImage(url: model?.image_url) titleLabel.text = model?.name + + if model?.tag_type == .hot { + markView.isHidden = false + markView.colors = [UIColor.color3E23DE(alpha: 0.17).cgColor, UIColor.color4629F1(alpha: 0.74).cgColor, UIColor.color3D1DFF().cgColor] + markLabel.text = "HOT" + } else if model?.tag_type == .new { + markView.isHidden = false + markView.colors = [UIColor.colorDE2326(alpha: 0.17).cgColor, UIColor.colorF1298A(alpha: 0.74).cgColor, UIColor.colorFF1DE8().cgColor] + markLabel.text = "NEW" + } else { + markView.isHidden = true + } } } @@ -24,6 +36,22 @@ class SPHomeExploreCell: SPCollectionViewCell { return imageView }() + private lazy var markView: SPGradientView = { + let view = SPGradientView() + view.locations = [0, 0.3, 1] + view.startPoint = .init(x: 0, y: 0.7) + view.endPoint = .init(x: 1, y: 0.5) + view.addRadius(topLeft: 0, topRight: 0, bottomLeft: 12, bottomRight: 0) + return view + }() + + private lazy var markLabel: UILabel = { + let label = UILabel() + label.font = .fontBold(ofSize: 12) + label.textColor = .colorFFFFFF() + return label + }() + private lazy var titleLabel: UILabel = { let label = UILabel() label.font = .fontRegular(ofSize: 12) @@ -48,6 +76,8 @@ extension SPHomeExploreCell { private func _setupUI() { contentView.addSubview(coverImageView) + coverImageView.addSubview(markView) + markView.addSubview(markLabel) contentView.addSubview(titleLabel) coverImageView.snp.makeConstraints { make in @@ -55,6 +85,17 @@ extension SPHomeExploreCell { make.bottom.equalToSuperview().offset(-36) } + markView.snp.makeConstraints { make in + make.top.equalToSuperview() + make.right.equalToSuperview() + make.width.equalTo(46) + make.height.equalTo(18) + } + + markLabel.snp.makeConstraints { make in + make.center.equalToSuperview() + } + titleLabel.snp.makeConstraints { make in make.left.equalToSuperview() make.right.lessThanOrEqualToSuperview() diff --git a/MoviaBox/Class/Home/View/SPHomeShortCell.swift b/MoviaBox/Class/Home/View/SPHomeShortCell.swift index 239506a..17cf4af 100644 --- a/MoviaBox/Class/Home/View/SPHomeShortCell.swift +++ b/MoviaBox/Class/Home/View/SPHomeShortCell.swift @@ -13,6 +13,18 @@ class SPHomeShortCell: SPCollectionViewCell { didSet { coverImageView.sp_setImage(url: model?.image_url) titleLabel.text = model?.name + + if model?.tag_type == .hot { + markView.isHidden = false + markView.colors = [UIColor.color3E23DE(alpha: 0.17).cgColor, UIColor.color4629F1(alpha: 0.74).cgColor, UIColor.color3D1DFF().cgColor] + markLabel.text = "HOT" + } else if model?.tag_type == .new { + markView.isHidden = false + markView.colors = [UIColor.colorDE2326(alpha: 0.17).cgColor, UIColor.colorF1298A(alpha: 0.74).cgColor, UIColor.colorFF1DE8().cgColor] + markLabel.text = "NEW" + } else { + markView.isHidden = true + } } } @@ -21,6 +33,22 @@ class SPHomeShortCell: SPCollectionViewCell { return imageView }() + private lazy var markView: SPGradientView = { + let view = SPGradientView() + view.locations = [0, 0.3, 1] + view.startPoint = .init(x: 0, y: 0.7) + view.endPoint = .init(x: 1, y: 0.5) + view.addRadius(topLeft: 0, topRight: 4, bottomLeft: 12, bottomRight: 0) + return view + }() + + private lazy var markLabel: UILabel = { + let label = UILabel() + label.font = .fontBold(ofSize: 12) + label.textColor = .colorFFFFFF() + return label + }() + private lazy var titleLabel: UILabel = { let label = UILabel() label.font = .fontMedium(ofSize: 12) @@ -47,6 +75,8 @@ class SPHomeShortCell: SPCollectionViewCell { extension SPHomeShortCell { private func _setupUI() { contentView.addSubview(coverImageView) + coverImageView.addSubview(markView) + markView.addSubview(markLabel) contentView.addSubview(titleLabel) coverImageView.snp.makeConstraints { make in @@ -54,6 +84,17 @@ extension SPHomeShortCell { make.bottom.equalToSuperview().offset(-44) } + markView.snp.makeConstraints { make in + make.top.equalToSuperview().offset(6) + make.right.equalToSuperview().offset(-6) + make.width.equalTo(46) + make.height.equalTo(18) + } + + markLabel.snp.makeConstraints { make in + make.center.equalToSuperview() + } + titleLabel.snp.makeConstraints { make in make.left.equalToSuperview().offset(8) make.right.lessThanOrEqualToSuperview().offset(-8) diff --git a/MoviaBox/Class/Home/View/SPHomeTrendingCell.swift b/MoviaBox/Class/Home/View/SPHomeTrendingCell.swift index 65a52bb..115c093 100644 --- a/MoviaBox/Class/Home/View/SPHomeTrendingCell.swift +++ b/MoviaBox/Class/Home/View/SPHomeTrendingCell.swift @@ -13,10 +13,17 @@ class SPHomeTrendingCell: SPCollectionViewCell { didSet { coverImageView.sp_setImage(url: model?.image_url) titleLabel.text = model?.name - hotView.setTitle("\(model?.watch_total ?? 0)", for: .normal) - if let tag = model?.tag_type, !tag.isEmpty { - tagView.setTitle(tag, for: .normal) + let watchCount = model?.watch_total ?? 0 + if watchCount > 1000 { + let numStr = NSNumber(floatLiteral: CGFloat(watchCount) / 1000).toString(maximumFractionDigits: 1) + hotView.setTitle("\(numStr)K", for: .normal) + } else { + hotView.setTitle("\(watchCount)", for: .normal) + } + + if let category = model?.category?.first { + tagView.setTitle(category, for: .normal) tagView.isHidden = false } else { tagView.isHidden = true @@ -27,10 +34,23 @@ class SPHomeTrendingCell: SPCollectionViewCell { var row: Int = 0 { didSet { let num = row + 1 - if num < 4 { - numBgView.image = UIImage(named: "num_bg_icon_\(num)") - } else { - numBgView.image = UIImage(named: "num_bg_icon_4") +// if num < 4 { +// numBgView.image = UIImage(named: "num_bg_icon_\(num)") +// } else { +// numBgView.image = UIImage(named: "num_bg_icon_4") +// } + switch num { + case 1: + numBgView.colors = [UIColor.colorD93845().cgColor, UIColor.colorD93845(alpha: 0.74).cgColor, UIColor.colorD93845(alpha: 0.17).cgColor] + + case 2: + numBgView.colors = [UIColor.colorFF5528().cgColor, UIColor.colorFF5528(alpha: 0.74).cgColor, UIColor.colorFF5528(alpha: 0.17).cgColor] + + case 3: + numBgView.colors = [UIColor.colorFF9924().cgColor, UIColor.colorFF9924(alpha: 0.74).cgColor, UIColor.colorFF9924(alpha: 0.17).cgColor] + + default: + numBgView.colors = [UIColor.color000000(alpha: 0.45).cgColor, UIColor.color000000(alpha: 0.45).cgColor, UIColor.color000000(alpha: 0.45).cgColor] } numLabel.text = "\(num)" @@ -45,9 +65,13 @@ class SPHomeTrendingCell: SPCollectionViewCell { return imageView }() - private lazy var numBgView: UIImageView = { - let imageView = UIImageView() - return imageView + private lazy var numBgView: SPGradientView = { + let view = SPGradientView() + view.locations = [0, 0.5, 1] + view.startPoint = .init(x: 0.5, y: 0) + view.endPoint = .init(x: 0.5, y: 1) + view.addRadius(topLeft: 0, topRight: 0, bottomLeft: 0, bottomRight: 4) + return view }() private lazy var numLabel: UILabel = { @@ -122,6 +146,8 @@ extension SPHomeTrendingCell { numBgView.snp.makeConstraints { make in make.left.top.equalToSuperview() + make.width.equalTo(24) + make.height.equalTo(32) } numLabel.snp.makeConstraints { make in diff --git a/MoviaBox/Class/Home/View/SPHomeTrendingView.swift b/MoviaBox/Class/Home/View/SPHomeTrendingView.swift index 1eeaff9..e2db0fe 100644 --- a/MoviaBox/Class/Home/View/SPHomeTrendingView.swift +++ b/MoviaBox/Class/Home/View/SPHomeTrendingView.swift @@ -107,7 +107,11 @@ extension SPHomeTrendingView: UICollectionViewDataSource, UICollectionViewDelega } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return dataArr?.count ?? 0 + var count = self.dataArr?.count ?? 0 + if count > 9 { + count = 9 + } + return count } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { diff --git a/MoviaBox/Class/Home/View/SPHomeZoomBannerCell.swift b/MoviaBox/Class/Home/View/SPHomeZoomBannerCell.swift index b5f4636..9772cbb 100644 --- a/MoviaBox/Class/Home/View/SPHomeZoomBannerCell.swift +++ b/MoviaBox/Class/Home/View/SPHomeZoomBannerCell.swift @@ -13,6 +13,11 @@ class SPHomeZoomBannerCell: ZKCycleScrollViewCell { didSet { coverImageView.sp_setImage(url: model?.image_url) titleLabel.text = model?.name + if model?.tag_type == .new { + iconImageView.isHidden = false + } else { + iconImageView.isHidden = true + } } } @@ -78,7 +83,7 @@ extension SPHomeZoomBannerCell { titleLabel.snp.makeConstraints { make in make.left.equalToSuperview().offset(15) - make.right.lessThanOrEqualToSuperview().offset(-15) + make.right.lessThanOrEqualToSuperview().offset(-40) make.centerY.equalToSuperview() } } diff --git a/MoviaBox/Class/Player/Controller/SPPlayerListViewController.swift b/MoviaBox/Class/Player/Controller/SPPlayerListViewController.swift index cd257bb..0705ba1 100644 --- a/MoviaBox/Class/Player/Controller/SPPlayerListViewController.swift +++ b/MoviaBox/Class/Player/Controller/SPPlayerListViewController.swift @@ -182,10 +182,6 @@ class SPPlayerListViewController: SPViewController { self.collectionView.setContentOffset(CGPoint(x: 0, y: floor(offset)), animated: false) } } - - if currentIndexPath.row <= 2 { -// self.loadUpMoreData() - } } func pause() { diff --git a/MoviaBox/Class/Player/Model/SPShortModel.swift b/MoviaBox/Class/Player/Model/SPShortModel.swift index c147813..9fac89f 100644 --- a/MoviaBox/Class/Player/Model/SPShortModel.swift +++ b/MoviaBox/Class/Player/Model/SPShortModel.swift @@ -10,6 +10,11 @@ import SmartCodable class SPShortModel: SPModel, SmartCodable { + enum TagType: String, SmartCaseDefaultable { + case hot = "hot" + case new = "new" + } + var id: String? var all_coins: String? var buy_type: String? @@ -25,8 +30,9 @@ class SPShortModel: SPModel, SmartCodable { var short_id: String? var short_play_id: String? var short_play_video_id: String? - var tag_type: String? + var tag_type: TagType? var video_info: SPVideoInfoModel? + var category: [String]? ///观看数 var watch_total: Int? var current_episode: String? diff --git a/Podfile b/Podfile index 97bfe72..fb59046 100644 --- a/Podfile +++ b/Podfile @@ -26,6 +26,7 @@ target 'MoviaBox' do pod 'KTVHTTPCache' #视频缓存 pod 'HWPanModal' #底部弹出控制器 pod 'Kingfisher' #图片加载 +# pod 'KingfisherWebP' pod 'EmptyDataSet-Swift' #空数据页面 pod 'ReachabilitySwift' #网络状态监控 pod 'WMZPageController' #分页控制器 diff --git a/Podfile.lock b/Podfile.lock index 6fd758e..3c5da2c 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -98,6 +98,6 @@ SPEC CHECKSUMS: YYKit: 7cda43304a8dc3696c449041e2cb3107b4e236e7 ZFPlayer: 5cf39e8d9f0c2394a014b0db4767b5b5a6bffe13 -PODFILE CHECKSUM: 1e8174e48a7218cf3eed0a059ee987d0638ab131 +PODFILE CHECKSUM: de731c7a1ac66210ab6396d96271f2c62639627f COCOAPODS: 1.16.2