From 70074caeae00bca8dd6351a496747e9e25af35d3 Mon Sep 17 00:00:00 2001 From: Jeff Hokit Date: Fri, 27 Jan 2023 15:35:51 -0800 Subject: [PATCH 1/2] fix: updated for new timer api --- Astro Launches.xcodeproj/project.pbxproj | 20 +-- .../xcshareddata/swiftpm/Package.resolved | 4 +- Shared/CentralTimer.swift | 12 -- Shared/Views/Countdown.swift | 157 ------------------ Shared/Views/LaunchImage.swift | 20 ++- tvOS/LaunchView.swift | 13 +- 6 files changed, 24 insertions(+), 202 deletions(-) delete mode 100644 Shared/CentralTimer.swift delete mode 100644 Shared/Views/Countdown.swift diff --git a/Astro Launches.xcodeproj/project.pbxproj b/Astro Launches.xcodeproj/project.pbxproj index f9c264a..d4dd486 100644 --- a/Astro Launches.xcodeproj/project.pbxproj +++ b/Astro Launches.xcodeproj/project.pbxproj @@ -18,11 +18,9 @@ 7C3CB5D8270F4F98000448C6 /* LaunchTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C3CB5D5270F4F98000448C6 /* LaunchTime.swift */; }; 7C3CB5DA270F4FA4000448C6 /* LaunchDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C3CB5D9270F4FA4000448C6 /* LaunchDate.swift */; }; 7C3CB5DC270F4FA4000448C6 /* LaunchDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C3CB5D9270F4FA4000448C6 /* LaunchDate.swift */; }; - 7C3CB5DE270F4FD1000448C6 /* Countdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C3CB5DD270F4FD1000448C6 /* Countdown.swift */; }; 7C3D4CCE2603EFDA00CB0C41 /* LaunchCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C3D4CCD2603EFDA00CB0C41 /* LaunchCard.swift */; }; 7C44C05C2608FEDB00B8D86A /* launches.json in Resources */ = {isa = PBXBuildFile; fileRef = 7C44C05B2608FEDB00B8D86A /* launches.json */; }; 7C44C05F2608FEDB00B8D86A /* launches.json in Resources */ = {isa = PBXBuildFile; fileRef = 7C44C05B2608FEDB00B8D86A /* launches.json */; }; - 7C47D6182710B53100F5997E /* Countdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C3CB5DD270F4FD1000448C6 /* Countdown.swift */; }; 7C4DB82229035144007088A5 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C4DB82129035144007088A5 /* SettingsView.swift */; }; 7C54438026178C65007CCCC4 /* DateFormatters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C54437F26178C65007CCCC4 /* DateFormatters.swift */; }; 7C5A1AFB261BB51A00E452DE /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CD3C90426028B020071FB78 /* NetworkManager.swift */; }; @@ -41,8 +39,6 @@ 7C79988326FB7EC700FCAEF2 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C79988226FB7EC700FCAEF2 /* Colors.swift */; }; 7C83150125AE52B700E18441 /* AstroSwiftFoundation in Frameworks */ = {isa = PBXBuildFile; productRef = 7C83150025AE52B700E18441 /* AstroSwiftFoundation */; }; 7C834938260931D1008B4895 /* AppSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C834937260931D1008B4895 /* AppSettings.swift */; }; - 7C8976C227556A8F000815F7 /* CentralTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8976C127556A8F000815F7 /* CentralTimer.swift */; }; - 7C8976C427556A8F000815F7 /* CentralTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8976C127556A8F000815F7 /* CentralTimer.swift */; }; 7C8BFBF1270374BD00D6AB09 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7CF87F1B25AE45F300BD9D06 /* Assets.xcassets */; }; 7C8BFBF22703808C00D6AB09 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C79988226FB7EC700FCAEF2 /* Colors.swift */; }; 7C92392028E394CD00364E5A /* AstroLaunchesApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CF87F1825AE45F300BD9D06 /* AstroLaunchesApp.swift */; }; @@ -58,8 +54,6 @@ 7CE6154B28D91F550082459A /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CD3C90426028B020071FB78 /* NetworkManager.swift */; }; 7CE6154C28D91F550082459A /* DateFormatters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C54437F26178C65007CCCC4 /* DateFormatters.swift */; }; 7CE6154E28D91F550082459A /* LaunchTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C3CB5D5270F4F98000448C6 /* LaunchTime.swift */; }; - 7CE6155328D91F550082459A /* Countdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C3CB5DD270F4FD1000448C6 /* Countdown.swift */; }; - 7CE6155428D91F550082459A /* CentralTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8976C127556A8F000815F7 /* CentralTimer.swift */; }; 7CE6155528D91F550082459A /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C79988226FB7EC700FCAEF2 /* Colors.swift */; }; 7CE6155628D91F550082459A /* PadMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C9BDD87271642EC00A97374 /* PadMap.swift */; }; 7CE6155828D91F550082459A /* LaunchDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C3CB5D9270F4FA4000448C6 /* LaunchDate.swift */; }; @@ -92,7 +86,6 @@ 7C31CEB827F7BC3D00EA2DCC /* LaunchImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchImage.swift; sourceTree = ""; }; 7C3CB5D5270F4F98000448C6 /* LaunchTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchTime.swift; sourceTree = ""; }; 7C3CB5D9270F4FA4000448C6 /* LaunchDate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchDate.swift; sourceTree = ""; }; - 7C3CB5DD270F4FD1000448C6 /* Countdown.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Countdown.swift; sourceTree = ""; }; 7C3D4CCD2603EFDA00CB0C41 /* LaunchCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchCard.swift; sourceTree = ""; }; 7C44C05B2608FEDB00B8D86A /* launches.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = launches.json; sourceTree = ""; }; 7C4DB82129035144007088A5 /* SettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; @@ -102,7 +95,6 @@ 7C7243C826E8188400233B33 /* LaunchDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchDetail.swift; sourceTree = ""; }; 7C79988226FB7EC700FCAEF2 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = ""; }; 7C834937260931D1008B4895 /* AppSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSettings.swift; sourceTree = ""; }; - 7C8976C127556A8F000815F7 /* CentralTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CentralTimer.swift; sourceTree = ""; }; 7C9BDD87271642EC00A97374 /* PadMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PadMap.swift; sourceTree = ""; }; 7CA49FA9270BB08F00181220 /* LaunchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchView.swift; sourceTree = ""; }; 7CB0A2C72788F99200A542D5 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; @@ -180,7 +172,6 @@ isa = PBXGroup; children = ( 7C3D4CCD2603EFDA00CB0C41 /* LaunchCard.swift */, - 7C3CB5DD270F4FD1000448C6 /* Countdown.swift */, 7C9BDD87271642EC00A97374 /* PadMap.swift */, 7CF87F1925AE45F300BD9D06 /* ContentView.swift */, 7C7243C826E8188400233B33 /* LaunchDetail.swift */, @@ -263,7 +254,6 @@ 7CF87F1825AE45F300BD9D06 /* AstroLaunchesApp.swift */, 7C834937260931D1008B4895 /* AppSettings.swift */, 7C79988226FB7EC700FCAEF2 /* Colors.swift */, - 7C8976C127556A8F000815F7 /* CentralTimer.swift */, 7C09A5B228E7A4B90035CBD4 /* Data */, 7C09A5B328E7A4E60035CBD4 /* Views */, 7CF87F1B25AE45F300BD9D06 /* Assets.xcassets */, @@ -512,8 +502,6 @@ 7C71FEA328F0DC9F00F75C77 /* MissionStatusDate.swift in Sources */, 7CE6154E28D91F550082459A /* LaunchTime.swift in Sources */, 7C92392128E394D700364E5A /* AppSettings.swift in Sources */, - 7CE6155328D91F550082459A /* Countdown.swift in Sources */, - 7CE6155428D91F550082459A /* CentralTimer.swift in Sources */, 7C92392028E394CD00364E5A /* AstroLaunchesApp.swift in Sources */, 7CE6155528D91F550082459A /* Colors.swift in Sources */, 7C71FEA428F0DDD400F75C77 /* LaunchCard.swift in Sources */, @@ -538,8 +526,6 @@ 7C3D4CCE2603EFDA00CB0C41 /* LaunchCard.swift in Sources */, 7C31CEB727F7B74600EA2DCC /* MissionStatusDate.swift in Sources */, 7C31CEB927F7BC3D00EA2DCC /* LaunchImage.swift in Sources */, - 7C3CB5DE270F4FD1000448C6 /* Countdown.swift in Sources */, - 7C8976C227556A8F000815F7 /* CentralTimer.swift in Sources */, 7C79988326FB7EC700FCAEF2 /* Colors.swift in Sources */, 7C9BDD88271642EC00A97374 /* PadMap.swift in Sources */, 7CF87F3025AE45F300BD9D06 /* ContentView.swift in Sources */, @@ -554,10 +540,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 7C47D6182710B53100F5997E /* Countdown.swift in Sources */, 7C5A1B09261BB52B00E452DE /* DateFormatters.swift in Sources */, 7CDB913D290C220600056940 /* PlayPauseHUD.swift in Sources */, - 7C8976C427556A8F000815F7 /* CentralTimer.swift in Sources */, 7C5A1AFB261BB51A00E452DE /* NetworkManager.swift in Sources */, 7C3CB5DC270F4FA4000448C6 /* LaunchDate.swift in Sources */, 7CA49FAA270BB08F00181220 /* LaunchView.swift in Sources */, @@ -988,8 +972,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/RocketCommunicationsInc/AstroSwiftFoundation.git"; requirement = { - kind = upToNextMajorVersion; - minimumVersion = 3.0.0; + branch = "platforms-75"; + kind = branch; }; }; 7C9FCDDA2882057F0032EA88 /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */ = { diff --git a/Astro Launches.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Astro Launches.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 94431b1..5cc119e 100644 --- a/Astro Launches.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Astro Launches.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/RocketCommunicationsInc/AstroSwiftFoundation.git", "state" : { - "revision" : "3a3d154db4b47d80b3f5bee2a63368d9f5f77afa", - "version" : "3.0.0" + "branch" : "platforms-75", + "revision" : "fc6a272b14459bf259315b534f3f61199af34e64" } }, { diff --git a/Shared/CentralTimer.swift b/Shared/CentralTimer.swift deleted file mode 100644 index 43af195..0000000 --- a/Shared/CentralTimer.swift +++ /dev/null @@ -1,12 +0,0 @@ -// -// CentralTimer.swift -// Astro Launches -// -// Created by rocketjeff on 11/29/21. -// - -import Foundation -import SwiftUI - -// create a central timer shared by onscreen clocks and countdown timers so their ticks are synchronized -var centralTimer = Timer.publish(every: 1, on: .main, in: .common).autoconnect() diff --git a/Shared/Views/Countdown.swift b/Shared/Views/Countdown.swift deleted file mode 100644 index 20d3a8c..0000000 --- a/Shared/Views/Countdown.swift +++ /dev/null @@ -1,157 +0,0 @@ -// -// Countdown.swift -// Astro Launches -// -// Created by rocketjeff on 10/7/21. -// - -import SwiftUI - -struct Countdown: View { - var launch:Launch - - @State var timeRemaining: TimeInterval = 0 - - // defaults sizes can be overridden - var digitStyle:Font.TextStyle = .body - var labelStyle:Font.TextStyle = .caption2 - - var body: some View { - HStack { - HStack() - { - let digitFont = Font.system(digitStyle).weight(.semibold).monospacedDigit() - let labelFont = Font.system(labelStyle) - - VStack (alignment: .trailing){ - Text(timeRemaining.days()) - .font(digitFont) - Text("DAYS") - .font(labelFont) - } - - VStack (alignment: .trailing){ - Text(timeRemaining.hours()) - .font(digitFont) - Text("HRS") - .font(labelFont) - } - - VStack (alignment: .trailing){ - Text(timeRemaining.minutes()) - .font(digitFont) -// .transition(.opacity.animation(.easeInOut(duration:0.3))) -// .id("Minutes" + timeRemaining.minutes()) - Text("MIN") - .font(labelFont) - } - - VStack (alignment: .trailing){ - Text(timeRemaining.seconds()) - .font(digitFont) - //.transition(.scale.animation(.easeInOut(duration:0.3))) - //.id("Seconds" + timeRemaining.seconds()) - - Text("SEC") - .font(labelFont) - } - - } - -#if os(iOS) - .foregroundColor(Color(.label)) -#endif -#if os(macOS) - .foregroundColor(Color(.labelColor)) -#endif - - - .onReceive(centralTimer) { _ in - // refresh the time every second - calcTimeRemaining() - } - .onAppear { - // refresh the time when first shown - calcTimeRemaining() - } - .onChange(of: launch) { newLaunch in // on change of coordinates, update our related state variable 'region' - calcTimeRemaining(newlaunch:newLaunch) - print() - } - - } - } - - func calcTimeRemaining(newlaunch:Launch) - { - if let date = newlaunch.windowOpenDate - { - timeRemaining = Date().timeIntervalSince(date) - } - else - { - timeRemaining = 0 - } - } - - func calcTimeRemaining() - { - if let date = launch.windowOpenDate - { - timeRemaining = Date().timeIntervalSince(date) - } - else - { - timeRemaining = 0 - } - } -} - -// extend TimeInterval to output units of time as Strings, always with two digits -extension TimeInterval{ - - func days()->String { - - let time = NSInteger(self) - let days = abs((time / 86400)) - - return String(format: "%0.2d",days) - } - - func hours()->String { - - let time = NSInteger(self) - let hours = abs((time / 3600) % 24) - - return String(format: "%0.2d",hours) - } - - func minutes()->String { - - let time = NSInteger(self) - let minutes = abs((time / 60) % 60) - - return String(format: "%0.2d",minutes) - } - - func seconds()->String { - - let time = NSInteger(self) - let seconds = abs(time % 60) - - return String(format: "%0.2d",seconds) - } -} - - -struct LaunchCountdown_Previews: PreviewProvider { - static var networkManager = NetworkManager() - static var previews: some View { - Countdown(launch:networkManager.upcomingLaunches[0]) - .previewLayout(.sizeThatFits) - Countdown(launch:networkManager.upcomingLaunches[1]) - .preferredColorScheme(.dark) - .previewLayout(.sizeThatFits) - } -} - diff --git a/Shared/Views/LaunchImage.swift b/Shared/Views/LaunchImage.swift index 9d12623..ce6c9f7 100644 --- a/Shared/Views/LaunchImage.swift +++ b/Shared/Views/LaunchImage.swift @@ -7,6 +7,7 @@ import SwiftUI import CachedAsyncImage +import AstroSwiftFoundation struct LaunchCardImage: View { @@ -124,15 +125,18 @@ struct LogoCountdownBlock: View { } Spacer() // only show countown for launches in the future - if let interval = launch.windowOpenDate?.timeIntervalSinceNow + if let windowOpenDate = launch.windowOpenDate { - if interval > 0 - { - Countdown(launch: launch) - .padding(.trailing, 8) - .padding(.top, 2) - .padding(.bottom, 2) - } + IntervalTimer(targetDate: windowOpenDate,options: .all) +#if os(iOS) + .foregroundColor(Color(.label)) +#endif +#if os(macOS) + .foregroundColor(Color(.labelColor)) +#endif + .padding(.trailing, 8) + .padding(.top, 2) + .padding(.bottom, 2) } } .frame(maxWidth: .infinity) diff --git a/tvOS/LaunchView.swift b/tvOS/LaunchView.swift index e38eef3..ca91a61 100644 --- a/tvOS/LaunchView.swift +++ b/tvOS/LaunchView.swift @@ -36,11 +36,14 @@ struct LaunchView: View { VStack() { Spacer() - Countdown(launch:launch, digitStyle: .title, labelStyle: .caption) - .padding() - .background(.ultraThinMaterial) - .cornerRadius(6) - + if let windowOpenDate = launch.windowOpenDate + { + IntervalTimer(targetDate: windowOpenDate,options: .all, digitTextStyle: .title, labelFontStyle: .caption) + .padding() + //.foregroundColor(Color(.label)) + .background(.ultraThinMaterial) + .cornerRadius(6) + } }.padding(60) } // Right side bar From 9ebe6a921da9f4ae46678b97de4f2cef4f0cfc75 Mon Sep 17 00:00:00 2001 From: Jeff Hokit Date: Fri, 27 Jan 2023 15:40:57 -0800 Subject: [PATCH 2/2] build: set AstroSwiftFoundation to main branch --- Astro Launches.xcodeproj/project.pbxproj | 2 +- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Astro Launches.xcodeproj/project.pbxproj b/Astro Launches.xcodeproj/project.pbxproj index d4dd486..85ac24d 100644 --- a/Astro Launches.xcodeproj/project.pbxproj +++ b/Astro Launches.xcodeproj/project.pbxproj @@ -972,7 +972,7 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/RocketCommunicationsInc/AstroSwiftFoundation.git"; requirement = { - branch = "platforms-75"; + branch = main; kind = branch; }; }; diff --git a/Astro Launches.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Astro Launches.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 5cc119e..415f54b 100644 --- a/Astro Launches.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Astro Launches.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/RocketCommunicationsInc/AstroSwiftFoundation.git", "state" : { - "branch" : "platforms-75", - "revision" : "fc6a272b14459bf259315b534f3f61199af34e64" + "branch" : "main", + "revision" : "a303f2915c9fcf930619b055b99503fb6e1eb2b3" } }, {