SPB Git

Repository Public

SettingsView.swift 6.4 KB 137 lines swift

1//2//  Auto-Ka iOS v23//  File: AutoKa/Features/More/SettingsView.swift4//  Description: réglages — apparence, animations d'ouverture, unités, données gardées sur l'appareil, versions.5//6//  Author: Simon-Pierre Boucher7//  Contact: contact@spboucher.ai8//910import SwiftUI1112struct SettingsView: View {13    @Environment(AppModel.self) private var model14    @Environment(Library.self) private var library15    @Environment(BoardingCenter.self) private var boarding16    @Environment(\.accessibilityReduceMotion) private var reduceMotion1718    @State private var confirmErase = false19    @State private var service: APIVersion?2021    var body: some View {22        @Bindable var model = model23        @Bindable var boarding = boarding24        Page(spacing: 30) {25            section("Apparence") {26                SlidingSegmented(selection: $model.appearance, options: Appearance.allCases.map { (value: $0, label: $0.label) }, label: "Apparence")27            }2829            section("Animations d'ouverture") {30                SlidingSegmented(selection: $boarding.preference, options: BoardingPreference.allCases.map { (value: $0, label: $0.label) }, label: "Animations d'ouverture")31                Text(motionNote).font(.footnote).foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true)32            }3334            section("Unités") {35                SlidingSegmented(selection: $model.units, options: DistanceUnit.allCases.map { (value: $0, label: $0.label) }, label: "Unités de distance")36                Text("Les sources publient le kilométrage en kilomètres. En milles, les valeurs sont converties et arrondies sur l'appareil ; les filtres de recherche restent en kilomètres.")37                    .font(.footnote).foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true)38            }3940            section("Données sur cet appareil") {41                Text("Auto-Ka n'a pas de compte. Favoris, comparaison, recherches et véhicules consultés ne quittent pas cet appareil.")42                    .font(.footnote).foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true)43                VStack(spacing: 0) {44                    Rule()45                    action("Effacer les recherches récentes") {46                        library.clearRecentSearches()47                        model.showToast("Recherches récentes effacées")48                    }49                    action("Effacer les véhicules consultés", detail: Fmt.plural(library.seenIDs.count, "fiche", "fiches")) {50                        library.clearSeen()51                        model.showToast("Historique effacé")52                    }53                    action("Tout effacer", detail: "Favoris, comparaison, recherches, historique", destructive: true) {54                        confirmErase = true55                    }56                }57            }5859            section("Versions") {60                VStack(spacing: 0) {61                    Rule()62                    FactRow(label: "Application", value: appVersion)63                    FactRow(label: "Service", value: service.map { "\($0.version ?? "—") (API \($0.api))" } ?? "—")64                    if let n = service?.publicListings {65                        FactRow(label: "Annonces publiques", value: Fmt.int(n))66                    }67                }68            }69        }70        .navigationTitle("Réglages")71        .navigationBarTitleDisplayMode(.inline)72        .confirmationDialog("Effacer toutes les données gardées sur cet appareil ?", isPresented: $confirmErase, titleVisibility: .visible) {73            Button("Tout effacer", role: .destructive) {74                library.eraseAll()75                model.showToast("Données effacées")76            }77            Button("Annuler", role: .cancel) {}78        } message: {79            Text("Favoris, comparaison, recherches et véhicules consultés seront supprimés. Cette action ne peut pas être annulée.")80        }81        .task { service = try? await APIClient.shared.version() }82    }8384    private var motionNote: String {85        var s: String86        switch boarding.preference {87        case .automatic:88            s = "À l'ouverture d'une fiche, la portière apparaît sur la photo, pivote vers vous et dévoile le véhicule ; puis le compteur roule jusqu'au kilométrage. Le geste complet joue aux premières ouvertures, une version courte ensuite."89        case .discreet:90            s = "La version courte du geste joue à chaque ouverture d'une fiche."91        case .off:92            s = "Les fiches s'ouvrent sans animation ; les autres mouvements de l'interface sont coupés aussi."93        }94        if reduceMotion, boarding.preference != .off {95            s += " « Réduire les animations » est activé dans les réglages d'accessibilité de l'appareil : la fiche s'affiche par un simple fondu."96        } else {97            s += " Un toucher interrompt toujours l'animation. Le réglage « Réduire les animations » de l'appareil est respecté."98        }99        return s100    }101102    private var appVersion: String {103        let info = Bundle.main.infoDictionary104        let v = info?["CFBundleShortVersionString"] as? String ?? "—"105        let b = info?["CFBundleVersion"] as? String ?? "—"106        return "\(v) (\(b))"107    }108109    private func section<Content: View>(_ title: String, @ViewBuilder content: () -> Content) -> some View {110        VStack(alignment: .leading, spacing: 12) {111            Text(title).font(.editorial(20)).foregroundStyle(Theme.ink).accessibilityAddTraits(.isHeader)112            content()113        }114    }115116    private func action(_ title: String, detail: String? = nil, destructive: Bool = false, perform: @escaping () -> Void) -> some View {117        Button(action: perform) {118            VStack(spacing: 0) {119                HStack {120                    VStack(alignment: .leading, spacing: 2) {121                        Text(title).font(.body).foregroundStyle(destructive ? Theme.bad : Theme.brand).multilineTextAlignment(.leading)122                        if let detail { Text(detail).font(.footnote).foregroundStyle(Theme.ink3).num().multilineTextAlignment(.leading) }123                    }124                    Spacer(minLength: 8)125                }126                .padding(.vertical, 12)127                .frame(minHeight: 48)128                .contentShape(Rectangle())129                Rule()130            }131        }132        .buttonStyle(.plain)133        .accessibilityElement(children: .combine)134        .accessibilityAddTraits(.isButton)135    }136}137
Files main
Menu

Theme