Skip to content

Commit

Permalink
tvOS App:
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mulot committed Mar 2, 2024
1 parent 09a19dc commit f43b0c4
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 9 deletions.
2 changes: 2 additions & 0 deletions BeatTime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 */,
Expand Down
42 changes: 34 additions & 8 deletions TvOS/BeatTimeTvOSApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
}

Expand All @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
49 changes: 49 additions & 0 deletions WatchOS WatchKit Extension/BeatTimeApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import SwiftUI
import os

//let notificationCenter = UNUserNotificationCenter.current()
let manager = LocalNotificationManager()

@main
struct BeatTimeApp: App {
@WKApplicationDelegateAdaptor private var appDelegate: ExtensionDelegate
Expand All @@ -20,6 +23,7 @@ struct BeatTimeApp: App {
TabView {
ContentView()
ConvertView()
AlarmView()
}.tabViewStyle(PageTabViewStyle())
}.onChange(of: scenePhase) { (phase) in
switch phase {
Expand Down Expand Up @@ -112,6 +116,7 @@ struct ConvertView: View {
}
}.font(.title.bold())
}

}.onChange(of: selection) { time in
updateClock(time)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -213,6 +252,7 @@ struct Content_Preview: PreviewProvider {
TabView {
ContentView()
ConvertView()
AlarmView()
}.tabViewStyle(PageTabViewStyle())
}
}
Expand All @@ -225,3 +265,12 @@ struct Convert_Preview: PreviewProvider {
}.tabViewStyle(PageTabViewStyle())
}
}

struct Alarm_Preview: PreviewProvider {
static var previews: some View {
TabView {
AlarmView()
ContentView()
}.tabViewStyle(PageTabViewStyle())
}
}
2 changes: 1 addition & 1 deletion iOS/BeatTimeiOSApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import SwiftUI

let notificationCenter = UNUserNotificationCenter.current()
//let notificationCenter = UNUserNotificationCenter.current()
let manager = LocalNotificationManager()

@main
Expand Down

0 comments on commit f43b0c4

Please sign in to comment.