109 lines
4.0 KiB
Swift
109 lines
4.0 KiB
Swift
//
|
|
// MPPositive_MoreOperationTableViewCell.swift
|
|
// MusicPlayer
|
|
//
|
|
// Created by Mr.Zhou on 2024/5/29.
|
|
//
|
|
|
|
import UIKit
|
|
import DownloadButton
|
|
class MPPositive_MoreOperationDownLoadTableViewCell: UITableViewCell {
|
|
//设置下载按钮
|
|
lazy var loadBtn:PKDownloadButton = {
|
|
let btn:PKDownloadButton = .init()
|
|
btn.isUserInteractionEnabled = false
|
|
//开始下载状态
|
|
btn.startDownloadButton.cleanDefaultAppearance()
|
|
btn.startDownloadButton.setBackgroundImage(UIImage(named: "Song_Unload'logo"), for: .normal)
|
|
//下载结束状态
|
|
btn.downloadedButton.setBackgroundImage(UIImage(named: "Song_Loaded'logo"), for: .normal)
|
|
btn.downloadedButton.isUserInteractionEnabled = false
|
|
btn.downloadedButton.setAttributedTitle(nil, for: .normal)
|
|
//停止下载状态
|
|
btn.stopDownloadButton.stopButton.setImage(UIImage(named: "download"), for: .normal)
|
|
btn.stopDownloadButton.isUserInteractionEnabled = false
|
|
btn.stopDownloadButton.tintColor = UIColor(hex: "#80F988")
|
|
btn.stopDownloadButton.stopButtonWidth = 2
|
|
btn.stopDownloadButton.filledLineWidth = 3*width
|
|
btn.stopDownloadButton.filledLineStyleOuter = true
|
|
|
|
//加载状态设置
|
|
btn.pendingView.tintColor = UIColor(hex: "#80F988")
|
|
btn.pendingView.radius = 12*width
|
|
btn.pendingView.emptyLineRadians = 2*width
|
|
btn.pendingView.spinTime = 3
|
|
return btn
|
|
}()
|
|
|
|
private lazy var titleLabel:UILabel = createLabel(font: .systemFont(ofSize: 14*width, weight: .regular), textColor: .white, textAlignment: .left)
|
|
var title:String!{
|
|
didSet{
|
|
titleLabel.text = title
|
|
}
|
|
}
|
|
var progressBlock:(() -> Void)?
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
selectionStyle = .none
|
|
backgroundColor = .clear
|
|
configure()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
}
|
|
override func awakeFromNib() {
|
|
super.awakeFromNib()
|
|
// Initialization code
|
|
}
|
|
|
|
override func setSelected(_ selected: Bool, animated: Bool) {
|
|
super.setSelected(selected, animated: animated)
|
|
|
|
// Configure the view for the selected state
|
|
}
|
|
private func configure() {
|
|
contentView.addSubview(loadBtn)
|
|
loadBtn.snp.makeConstraints { make in
|
|
make.width.height.equalTo(24*width)
|
|
make.top.equalToSuperview().offset(12*width).priority(999)
|
|
make.bottom.equalToSuperview().offset(-12*width)
|
|
make.left.equalToSuperview().offset(18*width)
|
|
}
|
|
contentView.addSubview(titleLabel)
|
|
titleLabel.snp.makeConstraints { make in
|
|
make.centerY.equalToSuperview()
|
|
make.left.equalTo(loadBtn.snp.right).offset(12*width)
|
|
}
|
|
}
|
|
//对于下载按钮状态的刷新变动
|
|
public func restoreDownloadProgress(_ song:MPPositive_SongItemModel?) {
|
|
guard let song = song else {
|
|
return
|
|
}
|
|
//判断当前播放video是否正在下载
|
|
if let progress = MP_DownloadManager.shared.getProgress(for: song.videoId) {
|
|
DispatchQueue.main.async {
|
|
[weak self] in
|
|
guard let self = self else {return}
|
|
//是正在下载的URL
|
|
loadBtn.state = .downloading
|
|
//调整下载的进度
|
|
loadBtn.stopDownloadButton.progress = progress
|
|
if progressBlock != nil {
|
|
progressBlock!()
|
|
}
|
|
}
|
|
}else {
|
|
//不是正在下载的内容,判断是否已经下载
|
|
if MPPositive_DownloadItemModel.fetch(.init(format: "videoId == %@", song.videoId)).count != 0 {
|
|
//下载内容
|
|
loadBtn.state = .downloaded
|
|
}else {
|
|
//不是下载内容
|
|
loadBtn.state = .startDownload
|
|
}
|
|
}
|
|
}
|
|
}
|