|
@@ -11,6 +11,8 @@ import Kingfisher
|
|
import UIKit
|
|
import UIKit
|
|
|
|
|
|
class JDMineSettingViewController: BaseViewController {
|
|
class JDMineSettingViewController: BaseViewController {
|
|
|
|
+ var cacheStr: String = ""
|
|
|
|
+
|
|
lazy var tableView: UITableView = {
|
|
lazy var tableView: UITableView = {
|
|
let v = UITableView(frame: .zero, style: .plain)
|
|
let v = UITableView(frame: .zero, style: .plain)
|
|
v.delegate = self
|
|
v.delegate = self
|
|
@@ -88,6 +90,7 @@ class JDMineSettingViewController: BaseViewController {
|
|
|
|
|
|
override func viewDidLoad() {
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
super.viewDidLoad()
|
|
|
|
+
|
|
view.backgroundColor = color(248, 250, 254, 1)
|
|
view.backgroundColor = color(248, 250, 254, 1)
|
|
|
|
|
|
myNavigationBar.title_Label.text = switchLanguage("设置")
|
|
myNavigationBar.title_Label.text = switchLanguage("设置")
|
|
@@ -103,6 +106,8 @@ class JDMineSettingViewController: BaseViewController {
|
|
} else {
|
|
} else {
|
|
logoutBtn.setTitle(switchLanguage("登录"), for: .normal)
|
|
logoutBtn.setTitle(switchLanguage("登录"), for: .normal)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ updateData()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -113,8 +118,8 @@ extension JDMineSettingViewController: UITableViewDataSource {
|
|
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: JDMineSettingCell.description()) as! JDMineSettingCell
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: JDMineSettingCell.description()) as! JDMineSettingCell
|
|
-
|
|
|
|
cell.titleLb.text = titleAry[indexPath.row]
|
|
cell.titleLb.text = titleAry[indexPath.row]
|
|
|
|
+ cell.subTitleLb.text = cell.titleLb.text == switchLanguage("清除缓存") ? cacheStr : nil
|
|
return cell
|
|
return cell
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -125,7 +130,7 @@ extension JDMineSettingViewController: UITableViewDelegate {
|
|
v.backgroundColor = .white
|
|
v.backgroundColor = .white
|
|
return v
|
|
return v
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
return 5
|
|
return 5
|
|
}
|
|
}
|
|
@@ -153,8 +158,7 @@ extension JDMineSettingViewController: UITableViewDelegate {
|
|
} else if indexPath.row == 2 {
|
|
} else if indexPath.row == 2 {
|
|
UIAlertController.showAlert(in: self, title: switchLanguage("是否清除缓存?"), cancelTitle: switchLanguage("取消"), otherTitles: [switchLanguage("确认")]) { _, _, index in
|
|
UIAlertController.showAlert(in: self, title: switchLanguage("是否清除缓存?"), cancelTitle: switchLanguage("取消"), otherTitles: [switchLanguage("确认")]) { _, _, index in
|
|
if index == .sure {
|
|
if index == .sure {
|
|
- KingfisherManager.shared.cache.clearMemoryCache()
|
|
|
|
- KingfisherManager.shared.cache.clearDiskCache()
|
|
|
|
|
|
+ self.clearDiskMemory()
|
|
|
|
|
|
ProgressHUD.showSuccess(status: switchLanguage("缓存已清除"))
|
|
ProgressHUD.showSuccess(status: switchLanguage("缓存已清除"))
|
|
}
|
|
}
|
|
@@ -166,3 +170,51 @@ extension JDMineSettingViewController: UITableViewDelegate {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+extension JDMineSettingViewController {
|
|
|
|
+ func updateData() {
|
|
|
|
+ Task {
|
|
|
|
+ let cacheSize = await getCachSize()
|
|
|
|
+ await updateCacheData(withCacheSize: cacheSize)
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ self.tableView.reloadData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func getCachSize() async -> CGFloat {
|
|
|
|
+ do {
|
|
|
|
+ let cache = try await ImageCache.default.diskStorageSize
|
|
|
|
+ return CGFloat(cache) / 1024.0 / 1024.0
|
|
|
|
+ } catch {
|
|
|
|
+ return 0.0
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func clearDiskMemory() {
|
|
|
|
+ ImageCache.default.clearMemoryCache()
|
|
|
|
+ ImageCache.default.clearDiskCache {
|
|
|
|
+ self.updateData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func updateCacheData(withCacheSize cache: CGFloat) async {
|
|
|
|
+ var cacheStr: String
|
|
|
|
+
|
|
|
|
+ if abs(cache) <= 0.01 {
|
|
|
|
+ cacheStr = "0M"
|
|
|
|
+ } else {
|
|
|
|
+ if cache > 1024 {
|
|
|
|
+ cacheStr = String(format: "%.1fG", cache / 1024.0)
|
|
|
|
+ } else {
|
|
|
|
+ cacheStr = String(format: "%.1fM", cache)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if cacheStr.contains(".0") {
|
|
|
|
+ cacheStr = cacheStr.replacingOccurrences(of: ".0", with: "")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ self.cacheStr = cacheStr
|
|
|
|
+ }
|
|
|
|
+}
|