Fix uploads, add server key entry

This commit is contained in:
Christoph Hagen
2022-06-11 11:27:56 +02:00
parent 093d82893b
commit 2b3ab859fc
10 changed files with 155 additions and 100 deletions

View File

@@ -0,0 +1,47 @@
import SwiftUI
import SFSafeSymbols
struct FancyTextField: View {
@Binding
var text: String
let icon: SFSymbol
let placeholder: String
let showClearButton: Bool = true
var body: some View {
TextField("Search", text: $text, prompt: Text(placeholder))
.padding(7)
.padding(.horizontal, 25)
.background(Color(.systemGray5))
.cornerRadius(8)
.overlay(
HStack {
Image(systemSymbol: icon)
.foregroundColor(.gray)
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
.padding(.leading, 8)
if showClearButton && text != "" {
Button(action: {
self.text = ""
}) {
Image(systemSymbol: .multiplyCircleFill)
.foregroundColor(.gray)
.padding(.trailing, 8)
}
}
}
)
}
}
struct FancyTextField_Previews: PreviewProvider {
static var previews: some View {
FancyTextField(text: .constant("Text"),
icon: .magnifyingglass,
placeholder: "Enter text")
}
}

View File

@@ -7,28 +7,7 @@ struct SearchField: View {
var searchString: String
var body: some View {
TextField("Search", text: $searchString, prompt: Text("Search..."))
.padding(7)
.padding(.horizontal, 25)
.background(Color(.systemGray5))
.cornerRadius(8)
.overlay(
HStack {
Image(systemSymbol: .magnifyingglass)
.foregroundColor(.gray)
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
.padding(.leading, 8)
if searchString != "" {
Button(action: {
self.searchString = ""
}) {
Image(systemSymbol: .multiplyCircleFill)
.foregroundColor(.gray)
.padding(.trailing, 8)
}
}
}
)
FancyTextField(text: $searchString, icon: .magnifyingglass, placeholder: "Search...")
}
}

View File

@@ -1,65 +1,68 @@
import SwiftUI
import SFSafeSymbols
struct SettingsView: View {
@EnvironmentObject
var database: Database
@Binding
var isPresented: Bool
@AppStorage("authKey")
private var serverAuthenticationKey: String = ""
var body: some View {
VStack(alignment: .leading, spacing: 3) {
HStack {
Text("Settings")
.font(.title2)
.bold()
NavigationView {
VStack(alignment: .leading, spacing: 3) {
Text("Authentication")
.font(.footnote)
.textCase(.uppercase)
.foregroundColor(.secondary)
.padding(.top)
Group {
FancyTextField(text: $serverAuthenticationKey, icon: .key, placeholder: "Server key")
}.padding(.horizontal)
Text("Statistics")
.font(.footnote)
.textCase(.uppercase)
.foregroundColor(.secondary)
.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))
}.padding(.horizontal)
Text("Classifier")
.font(.footnote)
.textCase(.uppercase)
.foregroundColor(.secondary)
.padding(.top)
Group {
SettingsStatisticRow(label: "Version", value: "\(database.classifierVersion)")
SettingsStatisticRow(label: "Recognized caps", value: "\(database.classifierClassCount)")
}.padding(.horizontal)
Text("Storage")
.font(.footnote)
.textCase(.uppercase)
.foregroundColor(.secondary)
.padding(.top)
Group {
SettingsStatisticRow(label: "Image cache", value: byteString(database.imageCacheSize))
SettingsStatisticRow(label: "Database", value: byteString(database.databaseSize))
SettingsStatisticRow(label: "Classifier", value: byteString(database.classifierSize))
}.padding(.horizontal)
Spacer()
Button(action: hide) {
Image(systemSymbol: .xmarkCircleFill)
.foregroundColor(.gray)
.font(.system(size: 26))
}
}
Text("Statistics")
.font(.footnote)
.textCase(.uppercase)
.foregroundColor(.secondary)
.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))
}.padding(.horizontal)
Text("Classifier")
.font(.footnote)
.textCase(.uppercase)
.foregroundColor(.secondary)
.padding(.top)
Group {
SettingsStatisticRow(label: "Version", value: "\(database.classifierVersion)")
SettingsStatisticRow(label: "Recognized caps", value: "\(database.classifierClassCount)")
}.padding(.horizontal)
Text("Storage")
.font(.footnote)
.textCase(.uppercase)
.foregroundColor(.secondary)
.padding(.top)
Group {
SettingsStatisticRow(label: "Image cache", value: byteString(database.imageCacheSize))
SettingsStatisticRow(label: "Database", value: byteString(database.databaseSize))
SettingsStatisticRow(label: "Classifier", value: byteString(database.classifierSize))
}.padding(.horizontal)
Spacer()
.padding(.horizontal)
.navigationTitle("Settings")
}
.padding(.horizontal)
}
private func hide() {
isPresented = false
}
private func byteString(_ count: Int) -> String {
ByteCountFormatter.string(fromByteCount: Int64(count), countStyle: .file)
}
@@ -69,6 +72,6 @@ struct SettingsView_Previews: PreviewProvider {
static var previews: some View {
SettingsView(isPresented: .constant(true))
.environmentObject(Database.mock)
.previewLayout(.fixed(width: 375, height: 330))
//.previewLayout(.fixed(width: 375, height: 410))
}
}