Improve cache settings view

This commit is contained in:
Christoph Hagen
2023-10-24 15:44:13 +02:00
parent d5edf360fb
commit f192e1c29d
6 changed files with 110 additions and 74 deletions

View File

@@ -0,0 +1,15 @@
import SwiftUI
struct CachedImageCountView: View {
@ObservedObject
var cache: ImageCache
var body: some View {
SettingsStatisticRow(label: "Downloaded images", value: "\(cache.imageCount)")
}
}
#Preview {
CachedImageCountView(cache: Database.mock.images)
}

View File

@@ -33,8 +33,22 @@ struct SettingsView: View {
.padding(.top)
Group {
SettingsStatisticRow(label: "Caps", value: "\(database.numberOfCaps)")
SettingsStatisticRow(label: "Total images", value: "\(database.numberOfImages)")
SettingsStatisticRow(label: "Images per cap", value: String(format: "%.1f", database.averageImageCount))
SettingsStatisticRow(label: "Total images", value: "\(database.numberOfImages)")
CachedImageCountView(cache: database.images)
SettingsStatisticRow(label: "Cache size", value: byteString(imageCacheSize))
SettingsStatisticRow(label: "Database", value: byteString(database.databaseSize))
if database.pendingImageUploadCount > 0 {
SettingsStatisticRow(label: "Images to upload", value: "\(database.pendingImageUploadCount)")
}
HStack {
Spacer()
Button(action: clearImageCache) {
Label("Clear image cache", systemSymbol: .trash)
}
.padding()
Spacer()
}
}.padding(.horizontal)
Text("Classifier")
.font(.footnote)
@@ -44,6 +58,7 @@ struct SettingsView: View {
Group {
SettingsStatisticRow(label: "Server Version", value: "\(database.serverClassifierVersion)")
SettingsStatisticRow(label: "Local Version", value: "\(database.localClassifierVersion)")
SettingsStatisticRow(label: "Size", value: byteString(database.classifierSize))
SettingsStatisticRow(label: "Recognized caps", value: "\(database.classifierClassCount)")
HStack {
Spacer()
@@ -65,24 +80,6 @@ struct SettingsView: View {
ClassifierDownloadView(progress: progress)
}
}.padding(.horizontal)
Text("Storage")
.font(.footnote)
.textCase(.uppercase)
.foregroundColor(.secondary)
.padding(.top)
Group {
SettingsStatisticRow(label: "Image cache", value: byteString(imageCacheSize))
SettingsStatisticRow(label: "Database", value: byteString(database.databaseSize))
SettingsStatisticRow(label: "Classifier", value: byteString(database.classifierSize))
HStack {
Spacer()
Button(action: clearImageCache) {
Label("Clear image cache", systemSymbol: .trash)
}
.padding()
Spacer()
}
}.padding(.horizontal)
Spacer()
}
.padding(.horizontal)
@@ -109,6 +106,7 @@ struct SettingsView: View {
// Ensure that correct version is saved
await database.updateServerClassifierVersion()
await database.downloadClassifier()
await database.downloadClassifierClasses()
}
}