From 32bd299739d6a6b6a72521e9e3e992003523d459 Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 9 Mar 2023 15:49:34 +0100 Subject: [PATCH] update look and feel --- LeCountdown/Stats/Stat.swift | 18 +- LeCountdown/Subscription/Store.swift | 10 - .../Utils/TimeInterval+Extensions.swift | 4 + LeCountdown/Views/HomeView.swift | 3 +- LeCountdown/Views/PresetsView.swift | 272 +++++++++--------- LeCountdown/Views/Stats/GraphsView.swift | 38 ++- LeCountdown/Views/Stats/RecordsView.swift | 11 +- LeCountdown/fr.lproj/Localizable.strings | 8 +- 8 files changed, 186 insertions(+), 178 deletions(-) diff --git a/LeCountdown/Stats/Stat.swift b/LeCountdown/Stats/Stat.swift index 07caea9..253233d 100644 --- a/LeCountdown/Stats/Stat.swift +++ b/LeCountdown/Stats/Stat.swift @@ -16,7 +16,7 @@ enum Stat: Int, CaseIterable { var localizedName: String { switch self { case .count: return NSLocalizedString("Count", comment: "") - case .totalDuration: return NSLocalizedString("Duration", comment: "") + case .totalDuration: return NSLocalizedString("Total duration", comment: "") case .averageDuration: return NSLocalizedString("Average duration", comment: "") } } @@ -56,14 +56,14 @@ enum Stat: Int, CaseIterable { } } - var calendarYUnit: Calendar.Component? { - switch self { - case .totalDuration, .averageDuration: - return .hour - default: - return nil - } - } +// var calendarYUnit: Calendar.Component? { +// switch self { +// case .totalDuration, .averageDuration: +// return .hour +// default: +// return nil +// } +// } } diff --git a/LeCountdown/Subscription/Store.swift b/LeCountdown/Subscription/Store.swift index 868272a..c7136cb 100644 --- a/LeCountdown/Subscription/Store.swift +++ b/LeCountdown/Subscription/Store.swift @@ -8,19 +8,11 @@ import Foundation import StoreKit -//public enum StoreError: Error { -// case failedVerification -//} - protocol StoreDelegate { func productsReceived() func errorDidOccur(error: Error) } -//extension Notification.Name { -// static let StoreEventHappened = Notification.Name("storePurchaseSucceeded") -//} - class Store: ObservableObject { @Published private(set) var products: [Product] = [] @@ -52,8 +44,6 @@ class Store: ObservableObject { @MainActor func requestProducts() async { do { - - let currentPlan = AppGuard.main.currentPlan let identifiers: [String] = [StorePlan.unlimited.rawValue] products = try await Product.products(for: identifiers) Logger.log("products = \(self.products.count)") diff --git a/LeCountdown/Utils/TimeInterval+Extensions.swift b/LeCountdown/Utils/TimeInterval+Extensions.swift index 7267ebd..36b4010 100644 --- a/LeCountdown/Utils/TimeInterval+Extensions.swift +++ b/LeCountdown/Utils/TimeInterval+Extensions.swift @@ -9,6 +9,10 @@ import Foundation extension TimeInterval { + var hourMinuteSecond: String { + return String(format:"%d:%02d:%02d", hour, minute, second) + } + var hourMinuteSecondHS: String { let h = self.hour if h > 1 { diff --git a/LeCountdown/Views/HomeView.swift b/LeCountdown/Views/HomeView.swift index faea315..2f0db8e 100644 --- a/LeCountdown/Views/HomeView.swift +++ b/LeCountdown/Views/HomeView.swift @@ -22,7 +22,7 @@ struct CompactHomeView: View { var body: some View { - NavigationView { + NavigationStack { TabView(selection: $tabSelection) { PresetsView(tabSelection: $tabSelection) @@ -39,6 +39,7 @@ struct CompactHomeView: View { .tabItem { Label("Stats", systemImage: "chart.bar.fill") } .tag(2) } + .navigationBarTitleDisplayMode(NavigationBarItem.TitleDisplayMode.large) .tabViewStyle(.page(indexDisplayMode: .never)) } .onAppear { diff --git a/LeCountdown/Views/PresetsView.swift b/LeCountdown/Views/PresetsView.swift index fac267f..8791c0b 100644 --- a/LeCountdown/Views/PresetsView.swift +++ b/LeCountdown/Views/PresetsView.swift @@ -7,6 +7,140 @@ import SwiftUI +class PresetModel : ObservableObject { + + @Published var selectedPreset: Preset = Preset.hardBoiledEggs + +} + +struct PresetsView: View { + + @Environment(\.managedObjectContext) private var viewContext + + @StateObject var model: PresetModel = PresetModel() + + @State var isPresented: Bool = false + + @State var isShowingNewCountdown = false + @State var isShowingNewStopwatch = false + + var tabSelection: Binding + + fileprivate func _columnCount() -> Int { + return 2 + +// #if os(iOS) +// if UIDevice.isPhoneIdiom { +// return 2 +// } else { +// return 3 +// } +// #else +// return 3 +// #endif + } + + fileprivate func _columns() -> [GridItem] { + return (0.. - - fileprivate func _columnCount() -> Int { - return 2 - -// #if os(iOS) -// if UIDevice.isPhoneIdiom { -// return 2 -// } else { -// return 3 -// } -// #else -// return 3 -// #endif - } - - fileprivate func _columns() -> [GridItem] { - return (0.. String { + let text: String? + switch self { + case .count: + text = axisValue.as(Int.self)?.formatted() + case .totalDuration, .averageDuration: + text = axisValue.as(Double.self)?.hourMinuteSecond + } + return text ?? NSLocalizedString("Formatting failed", comment: "") + } + +} + struct StatGraphView_Previews: PreviewProvider { static let points: [Point] = [Point(date: Date(), value: 1), diff --git a/LeCountdown/Views/Stats/RecordsView.swift b/LeCountdown/Views/Stats/RecordsView.swift index 5588dac..edaa12e 100644 --- a/LeCountdown/Views/Stats/RecordsView.swift +++ b/LeCountdown/Views/Stats/RecordsView.swift @@ -26,13 +26,10 @@ struct RecordsView: View { let filters: [Filter] var body: some View { - -// Section { - ForEach(self.filters) { filter in - RecordsSectionView(activity: self.activity, filter: filter) - .environment(\.managedObjectContext, viewContext) - } -// } + ForEach(self.filters) { filter in + RecordsSectionView(activity: self.activity, filter: filter) + .environment(\.managedObjectContext, viewContext) + } } } diff --git a/LeCountdown/fr.lproj/Localizable.strings b/LeCountdown/fr.lproj/Localizable.strings index cf7271c..481443e 100644 --- a/LeCountdown/fr.lproj/Localizable.strings +++ b/LeCountdown/fr.lproj/Localizable.strings @@ -1,8 +1,8 @@ /* No comment provided by engineer. */ -".create countdown" = ".Créer un minuteur"; +"Create countdown" = "Créer un minuteur"; /* No comment provided by engineer. */ -".create stopwatch" = ".Créer un chrono"; +"Create stopwatch" = "Créer un chrono"; /* No comment provided by engineer. */ "Activities" = "Activités"; @@ -65,7 +65,7 @@ "Done" = "Sauver"; /* No comment provided by engineer. */ -"Duration" = "Durée"; +"Total duration" = "Durée totale"; /* No comment provided by engineer. */ "Edit" = "Editer"; @@ -229,7 +229,7 @@ "You can ask Siri to create and launch countdowns and stopwatches" = "Vous pouvez demander à Siri de vous lancer les minuteurs et les chronos"; /* No comment provided by engineer. */ -"You can edit the duration, sound and label before adding" = "Vous pouvez changer la durée, le son et le label avant l'ajout"; +"You can edit the duration, sound and label before adding" = "Vous pourrez changer la durée, le son et le label avant l'ajout"; /* No comment provided by engineer. */ "You don't have any recorded activity yet" = "Vous n'avez pas encore d'activités enregistrées";