Skip to content

Commit e8d9399

Browse files
committed
Fix crash and bugs
1 parent e0c2af5 commit e8d9399

3 files changed

Lines changed: 42 additions & 33 deletions

File tree

InfiniLink/Core/Components/WatchFaceView.swift

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ struct DigitalWF: View {
300300
.foregroundColor(.white)
301301
.frame(width: geometry.size.width, height: geometry.size.height / 1.95, alignment: .topTrailing)
302302
}
303-
if Calendar.current.component(.hour, from: Date()) > 12 && !hour24() {
303+
if !hour24() {
304304
CustomTextView(text: "\(Calendar.current.component(.hour, from: Date()) - 12):\(String(format: "%02d", Calendar.current.component(.minute, from: Date())))", font: .custom("JetBrainsMono-ExtraBold", size: geometry.size.width * 0.33), lineSpacing: 0)
305305
.foregroundColor(.white)
306306
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing)
@@ -319,8 +319,8 @@ struct DigitalWF: View {
319319

320320
return formatter.string(from: current).uppercased()
321321
}(), font: .custom("JetBrainsMono-Bold", size: geometry.size.width * 0.085), lineSpacing: 0)
322-
.foregroundColor(Color(.lightGray))
323-
.frame(width: geometry.size.width, height: geometry.size.height / 1.6, alignment: .bottom)
322+
.foregroundColor(Color(.lightGray))
323+
.frame(width: geometry.size.width, height: geometry.size.height / 1.6, alignment: .bottom)
324324
}
325325
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .center)
326326
}
@@ -534,7 +534,7 @@ struct InfineatWF: View {
534534
.foregroundColor(.white)
535535
.frame(width: geometry.size.width, height: geometry.size.height / 1.35, alignment: .topTrailing)
536536
}
537-
if Calendar.current.component(.hour, from: Date()) >= 12 && !hour24() {
537+
if !hour24() {
538538
let currentHour = Calendar.current.component(.hour, from: Date())
539539
let hour24 = currentHour % 12 == 0 ? 12 : currentHour
540540
let hourString = String(format: "%02d", hour24)
@@ -673,22 +673,17 @@ struct TerminalWF: View {
673673
.font(.custom("JetBrainsMono-Bold", size: geometry.size.width * 0.085))
674674
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
675675
.position(x: geometry.size.width / 2.0, y: geometry.size.height / 6.5)
676-
if !hour24() {
677-
Group {
678-
Text("[TIME]").foregroundColor(.white) + Text("\(String(format: "%02d", currentHour % 12 == 0 ? 12 : currentHour % 12)):\(String(format: "%02d", currentMinute)):\(String(format: "%02d", currentSecond)) \(currentHour >= 12 ? "PM" : "AM")").foregroundColor(.green)
679-
}
680-
.font(.custom("JetBrainsMono-Bold", size: geometry.size.width * 0.085))
681-
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
682-
.position(x: geometry.size.width / 2.0, y: geometry.size.height / 4.1)
683-
} else {
684-
Group {
685-
Text("[TIME]").foregroundColor(.white) + Text("\(String(format: "%02d", currentHour)):\(String(format: "%02d", currentMinute)):\(String(format: "%02d", currentSecond))").foregroundColor(.green)
676+
Group {
677+
if !hour24() {
678+
Text("[TIME]").foregroundColor(.white) + Text("\(String(format: "%02d", currentHour % 12 == 0 ? 12 : currentHour % 12)):\(String(format: "%02d", currentMinute)):\(String(format: "%02d", currentSecond)) \(currentHour >= 12 ? "PM" : "AM")")
679+
} else {
680+
Text("[TIME]").foregroundColor(.white) + Text("\(String(format: "%02d", currentHour)):\(String(format: "%02d", currentMinute)):\(String(format: "%02d", currentSecond))")
686681
}
687-
.font(.custom("JetBrainsMono-Bold", size: geometry.size.width * 0.085))
688-
.foregroundColor(.white)
689-
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
690-
.position(x: geometry.size.width / 2.0, y: geometry.size.height / 4.1)
691682
}
683+
.foregroundColor(.green)
684+
.font(.custom("JetBrainsMono-Bold", size: geometry.size.width * 0.085))
685+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
686+
.position(x: geometry.size.width / 2.0, y: geometry.size.height / 4.1)
692687
Group {
693688
Text("[DATE]").foregroundColor(.white) + Text("\(String(format: "%04d-%02d-%02d", Calendar.current.component(.year, from: Date()), Calendar.current.component(.month, from: Date()), Calendar.current.component(.day, from: Date())))").foregroundColor(.blue)
694689
}
@@ -869,3 +864,12 @@ enum InfineatItem {
869864
case midBottom
870865
case midTop
871866
}
867+
868+
#Preview {
869+
GeometryReader { geo in
870+
VStack {
871+
TerminalWF(geometry: .constant(geo), device: Device())
872+
}
873+
.frame(maxWidth: geo.size.width / 2.5)
874+
}
875+
}

InfiniLink/Core/Exercise/Views/AllExercisesView.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ struct AllExercisesView: View {
4747
Text("You don't have any saved exercises. When you complete one, they'll show up here.")
4848
} else {
4949
ForEach(filteredExercises.sorted(by: { $0.startDate ?? Date() > $1.startDate ?? Date() })) { userExercise in
50-
let exercise = exerciseViewModel.exercises.first(where: { $0.id == userExercise.exerciseId })!
51-
52-
NavigationLink {
53-
ExerciseDetailView(userExercise: userExercise)
54-
} label: {
55-
HStack {
56-
Image(systemName: exercise.icon)
57-
.font(.system(size: 24).weight(.medium))
58-
VStack(alignment: .leading, spacing: 4) {
59-
Text(exercise.name)
60-
.font(.body.weight(.medium))
61-
Text(userExercise.startDate!.formatted())
62-
.foregroundStyle(Color.gray)
50+
if let exercise = exerciseViewModel.exercises.first(where: { $0.id == userExercise.exerciseId }) {
51+
NavigationLink {
52+
ExerciseDetailView(userExercise: userExercise)
53+
} label: {
54+
HStack {
55+
Image(systemName: exercise.icon)
56+
.font(.system(size: 24).weight(.medium))
57+
VStack(alignment: .leading, spacing: 4) {
58+
Text(exercise.name)
59+
.font(.body.weight(.medium))
60+
Text(userExercise.startDate?.formatted() ?? "Unknown date")
61+
.foregroundStyle(Color.gray)
62+
}
6363
}
6464
}
6565
}

InfiniLink/Core/Settings/Weather/WeatherSettingsView.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct WeatherSettingsView: View {
1111
@ObservedObject var locationManager = LocationManager.shared
1212

1313
@AppStorage("useCurrentLocation") var useCurrentLocation = true
14+
@AppStorage("setLocation") var setLocation = "Cupertino"
1415
@AppStorage("displayLocation") var displayLocation = "Cupertino"
1516

1617
var body: some View {
@@ -40,8 +41,12 @@ struct WeatherSettingsView: View {
4041
}
4142
}
4243
.navigationTitle("Settings")
43-
.onChange(of: useCurrentLocation) { _ in
44-
locationManager.getLocation()
44+
.onChange(of: useCurrentLocation) { useCurrentLocation in
45+
if useCurrentLocation {
46+
locationManager.getLocation()
47+
} else {
48+
locationManager.setLocation(setLocation)
49+
}
4550
}
4651
.onAppear {
4752
locationManager.requestLocation()

0 commit comments

Comments
 (0)