From 1dffd82236855e955629cb0f5f57513ae90710e0 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 24 May 2023 16:27:52 +0200 Subject: [PATCH] Small improvements --- LeCountdown/Sound/Sound.swift | 11 ++++++++++- LeCountdown/Views/ContentView.swift | 7 ++++++- LeCountdown/Views/Reusable/SoundFormView.swift | 2 +- LeCountdown/Views/Reusable/TimerModel.swift | 5 +++-- LeCountdown/Views/StartView.swift | 2 +- LeCountdown/Views/TimersView.swift | 1 - 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/LeCountdown/Sound/Sound.swift b/LeCountdown/Sound/Sound.swift index 01894c4..e8d05e5 100644 --- a/LeCountdown/Sound/Sound.swift +++ b/LeCountdown/Sound/Sound.swift @@ -77,7 +77,7 @@ enum Playlist: String, CaseIterable, Identifiable, Localized { case .nature: return NSLocalizedString("Nature", comment: "") case .stephanBodzin: - return "Boavista" + return "Stephan Bodzin - Boavista" case .custom: return NSLocalizedString("Custom", comment: "") case .relax: @@ -87,6 +87,15 @@ enum Playlist: String, CaseIterable, Identifiable, Localized { } } + var shortName: String { + switch self { + case .stephanBodzin: + return "Boavista" + default: + return self.localizedString + } + } + } // Sound id are stored thus case order should not be changed diff --git a/LeCountdown/Views/ContentView.swift b/LeCountdown/Views/ContentView.swift index dd2b877..5ec775a 100644 --- a/LeCountdown/Views/ContentView.swift +++ b/LeCountdown/Views/ContentView.swift @@ -27,6 +27,11 @@ struct ContentView: View { @State private var showStatsSheet: Bool = false @State private var showSubscriptionSheet: Bool = false + @FetchRequest( + sortDescriptors: [NSSortDescriptor(keyPath: \AbstractTimer.order, ascending: true)], + animation: .default) + private var timers: FetchedResults + var body: some View { VStack { @@ -56,7 +61,7 @@ struct ContentView: View { .foregroundColor(.black) .background(self._backgroundColor) .cornerRadius(32.0, corners: [.topRight, .topLeft]) - } else if let tip = self.showTip { + } else if let tip = self.showTip, self.timers.count > 0 { TipView(tip: tip) { Preferences.lastShownTip = tip.rawValue self.showTip = nil diff --git a/LeCountdown/Views/Reusable/SoundFormView.swift b/LeCountdown/Views/Reusable/SoundFormView.swift index efc0482..8200786 100644 --- a/LeCountdown/Views/Reusable/SoundFormView.swift +++ b/LeCountdown/Views/Reusable/SoundFormView.swift @@ -72,7 +72,7 @@ struct SoundLinkView: View { catalog: self.catalog) } } label: { - LabeledContent(self.title, value: self.soundModel.soundSelection) + LabeledContent(self.title, value: self.soundModel.soundSelection()) } } diff --git a/LeCountdown/Views/Reusable/TimerModel.swift b/LeCountdown/Views/Reusable/TimerModel.swift index 4bde9b3..a4bb1b2 100644 --- a/LeCountdown/Views/Reusable/TimerModel.swift +++ b/LeCountdown/Views/Reusable/TimerModel.swift @@ -52,9 +52,10 @@ class SoundModel: ObservableObject, SoundHolder { } } - var soundSelection: String { + func soundSelection(short: Bool = false) -> String { if self.playlists.count == 1 { - return self.playlists.first!.localizedString + let playlist = self.playlists.first! + return short ? playlist.shortName : playlist.localizedString } if !sounds.isEmpty { if sounds.count == 1 { diff --git a/LeCountdown/Views/StartView.swift b/LeCountdown/Views/StartView.swift index 0a148ac..194d9c8 100644 --- a/LeCountdown/Views/StartView.swift +++ b/LeCountdown/Views/StartView.swift @@ -160,7 +160,7 @@ struct SoundButtonView: View { self.showSoundSheet = true } label: { Image(systemName: "music.note") - Text(self.soundModel.soundSelection) + Text(self.soundModel.soundSelection(short: true)) }.sheet(isPresented: $showSoundSheet) { PlaylistsView(model: self.soundModel, catalog: .ring) diff --git a/LeCountdown/Views/TimersView.swift b/LeCountdown/Views/TimersView.swift index 6f1c14c..8326989 100644 --- a/LeCountdown/Views/TimersView.swift +++ b/LeCountdown/Views/TimersView.swift @@ -24,7 +24,6 @@ struct TimersView: View { private var timers: FetchedResults fileprivate let itemSpacing: CGFloat = 10.0 - var body: some View {