Skip to content

Commit 3e378da

Browse files
committed
work on apple watch app
1 parent 6be80b5 commit 3e378da

25 files changed

Lines changed: 1081 additions & 139 deletions

fix_watch_project.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'xcodeproj'
2+
project_path = 'ios/Runner.xcodeproj'
3+
project = Xcodeproj::Project.open(project_path)
4+
5+
runner_target = project.targets.find { |t| t.name == 'Runner' }
6+
watch_target = project.targets.find { |t| t.name == 'NeverSkipWatch Watch App' }
7+
8+
if runner_target && watch_target
9+
unless runner_target.dependencies.any? { |dep| dep.target == watch_target }
10+
runner_target.add_dependency(watch_target)
11+
puts "Added Target Dependency"
12+
end
13+
14+
embed_phase = runner_target.build_phases.find { |bp| bp.respond_to?(:name) && bp.name == 'Embed Watch Content' }
15+
if embed_phase
16+
unless embed_phase.files_references.include?(watch_target.product_reference)
17+
build_file = embed_phase.add_file_reference(watch_target.product_reference)
18+
build_file.settings = { 'ATTRIBUTES' => ['RemoveHeadersOnCopy'] }
19+
puts "Added to Embed Watch Content"
20+
end
21+
end
22+
23+
project.save
24+
puts "Project saved."
25+
else
26+
puts "Targets not found."
27+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"platform" : "watchos",
6+
"size" : "1024x1024"
7+
}
8+
],
9+
"info" : {
10+
"author" : "xcode",
11+
"version" : 1
12+
}
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import SwiftUI
2+
3+
struct ContentView: View {
4+
@StateObject var viewModel = WatchViewModel()
5+
6+
var body: some View {
7+
NavigationStack {
8+
List(viewModel.activities) { activity in
9+
NavigationLink(destination: ActivityDetailView(viewModel: viewModel, activityId: activity.id)) {
10+
VStack(alignment: .leading) {
11+
Text(activity.name)
12+
.font(.headline)
13+
Text("\(activity.completedSets)/\(activity.targetSets) Sets")
14+
.font(.subheadline)
15+
.foregroundColor(activity.completedSets >= activity.targetSets ? .green : .secondary)
16+
}
17+
}
18+
}
19+
.navigationTitle("Today")
20+
.overlay {
21+
if viewModel.activities.isEmpty {
22+
Text("Open iPhone app to sync today's workout.")
23+
.multilineTextAlignment(.center)
24+
.padding()
25+
}
26+
}
27+
}
28+
}
29+
}
30+
31+
struct ActivityDetailView: View {
32+
@ObservedObject var viewModel: WatchViewModel
33+
let activityId: String
34+
35+
@State private var reps: Int = 0
36+
@State private var weight: Double = 0.0
37+
@State private var initialized = false
38+
39+
var activity: WatchActivity? {
40+
viewModel.activities.first(where: { $0.id == activityId })
41+
}
42+
43+
var body: some View {
44+
ScrollView {
45+
if let act = activity {
46+
VStack(spacing: 16) {
47+
Text(act.name)
48+
.font(.headline)
49+
.multilineTextAlignment(.center)
50+
51+
HStack {
52+
Text("Reps:")
53+
Spacer()
54+
Stepper("\(reps)", value: $reps, in: 1...100)
55+
}
56+
57+
if act.type == "Weighted" {
58+
HStack {
59+
Text("Weight:")
60+
Spacer()
61+
Stepper(String(format: "%.1f", weight), value: $weight, in: 0...500, step: 2.5)
62+
}
63+
}
64+
65+
Button(action: {
66+
viewModel.logSet(for: act.id, reps: reps, weight: weight)
67+
}) {
68+
Text("Log Set (\(act.completedSets))")
69+
.fontWeight(.bold)
70+
}
71+
.tint(.blue)
72+
}
73+
.padding()
74+
.onAppear {
75+
if !initialized {
76+
reps = act.previousReps
77+
weight = act.previousWeight
78+
initialized = true
79+
}
80+
}
81+
} else {
82+
Text("Activity not found")
83+
}
84+
}
85+
}
86+
}
87+
88+
#Preview {
89+
ContentView()
90+
}
Lines changed: 30 additions & 0 deletions
Loading
Lines changed: 25 additions & 0 deletions
Loading
Lines changed: 31 additions & 0 deletions
Loading
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"fill" : {
3+
"automatic-gradient" : "display-p3:0.31376,0.49094,0.81492,1.00000"
4+
},
5+
"groups" : [
6+
{
7+
"layers" : [
8+
9+
],
10+
"shadow" : {
11+
"kind" : "neutral",
12+
"opacity" : 0.5
13+
},
14+
"translucency" : {
15+
"enabled" : true,
16+
"value" : 0.5
17+
}
18+
},
19+
{
20+
"blend-mode" : "normal",
21+
"layers" : [
22+
{
23+
"blend-mode" : "normal",
24+
"fill" : "none",
25+
"glass" : true,
26+
"hidden" : false,
27+
"image-name" : "plate3.svg",
28+
"name" : "plate3",
29+
"position" : {
30+
"scale" : 5.21,
31+
"translation-in-points" : [
32+
0,
33+
-125
34+
]
35+
}
36+
},
37+
{
38+
"blend-mode" : "normal",
39+
"glass" : true,
40+
"hidden" : false,
41+
"image-name" : "plate2 2.svg",
42+
"name" : "plate2 2",
43+
"opacity-specializations" : [
44+
{
45+
"appearance" : "dark",
46+
"value" : 1
47+
}
48+
],
49+
"position" : {
50+
"scale" : 5.21,
51+
"translation-in-points" : [
52+
0,
53+
-46.1875
54+
]
55+
}
56+
},
57+
{
58+
"blend-mode" : "normal",
59+
"glass" : true,
60+
"hidden" : false,
61+
"image-name" : "plate1 2.svg",
62+
"name" : "plate1 2",
63+
"position" : {
64+
"scale" : 5.21,
65+
"translation-in-points" : [
66+
0,
67+
47
68+
]
69+
}
70+
}
71+
],
72+
"shadow" : {
73+
"kind" : "neutral",
74+
"opacity" : 0.5
75+
},
76+
"translucency" : {
77+
"enabled" : true,
78+
"value" : 0.5
79+
}
80+
},
81+
{
82+
"layers" : [
83+
84+
],
85+
"shadow" : {
86+
"kind" : "neutral",
87+
"opacity" : 0.5
88+
},
89+
"translucency" : {
90+
"enabled" : true,
91+
"value" : 0.5
92+
}
93+
}
94+
],
95+
"supported-platforms" : {
96+
"circles" : [
97+
"watchOS"
98+
],
99+
"squares" : "shared"
100+
}
101+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import SwiftUI
2+
3+
@main
4+
struct NeverSkipWatch_Watch_AppApp: App {
5+
var body: some Scene {
6+
WindowGroup {
7+
ContentView()
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)