Implemented the Persisting the selected locale across launches on the ContentView view in the Sample app target.

This commit is contained in:
2026-07-05 21:04:29 +02:00
parent 58a6ec217f
commit cbb5703751
5 changed files with 99 additions and 13 deletions
+19 -3
View File
@@ -8,7 +8,8 @@ import SwiftUI
/// inside a navigation stack, and presents the transcribed text of every processed recording in a modal sheet of its own navigation stack.
/// A toolbar menu picks the locale of the spoken language to transcribe, and every pick kicks off the preinstallation of the locale's speech
/// model assets, whose download events surface as transient in-app notifications banners wearing the `Notifying` target's label
/// style overlaying the feature just below the navigation bar.
/// style overlaying the feature just below the navigation bar. The picked locale persists across launches in the user defaults, and is
/// restored realigned to the supported locales before the feature loads.
///
/// The services attached to the feature, the transcription shown in the sheet, and the notifier owning the notifications live in the view's
/// ``Model``; the view itself only renders it and forwards the feature's output, the picker's changes, and the sheet's dismissal. All
@@ -17,6 +18,10 @@ struct ContentView: View {
// MARK: Properties
/// The identifier of the picked locale, persisted across launches.
@AppStorage(Constant.Key.locale)
private var localeIdentifier: String = ""
/// The model that owns the attached services, the transcription presented in the modal sheet, and the notifier of the in-app
/// notifications.
@State
@@ -36,7 +41,8 @@ struct ContentView: View {
// MARK: Body
/// The content of the view: a navigation stack with the recording feature's view, attached to the model's services and expanded to fill
/// the available space, with a toolbar picker for the locale of the spoken language to transcribe, and a modal sheet presenting the
/// the available space, with a toolbar picker for the locale of the spoken language to transcribe restored from the user defaults
/// before the model loads, and persisted back on every change and a modal sheet presenting the
/// transcribed text of every processed recording or a content unavailable message when the transcription is empty closable
/// through its toolbar button or a swipe. The notifier's in-app notifications overlay the feature, stacking downward just below the
/// navigation bar; each one slides in from the leading edge when posted and out again when its scheduled dismissal arrives, without
@@ -70,12 +76,16 @@ struct ContentView: View {
stackNotifications
}
.task {
await model.load()
await model.load(
identifier: localeIdentifier
)
}
.onChange(
of: model.locale,
initial: false
) {
localeIdentifier = model.locale.identifier
model.preinstall()
}
}
@@ -211,6 +221,12 @@ private extension ContentView {
/// The constant values used across the view.
private enum Constant {
/// The key constants.
enum Key {
/// The user defaults key of the persisted locale identifier.
static let locale = "com.rock-n-code.app.attendi.sample.user-defaults.ket.selected-locale"
}
/// The spacing constants.
enum Spacing {
/// The spacing between the elements of a stack.