fixed SettingsViewController not updating after clearing caches

Fixes #1791

Signed-off-by: Daniel Standfest <daniel@standfest.io>
This commit is contained in:
Daniel Standfest 2024-10-23 23:20:02 +02:00
Родитель f6f93ea915
Коммит d3d1d5bbfd
1 изменённых файлов: 26 добавлений и 15 удалений

Просмотреть файл

@ -120,18 +120,8 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate, U
NotificationCenter.default.addObserver(self, selector: #selector(contactsAccessHasBeenUpdated(notification:)), name: NSNotification.Name.NCContactsManagerContactsAccessUpdated, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userProfileImageUpdated), name: NSNotification.Name.NCUserProfileImageUpdated, object: nil)
let imageCacheSize = NCImageSessionManager.shared.cache.currentDiskUsage
let sdImageCacheSize = SDImageCache.shared.totalDiskSize()
self.totalImageCacheSize = imageCacheSize + Int(sdImageCacheSize)
let fileController = NCChatFileController()
let talkAccounts = NCDatabaseManager.sharedInstance().allAccounts()
if let talkAccounts = talkAccounts as? [TalkAccount] {
for account in talkAccounts {
self.totalFileCacheSize += Int(fileController.getDiskUsage(for: account))
}
}
self.updateTotalImageCacheSize()
self.updateTotalFileCacheSize()
self.adaptInterfaceForAppState(appState: NCConnectionController.sharedInstance().appState)
}
@ -556,9 +546,10 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate, U
NCImageSessionManager.shared.cache.removeAllCachedResponses()
SDImageCache.shared.clearMemory()
SDImageCache.shared.clearDisk()
self.tableView.reloadData()
SDImageCache.shared.clearDisk {
self.updateTotalImageCacheSize()
self.tableView.reloadData()
}
}
clearCacheDialog.addAction(clearAction)
@ -584,6 +575,7 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate, U
}
}
self.updateTotalFileCacheSize()
self.tableView.reloadData()
}
clearCacheDialog.addAction(clearAction)
@ -1025,4 +1017,23 @@ extension SettingsTableViewController {
return NCAPIController.sharedInstance().userProfileImage(for: account, with: self.traitCollection.userInterfaceStyle)
}
func updateTotalImageCacheSize() {
let imageCacheSize = NCImageSessionManager.shared.cache.currentDiskUsage
let sdImageCacheSize = SDImageCache.shared.totalDiskSize()
self.totalImageCacheSize = imageCacheSize + Int(sdImageCacheSize)
}
func updateTotalFileCacheSize() {
self.totalFileCacheSize = 0
let fileController = NCChatFileController()
let talkAccounts = NCDatabaseManager.sharedInstance().allAccounts()
if let talkAccounts = talkAccounts as? [TalkAccount] {
for account in talkAccounts {
self.totalFileCacheSize += Int(fileController.getDiskUsage(for: account))
}
}
}
}