同步相册云盘界面并完善相关交互

This commit is contained in:
2026-07-10 17:15:15 +08:00
parent ab5220e460
commit ceca780ab3
13 changed files with 2269 additions and 532 deletions

View File

@ -24,15 +24,16 @@ enum CloudDriveFormatter {
///
static func fileDescription(_ file: CloudFile) -> String {
let createdDate = dateOnly(file.createdAt)
if file.isFolder {
return "\(file.childNum) 个项目"
return "\(createdDate) | \(file.childNum)个项目"
}
return "\(typeName(file.type)) \(fileSize(file.fileSize))"
return "\(createdDate) | \(fileSize(file.fileSize))"
}
///
static func fileSize(_ bytes: Int64) -> String {
guard bytes > 0 else { return "0B" }
guard bytes > 0 else { return "0 B" }
let units = ["B", "KB", "MB", "GB", "TB"]
var value = Double(bytes)
var index = 0
@ -40,10 +41,17 @@ enum CloudDriveFormatter {
value /= 1024
index += 1
}
if index == 0 {
return "\(Int(value))\(units[index])"
return String(format: "%.2f %@", value, units[index])
}
/// Android 使 yyyy-MM-dd
static func dateOnly(_ value: String) -> String {
guard !value.isEmpty else { return "" }
if value.count >= 10 {
let endIndex = value.index(value.startIndex, offsetBy: 10)
return String(value[..<endIndex])
}
return String(format: "%.1f%@", value, units[index])
return value
}
/// URL
@ -59,4 +67,13 @@ enum CloudDriveAsset {
static func image(named name: String, fallbackSystemName: String) -> UIImage? {
UIImage(named: name)?.withRenderingMode(.alwaysOriginal) ?? UIImage(systemName: fallbackSystemName)
}
///
static func resizedImage(named name: String, fallbackSystemName: String, size: CGSize) -> UIImage? {
guard let source = image(named: name, fallbackSystemName: fallbackSystemName) else { return nil }
let renderer = UIGraphicsImageRenderer(size: size)
return renderer.image { _ in
source.draw(in: CGRect(origin: .zero, size: size))
}.withRenderingMode(.alwaysOriginal)
}
}