同步相册云盘界面并完善相关交互
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user