D.10 401-Handling: APIError.unauthorized, NotificationCenter-Bridge, AuthSession.logout() bei 401 → User landet wieder im Login D.12 PWA-Deep-Links: Settings-Section mit Forum/Hunde/Walks/Settings öffnet Safari per https://banyaro.app/#fragment B.4 Auto-Pause: 2-min-Inaktivität → isAutoPaused, automatischer Resume bei nächstem GPS-Update. Settings-Toggle, im UI eigenes Badge "Auto-Pause" (grau vs. Pause orange). C.7 Edit/Delete: RouteUpdateBody + APIClient.patch + APIClient.delete, EditRouteSheet (Name/Beschreibung/Public), Menu in Toolbar (nur eigene Touren), Alert für Delete. C.9 Statistik-Tab: neuer Tab "Statistik" zwischen Hunde und Mehr. Filtert /api/routes auf meine Touren, rechnet Woche/Monat/Allzeit (Distanz, Dauer, Touren), Längste Tour, aktuelle Streak (Tage in Folge). B.5 Walk-Review: Map-Header an die Spitze des FinishWalkSheet-Forms. B.6 Geo-Fotos: CapturedPhoto (Data + GPSPoint?), PhotoLocation @Model in SwiftData. Kamera während Walk taggt mit tracker.points.last. Nach Upload: foto_url aus Response → PhotoLocation persistiert. MiniRouteMap rendert Annotations mit Tap-Callback, PhotoViewerSheet zeigt Foto fullscreen. C.8 Share PNG+GPX: RouteShareImage (MKMapSnapshotter + Polyline overlay + SwiftUI ShareCard via ImageRenderer), GPXExporter (Tempfile mit XML), ShareSheet (UIActivityViewController-Wrapper), Menu in Route-Toolbar. D.11 Icon-Varianten: AppIcon-Dark (0.45 Brightness), AppIcon-Tinted (Grayscale + Kontrastverstärkung), Contents.json mit appearance entries. A.2 HealthKit: BanYaroGo.entitlements (com.apple.developer.healthkit), NSHealthShare/UpdateUsageDescription. WalkHealthSync.shared mit HKWorkoutBuilder (.walking) + HKWorkoutRouteBuilder, Timestamps gleichmäßig über Walk-Dauer verteilt. Settings-Toggle mit Permission-Request.
169 lines
6.5 KiB
Swift
169 lines
6.5 KiB
Swift
import SwiftUI
|
|
|
|
struct SettingsView: View {
|
|
@Environment(AuthSession.self) private var auth
|
|
@AppStorage("autoPauseEnabled") private var autoPauseEnabled = true
|
|
@AppStorage("healthKitSyncEnabled") private var healthKitSyncEnabled = false
|
|
@State private var showHealthPermissionAlert = false
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
Form {
|
|
Section {
|
|
HStack(spacing: 14) {
|
|
avatarView
|
|
.frame(width: 60, height: 60)
|
|
.clipShape(Circle())
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text(displayName)
|
|
.font(.headline)
|
|
if let email = auth.profile?.email {
|
|
Text(email)
|
|
.font(.footnote)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
}
|
|
.padding(.vertical, 4)
|
|
}
|
|
|
|
Section("Account") {
|
|
LabeledContent("Rolle", value: rolleLabel)
|
|
if auth.profile?.isFounderFlag == true {
|
|
LabeledContent("Founder", value: founderLabel)
|
|
}
|
|
if auth.profile?.isPartnerFlag == true {
|
|
LabeledContent("Partner", value: "Ja")
|
|
}
|
|
if let tier = auth.profile?.subscriptionTier, !tier.isEmpty {
|
|
LabeledContent("Abo", value: tier.capitalized)
|
|
}
|
|
LabeledContent("Premium", value: premiumValue ? "Ja" : "Nein")
|
|
}
|
|
|
|
if let wohnort = auth.profile?.wohnort, !wohnort.isEmpty {
|
|
Section("Ort") {
|
|
Text(wohnort)
|
|
}
|
|
}
|
|
|
|
Section {
|
|
Toggle(isOn: $autoPauseEnabled) {
|
|
Label("Auto-Pause", systemImage: "pause.circle")
|
|
}
|
|
Toggle(isOn: $healthKitSyncEnabled) {
|
|
Label("Apple Health Sync", systemImage: "heart.fill")
|
|
}
|
|
.onChange(of: healthKitSyncEnabled) { _, newValue in
|
|
if newValue {
|
|
Task {
|
|
let granted = await WalkHealthSync.shared.requestAuthorization()
|
|
if !granted {
|
|
healthKitSyncEnabled = false
|
|
showHealthPermissionAlert = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} header: {
|
|
Text("Aufnahme")
|
|
} footer: {
|
|
Text("Auto-Pause: pausiert die Aufnahme, wenn du 2 Minuten lang stehen bleibst.\nApple Health: schreibt jede gespeicherte Tour als Spaziergang-Workout mit Route in Health.")
|
|
}
|
|
|
|
Section("Mehr auf banyaro.app") {
|
|
pwaLink("Forum", systemImage: "bubble.left.and.bubble.right.fill", fragment: "forum")
|
|
pwaLink("Hunde-Profile bearbeiten", systemImage: "pawprint.fill", fragment: "dogs")
|
|
pwaLink("Gassi-Treffen", systemImage: "person.2.fill", fragment: "walks")
|
|
pwaLink("Profil & Einstellungen", systemImage: "gearshape.fill", fragment: "settings")
|
|
}
|
|
|
|
Section {
|
|
Button("Abmelden", role: .destructive) {
|
|
auth.logout()
|
|
}
|
|
}
|
|
|
|
Section("Über") {
|
|
Text("Ban Yaro Go ist die native iOS-Ergänzung zur banyaro.app PWA. Phase 1: deine Touren ansehen.")
|
|
.font(.footnote)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
.navigationTitle("Mehr")
|
|
.refreshable { await auth.loadProfile() }
|
|
.alert("Apple Health hat den Zugriff verweigert", isPresented: $showHealthPermissionAlert) {
|
|
Button("OK", role: .cancel) {}
|
|
} message: {
|
|
Text("Du kannst die Berechtigung in den iOS-Einstellungen unter Datenschutz & Sicherheit → Health → Ban Yaro Go nachträglich ändern.")
|
|
}
|
|
}
|
|
}
|
|
|
|
private var displayName: String {
|
|
auth.profile?.name ?? auth.userName ?? "—"
|
|
}
|
|
|
|
private var premiumValue: Bool {
|
|
auth.profile?.isPremium ?? auth.isPremium
|
|
}
|
|
|
|
private var rolleLabel: String {
|
|
switch auth.profile?.rolle?.lowercased() {
|
|
case "admin": return "Admin"
|
|
case "moderator": return "Moderator"
|
|
case nil: return "—"
|
|
default: return "Mitglied"
|
|
}
|
|
}
|
|
|
|
private var founderLabel: String {
|
|
if let n = auth.profile?.founderNumber { return "#\(n)" }
|
|
return "Ja"
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var avatarView: some View {
|
|
if let path = auth.profile?.avatarUrl, !path.isEmpty,
|
|
let url = avatarURL(path) {
|
|
AsyncImage(url: url) { phase in
|
|
switch phase {
|
|
case .success(let img): img.resizable().scaledToFill()
|
|
default: avatarPlaceholder
|
|
}
|
|
}
|
|
} else {
|
|
avatarPlaceholder
|
|
}
|
|
}
|
|
|
|
private var avatarPlaceholder: some View {
|
|
ZStack {
|
|
Color.accentColor.opacity(0.2)
|
|
Image(systemName: "person.crop.circle.fill")
|
|
.font(.system(size: 36))
|
|
.foregroundStyle(Color.accentColor)
|
|
}
|
|
}
|
|
|
|
private func avatarURL(_ path: String) -> URL? {
|
|
if path.hasPrefix("http") { return URL(string: path) }
|
|
return URL(string: "https://banyaro.app\(path)")
|
|
}
|
|
|
|
@ViewBuilder
|
|
private func pwaLink(_ title: String, systemImage: String, fragment: String) -> some View {
|
|
if let url = URL(string: "https://banyaro.app/#\(fragment)") {
|
|
Link(destination: url) {
|
|
HStack {
|
|
Label(title, systemImage: systemImage)
|
|
.foregroundStyle(.primary)
|
|
Spacer()
|
|
Image(systemName: "arrow.up.right.square")
|
|
.font(.caption)
|
|
.foregroundStyle(.tertiary)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|