Music_Player3/relax.offline.mp3.music/MP/MPPositive/Views/Base/MPPositive_MoreOperationDownLoadTableViewCell.swift
2024-06-03 15:34:16 +08:00

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
}
}
}
}