From f43b0c490ab7092069ed64e205fc6d5548514d30 Mon Sep 17 00:00:00 2001 From: mulot Date: Sat, 2 Mar 2024 21:42:55 +0100 Subject: [PATCH] tvOS App: Add remote movements : - up to increase line width - down to toggle circle back - left & right to decrease & increase timezone - long button press to reset timezone - short button press to toggle centi beats watchOS App: Add alarm tab --- BeatTime.xcodeproj/project.pbxproj | 2 + TvOS/BeatTimeTvOSApp.swift | 42 +++++++++++++--- .../AppIcon.appiconset/Contents.json | 14 ++++++ WatchOS WatchKit Extension/BeatTimeApp.swift | 49 +++++++++++++++++++ iOS/BeatTimeiOSApp.swift | 2 +- 5 files changed, 100 insertions(+), 9 deletions(-) diff --git a/BeatTime.xcodeproj/project.pbxproj b/BeatTime.xcodeproj/project.pbxproj index e6da444..0878238 100644 --- a/BeatTime.xcodeproj/project.pbxproj +++ b/BeatTime.xcodeproj/project.pbxproj @@ -36,6 +36,7 @@ 945F06C926543EDE00391A7D /* BeatTImeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94BEB1BE2646D9C500A5D811 /* BeatTImeView.swift */; }; 945F06CA26543EE200391A7D /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94BEB20E2646E92E00A5D811 /* Colors.swift */; }; 945F06CB26543EE500391A7D /* UIViewDraw.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94BEB1CB2646DBEB00A5D811 /* UIViewDraw.swift */; }; + 9475DB862B910AF100402BAA /* LocalNotificationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94F62D872B717A0200C4C2C4 /* LocalNotificationManager.swift */; }; 9476F3282639D65A006FBF66 /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9476F3272639D65A006FBF66 /* WidgetKit.framework */; }; 9476F32A2639D65A006FBF66 /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9476F3292639D65A006FBF66 /* SwiftUI.framework */; }; 9476F32F2639D662006FBF66 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9476F32E2639D662006FBF66 /* Assets.xcassets */; }; @@ -866,6 +867,7 @@ files = ( 947C5643264814F1007E6B4A /* NotificationController.swift in Sources */, 947C566226481A68007E6B4A /* Colors.swift in Sources */, + 9475DB862B910AF100402BAA /* LocalNotificationManager.swift in Sources */, 94196346292F61DA009BC68A /* ComplicationController.swift in Sources */, 94A89355264D863700C86B3E /* ExtensionDelegate.swift in Sources */, 947C566326481B22007E6B4A /* BeatTImeView.swift in Sources */, diff --git a/TvOS/BeatTimeTvOSApp.swift b/TvOS/BeatTimeTvOSApp.swift index 426752d..c169a9a 100644 --- a/TvOS/BeatTimeTvOSApp.swift +++ b/TvOS/BeatTimeTvOSApp.swift @@ -50,15 +50,14 @@ struct ContentView: View { @Binding var hoursOffsetGMT: Int @State var bgCircle: Bool = true + @State var centiBeats: Bool = false + @State var lineWidth: CGFloat = 40 var longPress: some Gesture { LongPressGesture(minimumDuration: 1.0) .onEnded { _ in - hoursOffsetGMT += 1 - if hoursOffsetGMT == 13 { - hoursOffsetGMT = -12 - } - print("longpress > GMT: \(hoursOffsetGMT)") + hoursOffsetGMT = BeatTime.hoursOffsetWithGMT() + //print("longpress > GMT: \(hoursOffsetGMT)") } } @@ -77,16 +76,43 @@ struct ContentView: View { .gradientForeground(colors: [.startGradient, .midGradient, .mid2Gradient, .endGradient]) */ if #available(tvOS 16.0, *) { - BeatTimeView(lineWidth: 40, fullCircleBg: bgCircle, hoursOffsetGMT: hoursOffsetGMT) + BeatTimeView(lineWidth: lineWidth, centiBeats: centiBeats, fullCircleBg: bgCircle, hoursOffsetGMT: hoursOffsetGMT) .focusable(true) .highPriorityGesture(longPress) .onLongPressGesture(minimumDuration: 0.01, pressing: { _ in }) { print("short press") - bgCircle = !bgCircle + centiBeats = !centiBeats } + .onMoveCommand(perform: { direction in + switch direction { + case .down: + print("down press") + bgCircle = !bgCircle + case .up: + print("up press") + lineWidth += 10 + if lineWidth == 110 { + lineWidth = 40 + } + case .left: + print("left press") + hoursOffsetGMT -= 1 + if hoursOffsetGMT == -13 { + hoursOffsetGMT = 12 + } + case .right: + print("right press") + hoursOffsetGMT += 1 + if hoursOffsetGMT == 13 { + hoursOffsetGMT = -12 + } + default: + print("move press") + } + }) } else { - BeatTimeView(lineWidth: 40) + BeatTimeView(lineWidth: lineWidth) } } } diff --git a/WatchOS WatchKit App/Assets.xcassets/AppIcon.appiconset/Contents.json b/WatchOS WatchKit App/Assets.xcassets/AppIcon.appiconset/Contents.json index 4fe3b34..cea8e11 100644 --- a/WatchOS WatchKit App/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/WatchOS WatchKit App/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -75,6 +75,13 @@ "size" : "51x51", "subtype" : "45mm" }, + { + "idiom" : "watch", + "role" : "appLauncher", + "scale" : "2x", + "size" : "54x54", + "subtype" : "49mm" + }, { "filename" : "BeatTime App Icon-WatchOS-172.png", "idiom" : "watch", @@ -106,6 +113,13 @@ "size" : "117x117", "subtype" : "45mm" }, + { + "idiom" : "watch", + "role" : "quickLook", + "scale" : "2x", + "size" : "129x129", + "subtype" : "49mm" + }, { "filename" : "BeatTime App Icon-WatchOS-1024.png", "idiom" : "watch-marketing", diff --git a/WatchOS WatchKit Extension/BeatTimeApp.swift b/WatchOS WatchKit Extension/BeatTimeApp.swift index 5230c69..7a5971e 100644 --- a/WatchOS WatchKit Extension/BeatTimeApp.swift +++ b/WatchOS WatchKit Extension/BeatTimeApp.swift @@ -8,6 +8,9 @@ import SwiftUI import os +//let notificationCenter = UNUserNotificationCenter.current() +let manager = LocalNotificationManager() + @main struct BeatTimeApp: App { @WKApplicationDelegateAdaptor private var appDelegate: ExtensionDelegate @@ -20,6 +23,7 @@ struct BeatTimeApp: App { TabView { ContentView() ConvertView() + AlarmView() }.tabViewStyle(PageTabViewStyle()) }.onChange(of: scenePhase) { (phase) in switch phase { @@ -112,6 +116,7 @@ struct ConvertView: View { } }.font(.title.bold()) } + }.onChange(of: selection) { time in updateClock(time) } @@ -155,6 +160,40 @@ struct ConvertView: View { } } +struct AlarmView: View { + @State var selection: String = BeatTime.beats() + + func setNotification(msg: String, date: Date) -> Void { + if (date.timeIntervalSinceNow < 0) { + manager.addNotification(title: msg, time: 86400 + date.timeIntervalSinceNow, date: date.addingTimeInterval(86400)) + } + else { + manager.addNotification(title: msg, time: date.timeIntervalSinceNow, date: date) + } + } + + var body: some View { + VStack { + HStack { + Picker("", selection: $selection) { + ForEach(0..<1000, id:\.self) { index in + Text(verbatim: "@\(index)") + .tag("\(index)") + } + } + .font(.title.bold()) + } + HStack { + Text(DateFormatter.localizedString(from: BeatTime.date(beats: selection), dateStyle: .short, timeStyle: .short)) + .font(.title3.bold()) + } + Button("Set notif ", action: { + self.setNotification(msg: "@\(selection) .beats", date: BeatTime.date(beats: selection)) + }) + } + } +} + struct ContentView: View { let fgColors: [Color] = [.orange, .gray, .red, .yellow, .green, .blue, .purple, .pink] @SceneStorage("ContentView.color") private var index:Double = 0.0 @@ -213,6 +252,7 @@ struct Content_Preview: PreviewProvider { TabView { ContentView() ConvertView() + AlarmView() }.tabViewStyle(PageTabViewStyle()) } } @@ -225,3 +265,12 @@ struct Convert_Preview: PreviewProvider { }.tabViewStyle(PageTabViewStyle()) } } + +struct Alarm_Preview: PreviewProvider { + static var previews: some View { + TabView { + AlarmView() + ContentView() + }.tabViewStyle(PageTabViewStyle()) + } +} diff --git a/iOS/BeatTimeiOSApp.swift b/iOS/BeatTimeiOSApp.swift index ca4b225..55ff932 100644 --- a/iOS/BeatTimeiOSApp.swift +++ b/iOS/BeatTimeiOSApp.swift @@ -7,7 +7,7 @@ import SwiftUI -let notificationCenter = UNUserNotificationCenter.current() +//let notificationCenter = UNUserNotificationCenter.current() let manager = LocalNotificationManager() @main