Music_Player3/relax.offline.mp3.music/MP/MPPositive/Views/Base/MPPositive_MoreOperationDownLoadTableViewCell.swift

127 lines
4.9 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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
}()
var song:MPPositive_SongItemModel!{
didSet{
setProgress(song.videoId)
}
}
private lazy var titleLabel:UILabel = createLabel("Status" ,font: .systemFont(ofSize: 14*width, weight: .regular), textColor: .white, textAlignment: .left)
//videoId
func setProgress(_ videoId:String) {
guard videoId.isEmpty == false, videoId == song?.videoId else {
return
}
MP_DownloadManager.shared.loadQueue.async {
[weak self] in
guard let self = self else {return}
//
guard MP_DownloadManager.shared.isDownloadedFileDocuments(videoId) == false else {
DispatchQueue.main.async {
//
self.loadBtn.state = .downloaded
self.titleLabel.text = "Remove download"
}
return
}
//,
guard MP_DownloadManager.shared.isTasksQueue(for: videoId) else {
DispatchQueue.main.async {
//
self.loadBtn.state = .startDownload
self.titleLabel.text = "Download"
}
return
}
//
if MP_DownloadManager.shared.isActiveTask(for: videoId) {
DispatchQueue.main.async {
self.loadBtn.state = .downloading
self.titleLabel.text = "Downloading"
}
//
if let progress = MP_DownloadManager.shared.getProgress(for: videoId) {
//
DispatchQueue.main.async {
self.loadBtn.stopDownloadButton.progress = progress
}
}
}else {
//
DispatchQueue.main.async {
//
self.loadBtn.state = .pending
self.titleLabel.text = "Downloading"
}
}
}
}
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)
}
}
}