fix: remove magic numbers to make it clear and robust
This commit is contained in:
parent
db3d16be41
commit
ceba2772c1
|
@ -301,33 +301,41 @@ extension SettingsViewController: UITableViewDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
guard indexPath.section == 2 || indexPath.section == 3 else { return }
|
let snapshot = self.viewModel.dataSource.snapshot()
|
||||||
|
let sectionIds = snapshot.sectionIdentifiers
|
||||||
|
guard indexPath.section < sectionIds.count else { return }
|
||||||
|
let sectionIdentifier = sectionIds[indexPath.section]
|
||||||
|
let items = snapshot.itemIdentifiers(inSection: sectionIdentifier)
|
||||||
|
guard indexPath.row < items.count else { return }
|
||||||
|
let item = items[indexPath.item]
|
||||||
|
|
||||||
if indexPath.section == 2 {
|
switch item {
|
||||||
|
case .boringZone:
|
||||||
coordinator.present(
|
coordinator.present(
|
||||||
scene: .safari(url: URL(string: "https://mastodon.online/terms")!),
|
scene: .safari(url: URL(string: "https://mastodon.online/terms")!),
|
||||||
from: self,
|
from: self,
|
||||||
transition: .safariPresent(animated: true, completion: nil)
|
transition: .safariPresent(animated: true, completion: nil)
|
||||||
)
|
)
|
||||||
}
|
case .spicyZone(let link):
|
||||||
|
// clear media cache
|
||||||
// clear media cache
|
if link.title == L10n.Scene.Settings.Section.Spicyzone.clear {
|
||||||
if indexPath.section == 3, indexPath.row == 0 {
|
// clean image cache for AlamofireImage
|
||||||
// clean image cache for AlamofireImage
|
let diskBytes = ImageDownloader.defaultURLCache().currentDiskUsage
|
||||||
let diskBytes = ImageDownloader.defaultURLCache().currentDiskUsage
|
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: diskBytes %d", ((#file as NSString).lastPathComponent), #line, #function, diskBytes)
|
||||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: diskBytes %d", ((#file as NSString).lastPathComponent), #line, #function, diskBytes)
|
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: clean image cache", ((#file as NSString).lastPathComponent), #line, #function)
|
||||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: clean image cache", ((#file as NSString).lastPathComponent), #line, #function)
|
ImageDownloader.defaultURLCache().removeAllCachedResponses()
|
||||||
ImageDownloader.defaultURLCache().removeAllCachedResponses()
|
let cleanedDiskBytes = ImageDownloader.defaultURLCache().currentDiskUsage
|
||||||
let cleanedDiskBytes = ImageDownloader.defaultURLCache().currentDiskUsage
|
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: diskBytes %d", ((#file as NSString).lastPathComponent), #line, #function, cleanedDiskBytes)
|
||||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: diskBytes %d", ((#file as NSString).lastPathComponent), #line, #function, cleanedDiskBytes)
|
|
||||||
|
// clean Kingfisher Cache
|
||||||
// clean Kingfisher Cache
|
KingfisherManager.shared.cache.clearDiskCache()
|
||||||
KingfisherManager.shared.cache.clearDiskCache()
|
}
|
||||||
}
|
// logout
|
||||||
|
if link.title == L10n.Scene.Settings.Section.Spicyzone.signout {
|
||||||
// logout
|
alertToSignout()
|
||||||
if indexPath.section == 3, indexPath.row == 1 {
|
}
|
||||||
alertToSignout()
|
default:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,10 +245,10 @@ class SettingsViewModel: NSObject, NeedsDependency {
|
||||||
L10n.Scene.Settings.Section.Spicyzone.signout]
|
L10n.Scene.Settings.Section.Spicyzone.signout]
|
||||||
var spicyLinkItems = [SettingsItem]()
|
var spicyLinkItems = [SettingsItem]()
|
||||||
for l in spicyLinks {
|
for l in spicyLinks {
|
||||||
let item = SettingsItem.boringZone(item: SettingsItem.Link(title: l, color: .systemRed))
|
let item = SettingsItem.spicyZone(item: SettingsItem.Link(title: l, color: .systemRed))
|
||||||
spicyLinkItems.append(item)
|
spicyLinkItems.append(item)
|
||||||
}
|
}
|
||||||
let spicySection = SettingsSection.boringZone(title: L10n.Scene.Settings.Section.Spicyzone.title, items: spicyLinkItems)
|
let spicySection = SettingsSection.spicyZone(title: L10n.Scene.Settings.Section.Spicyzone.title, items: spicyLinkItems)
|
||||||
snapshot.appendSections([spicySection])
|
snapshot.appendSections([spicySection])
|
||||||
snapshot.appendItems(spicyLinkItems)
|
snapshot.appendItems(spicyLinkItems)
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ enum SettingsSection: Hashable {
|
||||||
case apperance(title: String, selectedMode: SettingsItem)
|
case apperance(title: String, selectedMode: SettingsItem)
|
||||||
case notifications(title: String, items: [SettingsItem])
|
case notifications(title: String, items: [SettingsItem])
|
||||||
case boringZone(title: String, items: [SettingsItem])
|
case boringZone(title: String, items: [SettingsItem])
|
||||||
case spicyZone(tilte: String, items: [SettingsItem])
|
case spicyZone(title: String, items: [SettingsItem])
|
||||||
|
|
||||||
var title: String {
|
var title: String {
|
||||||
switch self {
|
switch self {
|
||||||
|
|
Loading…
Reference in New Issue