Commit 0d4d241e authored by CZ1004's avatar CZ1004

【修复】

1、跳转问题
2、缓存问题
3、首页UI问题
4、磁盘占用空间更改
parent ea238559
......@@ -41,14 +41,14 @@ class CompressSelectCell : UICollectionViewCell {
let compressCompletedSize = Double(compressedData.count)
let saveSize = model.orgSize - compressCompletedSize
let sizeKB : Double = saveSize/1024
let sizeKB : Double = saveSize/1000
DispatchQueue.main.async {
if sizeKB < 1024{
if sizeKB < 1000{
self.saveSizeLabel.text = String(format: "Save %.2f KB" ,sizeKB)
}else if sizeKB < (1024 * 1024) && sizeKB > 1024{
self.saveSizeLabel.text = String(format: "Save %.2f MB" ,sizeKB/1024)
}else if sizeKB < (1000 * 1000) && sizeKB > 1000{
self.saveSizeLabel.text = String(format: "Save %.2f MB" ,sizeKB/1000)
}else{
self.saveSizeLabel.text = String(format: "Save %.2f GB" ,sizeKB/(1024 * 1024))
self.saveSizeLabel.text = String(format: "Save %.2f GB" ,sizeKB/(1000 * 1000))
}
}
}
......
......@@ -199,15 +199,15 @@ class CompressQualityController : BaseViewController{
orgAllSize = orgAllSize + modelData.orgSize
}
sum = orgAllSize - compressAllSize
sum = sum / 1024
sum = sum / 1000
if sum < 1024{
if sum < 1000{
vc.sizeToplabel.text = String(format:"%.2lfKB",sum)
}else if sum < (1024 * 1024) && sum > 1024{
sum = sum / 1024
}else if sum < (1000 * 1000) && sum > 1000{
sum = sum / 1000
vc.sizeToplabel.text = String(format:"%.2lfMB",sum)
}else{
sum = sum / (1024 * 1024)
sum = sum / (1000 * 1000)
vc.sizeToplabel.text = String(format:"%.2lfGB",sum)
}
let str = String(format:"%.2lf",(orgAllSize - compressAllSize) / orgAllSize)
......
......@@ -22,21 +22,21 @@ class CompressCustomHeaderView: UICollectionReusableView{
saveSum = saveSum + model.orgSize * 0.8
}
sum = sum / 1000
saveSum = saveSum / 1024
if sum < 1024 {
saveSum = saveSum / 1000
if sum < 1000 {
self.siezLabel.text = String(format: "%.2f KB" ,(sum))
}else if sum < (1024 * 1024) && sum > 1024{
self.siezLabel.text = String(format: "%.2f MB" ,(sum/1024))
}else if sum < (1000 * 1000) && sum > 1024{
self.siezLabel.text = String(format: "%.2f MB" ,(sum/1000))
}else{
self.siezLabel.text = String(format: "%.2f GB" ,sum/(1024*1024))
self.siezLabel.text = String(format: "%.2f GB" ,sum/(1000*1000))
}
if saveSum < 1024 {
if saveSum < 1000 {
self.saveSizeLabel.text = String(format: "%.2f KB" ,(saveSum))
}else if saveSum < (1024 * 1024) && saveSum > 1024{
self.saveSizeLabel.text = String(format: "%.2f MB" ,(saveSum/1024))
}else if saveSum < (1000 * 1000) && saveSum > 1024{
self.saveSizeLabel.text = String(format: "%.2f MB" ,(saveSum/1000))
}else{
self.saveSizeLabel.text = String(format: "%.2f GB" ,saveSum/(1024*1024))
self.saveSizeLabel.text = String(format: "%.2f GB" ,saveSum/(1000*1000))
}
}
......
......@@ -401,7 +401,7 @@ class CompressViewModel{
let imageManager = PHCachingImageManager()
let options = PHImageRequestOptions()
options.isSynchronous = false
options.deliveryMode = .highQualityFormat
options.deliveryMode = .opportunistic
options.isNetworkAccessAllowed = true
imageManager.requestImage(for: asset, targetSize: CGSize(width: 400, height: 400), contentMode: .aspectFill, options: options) { (image, _) in
......
......@@ -104,12 +104,6 @@ class HomeInfoViewController:BaseViewController {
})
}
// 更新下首页数据以及缓存数据
let dataUpdated = Notification.Name("DataUpdatedNotification")
NotificationCenter.default.post(name: dataUpdated, object: nil, userInfo: nil)
func updateFreeTimes(){
// 删除成功后更新次数
var times = UserDefaults.standard.object(forKey: "saveAdvTimes") as! Int
......
......@@ -622,9 +622,7 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti
// 清理下缓存数据
PhotoDataManager.manager.removeDataWhenDeleteInPage(data: self.selectedModel)
// 给首页发通知,数据删除
let dataUpdated = Notification.Name("DataUpdatedNotification")
NotificationCenter.default.post(name: dataUpdated, object: nil, userInfo: nil)
// 更新页面
......
......@@ -540,9 +540,7 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
// 清理下缓存数据
PhotoDataManager.manager.removeDataWhenDeleteInPage(data: self.selectedModel)
// 给首页发通知,数据删除
let dataUpdated = Notification.Name("DataUpdatedNotification")
NotificationCenter.default.post(name: dataUpdated, object: nil, userInfo: nil)
// 更新页面
......
......@@ -74,16 +74,16 @@ class HomeCollectionViewHeader : UICollectionReusableView {
// 文本
self.addSubview(self.tipLabel)
self.tipLabel.snp.makeConstraints { make in
make.left.equalToSuperview()
make.left.equalToSuperview().offset(8)
make.top.equalToSuperview().offset(4)
make.height.equalTo(17)
}
self.addSubview(self.progressBar)
self.progressBar.snp.makeConstraints { make in
make.top.equalTo(self.tipLabel.snp.bottom).offset(12)
make.width.equalToSuperview()
make.width.equalToSuperview().offset(-16)
make.height.equalTo(31)
make.left.equalToSuperview()
make.left.equalToSuperview().offset(8)
}
// self.addSubview(self.subTiplabel)
......@@ -163,12 +163,30 @@ class CustomProgressBar: UIView {
private let dotSize: CGFloat = 8
private let labelSpacing: CGFloat = 18
var usedProgress: CGFloat = 0
var chaoticProgress: CGFloat = 0
var usedProgress: CGFloat = 0 {
didSet{
self.updateProgress()
}
}
var totalProgress: CGFloat = 0
var chaoticProgress: CGFloat = 0 {
didSet{
self.updateProgress()
}
}
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
let disk = WidgetPublicModel.getDiskSpace()
self.totalProgress = Double(disk.0)
self.usedProgress = Double(disk.0) - Double(disk.1)
Task {
let photoData = await Double(StorageManager.manager.getPhotoResourceMemory())
self.chaoticProgress = photoData
}
}
required init?(coder: NSCoder) {
......@@ -177,22 +195,23 @@ class CustomProgressBar: UIView {
}
private func setupUI() {
layer.addSublayer(progressLayer)
usedLabel.text = "Used"
usedLabel.font = UIFont.systemFont(ofSize: 12)
usedLabel.textColor = .black
usedLabel.textColor = UIColor.colorWithHex(hexStr: black6Color)
addSubview(usedLabel)
chaoticLabel.text = "Chaotic content"
chaoticLabel.font = UIFont.systemFont(ofSize: 12)
chaoticLabel.textColor = .black
chaoticLabel.textColor = UIColor.colorWithHex(hexStr: black6Color)
addSubview(chaoticLabel)
idleLabel.text = "Idle"
idleLabel.font = UIFont.systemFont(ofSize: 12)
idleLabel.textColor = .black
idleLabel.textColor = UIColor.colorWithHex(hexStr: black6Color)
addSubview(idleLabel)
}
......@@ -222,38 +241,30 @@ class CustomProgressBar: UIView {
}
private func updateProgress() {
DispatchQueue.global(qos: .userInitiated).async {
let disk = WidgetPublicModel.getDiskSpace()
let usedData = Double(disk.1)
let tolData = Double(disk.0)
Task {
let photoData = await Double(StorageManager.manager.getPhotoResourceMemory())
// 回到主线程更新 UI
DispatchQueue.main.async {
let usedProgress = CGFloat(usedData / tolData)
let chaoticProgress = CGFloat(photoData / tolData)
let totalProgress = usedProgress + chaoticProgress
let remainingProgress = 1 - totalProgress
let usedWidth = self.bounds.width * usedProgress
let chaoticWidth = self.bounds.width * chaoticProgress
let idleWidth = self.bounds.width * remainingProgress
let usedLayer = CALayer()
usedLayer.frame = CGRect(x: 0, y: 0, width: usedWidth, height: self.progressLayer.bounds.height)
usedLayer.backgroundColor = self.usedColor.cgColor
let chaoticLayer = CALayer()
chaoticLayer.frame = CGRect(x: usedWidth, y: 0, width: chaoticWidth, height: self.progressLayer.bounds.height)
chaoticLayer.backgroundColor = self.chaoticColor.cgColor
let idleLayer = CALayer()
idleLayer.frame = CGRect(x: usedWidth + chaoticWidth, y: 0, width: idleWidth, height: self.progressLayer.bounds.height)
idleLayer.backgroundColor = self.idleColor.cgColor
self.progressLayer.sublayers = [usedLayer, chaoticLayer, idleLayer]
}
}
// 回到主线程更新 UI
DispatchQueue.main.async {
let usedProgress = CGFloat(self.usedProgress / self.totalProgress)
let chaoticProgress = CGFloat(self.chaoticProgress / self.totalProgress)
let totalProgress = usedProgress + chaoticProgress
let remainingProgress = 1 - totalProgress
let usedWidth = self.bounds.width * usedProgress
let chaoticWidth = self.bounds.width * chaoticProgress
let idleWidth = self.bounds.width * remainingProgress
let usedLayer = CALayer()
usedLayer.frame = CGRect(x: 0, y: 0, width: usedWidth, height: self.progressLayer.bounds.height)
usedLayer.backgroundColor = self.usedColor.cgColor
let chaoticLayer = CALayer()
chaoticLayer.frame = CGRect(x: usedWidth, y: 0, width: chaoticWidth, height: self.progressLayer.bounds.height)
chaoticLayer.backgroundColor = self.chaoticColor.cgColor
let idleLayer = CALayer()
idleLayer.frame = CGRect(x: usedWidth + chaoticWidth, y: 0, width: idleWidth, height: self.progressLayer.bounds.height)
idleLayer.backgroundColor = self.idleColor.cgColor
self.progressLayer.sublayers = [usedLayer, chaoticLayer, idleLayer]
}
}
......
......@@ -37,7 +37,7 @@ class HomeNavView:UIView {
// 标题
self.addSubview(self.homeTitle)
self.homeTitle.snp.makeConstraints { make in
make.left.equalTo(15)
make.left.equalTo(15 + 8)
make.top.equalTo(8 + statusBarHeight)
make.height.equalTo(28)
make.width.equalTo(149)
......
......@@ -84,7 +84,7 @@ class PhotoDataManager {
}
for index in 0..<model.titleModelArray.count {
// 删除相似截图和相似视频的缓存
var size :Double = 0.0
var size : Double = 0.0
var finalyVideoData : [[AssetModel]] = []
let array = model.titleModelArray[index].assets
......@@ -106,6 +106,10 @@ class PhotoDataManager {
}
// 处理完成保存下当前数据
self.saveToFileSystem(model: model)
// 更新下首页数据以及缓存数据
let dataUpdated = Notification.Name("DataUpdatedNotification")
NotificationCenter.default.post(name: dataUpdated, object: nil, userInfo: nil)
})
// 将单利中的数据也删除
for item in data {
......
......@@ -117,13 +117,13 @@ class HomeOtherCollectionCell: UICollectionViewCell {
self.countLabel.text = "\(count) Videos"
}
// 设置文件大小文字
let sizeKB : Double = model.allFileSize/1024
if sizeKB < 1024{
let sizeKB : Double = model.allFileSize/1000
if sizeKB < 1000{
self.sizeLabel.text = String(format: "(%.2lf) KB" ,sizeKB)
}else if sizeKB < (1024 * 1024) && sizeKB > 1024{
self.sizeLabel.text = String(format: "(%.2lf) MB" ,sizeKB/1024)
}else if sizeKB < (1000 * 1000) && sizeKB > 1000{
self.sizeLabel.text = String(format: "(%.2lf) MB" ,sizeKB/1000)
}else{
self.sizeLabel.text = String(format: "(%.2lf) GB" ,sizeKB/(1024 * 1024))
self.sizeLabel.text = String(format: "(%.2lf) GB" ,sizeKB/(1000 * 1000))
}
}
......
......@@ -46,13 +46,13 @@ class HomeVideoDetailCell : UICollectionViewCell {
DispatchQueue.main.async {
// 确保在主线程更新UI
self.backImageView.image = thumbnailImage
let sizeKB : Double = Double(assetSize / 1024)
if sizeKB < 1024{
let sizeKB : Double = Double(assetSize / 1000)
if sizeKB < 1000{
self.saveSizeLabel.text = String(format: "%.2f KB" ,sizeKB)
}else if sizeKB < (1024 * 1024) && sizeKB > 1024{
self.saveSizeLabel.text = String(format: "%.2f MB" ,sizeKB/1024)
}else if sizeKB < (1000 * 1000) && sizeKB > 1000{
self.saveSizeLabel.text = String(format: "%.2f MB" ,sizeKB/1000)
}else{
self.saveSizeLabel.text = String(format: "%.2f GB" ,sizeKB/(1024 * 1024))
self.saveSizeLabel.text = String(format: "%.2f GB" ,sizeKB/(1000 * 1000))
}
}
} else {
......
......@@ -18,14 +18,16 @@ class PMShowVideoCell: UICollectionViewCell {
var type : Int = 0
func reload() -> Void {
var url : URL
var url : URL?
if type == 0 {
url = "SecretIm".document().appendingPathComponent(playURL)
}else{
url = homeResouceUrl!
url = homeResouceUrl
}
if let url = url {
player.playVideo(from: url)
player.pause()
}
player.playVideo(from: url)
player.pause()
}
override init(frame: CGRect) {
......
......@@ -185,14 +185,24 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa
// 相似视频
if collectionView == MaxCollection {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowVideoCellID, for: indexPath) as! PMShowVideoCell
cell.homeResouceUrl = self.url
// 这里主动获取下视频的链接
let ident = self.homeDataSource?[indexPath.row].id?.localIdentifier
if let ident = ident {
self.getVideoURLFromLocalIdentifier(localIdentifier: ident) { videoUrl, error in
if let videoUrl = videoUrl {
cell.homeResouceUrl = videoUrl
DispatchQueue.main.async {
cell.reload()
}
}
}
}
// 表示这个是视频
cell.type = 1
cell.reload()
return cell
}else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowItemCellID, for: indexPath) as! PMShowItemCell
cell.icon = self.homeDataSource![indexPath.row].image!
cell.icon = self.homeDataSource![indexPath.row].image ?? UIImage()
cell.isCurrent = (self.currentIdx == indexPath.row)
return cell
}
......
......@@ -63,9 +63,12 @@ class SecretVideoPlayer: UIView {
}
}
func playVideo(from url: URL) {
func playVideo(from url: URL?) {
if url == nil {
return
}
removeObservers()
player = AVPlayer(url: url)
player = AVPlayer(url: url!)
if let playerLayer = layer.sublayers?.first as? AVPlayerLayer {
playerLayer.player = player
}
......
......@@ -20,6 +20,9 @@ class WidgetPublicModel: NSObject {
return batt
}
/// 已使用
/// - Returns: 已使用空间
public class func UseDiskSpace() -> CGFloat {
let disk = getDiskSpace()
let use = disk.0 - disk.1
......@@ -27,6 +30,9 @@ class WidgetPublicModel: NSObject {
return useP
}
/// 获取总共和可用空间
/// - Returns: 总共和可用空间
public class func getDiskSpace() -> (Int64,Int64) {
let total = TotalDiskSize()
let available = AvailableDiskSize()
......@@ -43,9 +49,15 @@ class WidgetPublicModel: NSObject {
}
// 硬盘剩余大小
class func AvailableDiskSize() -> Int64 {
var fs = blankof(type: statfs.self)
if statfs("/var",&fs) >= 0 {
return Int64(UInt64(fs.f_bsize) * fs.f_bavail)
do {
let fileURL = URL(fileURLWithPath: NSHomeDirectory())
let values = try fileURL.resourceValues(forKeys: [.volumeAvailableCapacityForImportantUsageKey])
if let availableSpace = values.volumeAvailableCapacityForImportantUsage {
return Int64(availableSpace)
}
} catch {
print("获取磁盘空间信息时出错: \(error)")
return -1
}
return -1
}
......
......@@ -135,51 +135,6 @@ class PhotoAndVideoMananger {
}
func fetchAllFile(propress:@escaping (Int,Double) -> Void,completion: @escaping (Double,Int) -> Void) {
// if (self.allAssets.count == 0 ) {
//
// let fetchOptions = PHFetchOptions()
//
// let photoAllAssets = PHAsset.fetchAssets(with: .image, options: fetchOptions)
//
// let videoAllAssets = PHAsset.fetchAssets(with: .video, options: fetchOptions)
//
// let photoAssetsArray = photoAllAssets.objects(at: IndexSet(0..<photoAllAssets.count))
//
// let videoAssetsArray = videoAllAssets.objects(at: IndexSet(0..<videoAllAssets.count))
//
// let combinedArray = photoAssetsArray + videoAssetsArray
//
// DispatchQueue.global().async {[weak self] in
//
// guard let self = self else { return }
// // 计算总大小
// self.calculateTotalSize(of: combinedArray,progress: { fileSiez, index in
// propress(index,Double(fileSiez))
// }, completion: { fileSize,index in
// completion(Double(fileSize),index)
// })
//
// }
//
// }else {
//
//
// let combinedArray = self.allAssets
//
// DispatchQueue.global().async {[weak self] in
//
// guard let self = self else { return }
// // 计算总大小
// self.calculateTotalSize(of: combinedArray,progress: { fileSiez, index in
//
// propress(index,Double(fileSiez))
// }, completion: { fileSize,index in
// completion(Double(fileSize),index)
// })
//
// }
// }
let fetchOptions = PHFetchOptions()
let photoAllAssets = PHAsset.fetchAssets(with: .image, options: fetchOptions)
......@@ -517,18 +472,24 @@ class PhotoAndVideoMananger {
func getPhotoAssetSize(_ asset: PHAsset, completion: @escaping (Int64) -> Void) {
let options = PHImageRequestOptions()
options.isSynchronous = false
options.version = .original // 获取原始数据
// 获取原始数据
options.version = .original
// 不去计算iclound资源
options.isNetworkAccessAllowed = false
PHImageManager.default().requestImageDataAndOrientation(for: asset, options: options) { (data, _, _, _) in
let size = Int64(data?.count ?? 0)
completion(size)
}
}
func getVideoAssetSize(_ asset: PHAsset, completion: @escaping (Int64) -> Void) {
let options = PHVideoRequestOptions()
// 获取原始数据
options.version = .original
// 不去计算iclound资源
options.isNetworkAccessAllowed = false
PHImageManager.default().requestAVAsset(forVideo: asset, options: options) { (avAsset, _, _) in
if let urlAsset = avAsset as? AVURLAsset {
let size = try? urlAsset.url.resourceValues(forKeys: [.fileSizeKey]).fileSize ?? 0
......@@ -934,7 +895,7 @@ class PhotoAndVideoMananger {
// 获取当前版本的照片或视频
options.version = .current
// 尽可能快地提供结果
options.deliveryMode = .highQualityFormat
options.deliveryMode = .fastFormat
// 允许从iCloud请求
options.isNetworkAccessAllowed = true
// 异步请求
......@@ -1188,6 +1149,9 @@ class SecretPhotoManager: NSObject, PhotoPickerControllerDelegate , CameraContro
PMLoadingHUD.share.disMiss()
}
} else if let error = error {
DispatchQueue.main.async {
PMLoadingHUD.share.disMiss()
}
print("删除失败: \(error.localizedDescription)")
}
......
......@@ -30,8 +30,8 @@ func formatFileSize(_ bytes: Double) -> String {
var unitIndex = 0
// 循环计算合适的单位
while size >= 1024 && unitIndex < units.count - 1 {
size /= 1024
while size >= 1000 && unitIndex < units.count - 1 {
size /= 1000
unitIndex += 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