SnoozerView.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // SnoozerView.swift
  3. // LoopFollow
  4. //
  5. // Created by Jonas Björkert on 2025-04-26.
  6. // Copyright © 2025 Jon Fawcett. All rights reserved.
  7. //
  8. import SwiftUI
  9. struct SnoozerView: View {
  10. @ObservedObject var minAgoText = Observable.shared.minAgoText
  11. @ObservedObject var bgText = Observable.shared.bgText
  12. @ObservedObject var bgTextColor = Observable.shared.bgTextColor
  13. @ObservedObject var directionText = Observable.shared.directionText
  14. @ObservedObject var deltaText = Observable.shared.deltaText
  15. @ObservedObject var bgStale = Observable.shared.bgStale
  16. @Binding var snoozeMinutes: Int
  17. var onSnooze: () -> Void
  18. var body: some View {
  19. GeometryReader { geo in
  20. ZStack {
  21. Color.black
  22. .edgesIgnoringSafeArea(.all)
  23. Group {
  24. if geo.size.width > geo.size.height {
  25. // Landscape: two columns
  26. HStack(spacing: 0) {
  27. leftColumn
  28. rightColumn
  29. }
  30. } else {
  31. // Portrait: single column
  32. VStack(spacing: 0) {
  33. leftColumn
  34. rightColumn
  35. }
  36. }
  37. }
  38. .frame(width: geo.size.width, height: geo.size.height)
  39. }
  40. }
  41. }
  42. // MARK: - Left Column (BG / Direction / Delta / Age)
  43. private var leftColumn: some View {
  44. VStack(spacing: 0) {
  45. Text(bgText.value)
  46. .font(.system(size: 220, weight: .black))
  47. .minimumScaleFactor(0.5)
  48. .foregroundColor(bgTextColor.value)
  49. .strikethrough(
  50. bgStale.value,
  51. pattern: .solid,
  52. color: bgStale.value ? .red : .clear
  53. )
  54. .frame(maxWidth: .infinity, maxHeight: 167)
  55. Text(directionText.value)
  56. .font(.system(size: 110, weight: .black))
  57. .minimumScaleFactor(0.5)
  58. .foregroundColor(.white)
  59. .frame(maxWidth: .infinity, maxHeight: 96)
  60. Text(deltaText.value)
  61. .font(.system(size: 70))
  62. .minimumScaleFactor(0.5)
  63. .foregroundColor(.white.opacity(0.8))
  64. .frame(maxWidth: .infinity, maxHeight: 78)
  65. Text(minAgoText.value)
  66. .font(.system(size: 70))
  67. .minimumScaleFactor(0.5)
  68. .foregroundColor(.white.opacity(0.6))
  69. .frame(maxWidth: .infinity, maxHeight: 48)
  70. }
  71. .padding(.top, 16)
  72. .padding(.horizontal, 16)
  73. }
  74. // MARK: - Right Column (Clock/Alert + Snooze Controls)
  75. private var rightColumn: some View {
  76. VStack(spacing: 0) {
  77. Spacer()
  78. // Clock and (optional) alert
  79. VStack(spacing: 8) {
  80. Text("19:59" /* replace with time.value */)
  81. .font(.system(size: 70))
  82. .minimumScaleFactor(0.5)
  83. .foregroundColor(.white)
  84. .frame(height: 78)
  85. /*
  86. if let alarm = alarmText.value, !alarm.isEmpty {
  87. Text(alarm)
  88. .font(.system(size: 40, weight: .semibold))
  89. .foregroundColor(.red)
  90. .minimumScaleFactor(0.5)
  91. .lineLimit(1)
  92. .frame(height: 48)
  93. }
  94. */
  95. }
  96. Spacer()
  97. // Snooze controls
  98. HStack(spacing: 12) {
  99. Text("Snooze for")
  100. .font(.system(size: 20))
  101. .foregroundColor(.white)
  102. Text("\(snoozeMinutes) min")
  103. .font(.system(size: 20, weight: .semibold))
  104. .foregroundColor(.white)
  105. Spacer()
  106. Stepper("", value: $snoozeMinutes, in: 1...60)
  107. .labelsHidden()
  108. }
  109. .padding(.horizontal, 32)
  110. .frame(height: 44)
  111. Button(action: onSnooze) {
  112. Text("Snooze")
  113. .font(.system(size: 24, weight: .bold))
  114. .frame(maxWidth: .infinity, minHeight: 56)
  115. }
  116. .background(Color(white: 0.15))
  117. .foregroundColor(.white)
  118. .cornerRadius(8)
  119. .padding(.horizontal, 32)
  120. .padding(.bottom, 32)
  121. }
  122. .padding(.top, 16)
  123. }
  124. }