@@ -10,6 +10,10 @@ import SwiftUI
1010struct WeatherDetailView : View {
1111 @ObservedObject var bleManagerVal = BLEManagerVal . shared
1212
13+ var celsius : Bool {
14+ ( UnitTemperature . current == . celsius && deviceData. chosenWeatherMode == " System " ) || deviceData. chosenWeatherMode == " Metric "
15+ }
16+
1317 func getIcon( icon: Int ) -> String {
1418 switch icon {
1519 case 0 :
@@ -30,9 +34,12 @@ struct WeatherDetailView: View {
3034 return " slash.circle "
3135 }
3236 }
33-
34- var celsius : Bool {
35- ( UnitTemperature . current == . celsius && deviceData. chosenWeatherMode == " System " ) || deviceData. chosenWeatherMode == " Metric "
37+ func temp( _ temp: Double ) -> String {
38+ if self . celsius {
39+ return String ( Int ( round ( temp) ) ) + " ° " + " C "
40+ } else {
41+ return String ( Int ( round ( temp * 1.8 + 32 ) ) ) + " ° " + " F "
42+ }
3643 }
3744
3845 let deviceData : DeviceData = DeviceData ( )
@@ -45,7 +52,7 @@ struct WeatherDetailView: View {
4552 }
4653
4754 var body : some View {
48- VStack {
55+ VStack ( spacing : 0 ) {
4956 HStack {
5057 Text ( NSLocalizedString ( " weather " , comment: " " ) )
5158 . font ( . title. bold ( ) )
@@ -61,72 +68,56 @@ struct WeatherDetailView: View {
6168 ProgressView ( NSLocalizedString ( " loading_weather " , comment: " " ) )
6269 Spacer ( )
6370 } else {
64- VStack ( spacing: 8 ) {
65- Image ( systemName: getIcon ( icon: bleManagerVal. weatherInformation. icon) )
66- . font ( . system( size: 45 ) . weight ( . medium) )
67- HStack {
68- Group {
69- if celsius {
70- Text ( String ( Int ( round ( bleManagerVal. weatherInformation. minTemperature) ) ) + " ° " + " C " )
71- } else {
72- Text ( String ( Int ( round ( bleManagerVal. weatherInformation. minTemperature * 1.8 + 32 ) ) ) + " ° " + " F " )
73- }
74- }
75- . foregroundColor ( . gray)
76- Group {
77- if celsius {
78- Text ( String ( Int ( round ( bleManagerVal. weatherInformation. temperature) ) ) + " ° " + " C " )
79- } else {
80- Text ( String ( Int ( round ( bleManagerVal. weatherInformation. temperature * 1.8 + 32 ) ) ) + " ° " + " F " )
81- }
71+ ScrollView {
72+ VStack ( spacing: 8 ) {
73+ Image ( systemName: getIcon ( icon: bleManagerVal. weatherInformation. icon) )
74+ . font ( . system( size: 45 ) . weight ( . medium) )
75+ HStack {
76+ Text ( temp ( bleManagerVal. weatherInformation. minTemperature) )
77+ . foregroundColor ( . gray)
78+ Text ( temp ( bleManagerVal. weatherInformation. temperature) )
79+ . font ( . system( size: 35 ) . weight ( . semibold) )
80+ Text ( temp ( bleManagerVal. weatherInformation. maxTemperature) )
81+ . foregroundColor ( . gray)
8282 }
83- . font ( . system( size: 35 ) . weight ( . semibold) )
84- Group {
85- if celsius {
86- Text ( String ( Int ( round ( bleManagerVal. weatherInformation. maxTemperature) ) ) + " ° " + " C " )
87- } else {
88- Text ( String ( Int ( round ( bleManagerVal. weatherInformation. maxTemperature * 1.8 + 32 ) ) ) + " ° " + " F " )
89- }
90- }
91- . foregroundColor ( . gray)
83+ Text ( bleManagerVal. weatherInformation. shortDescription)
84+ . foregroundColor ( . gray)
85+ . font ( . body. weight ( . semibold) )
9286 }
93- Text ( bleManagerVal. weatherInformation. shortDescription)
94- . foregroundColor ( . gray)
95- . font ( . body. weight ( . semibold) )
96- }
97- . padding ( )
98- Divider ( )
99- VStack {
100- ScrollView ( . horizontal, showsIndicators: false ) {
101- HStack ( spacing: 10 ) {
102- ForEach ( bleManagerVal. weatherForecastDays, id: \. name) { day in
103- VStack ( spacing: 6 ) {
104- Text ( day. name)
105- . foregroundColor ( . gray)
106- . font ( . system( size: 14 ) . weight ( . medium) )
107- Image ( systemName: getIcon ( icon: Int ( day. icon) ) )
108- . imageScale ( . large)
109- . font ( . system( size: 18 ) . weight ( . medium) )
110- VStack {
111- if celsius {
112- Text ( String ( Int ( round ( day. maxTemperature) ) ) + " ° " )
113- Text ( String ( Int ( round ( day. minTemperature) ) ) + " ° " )
114- } else {
115- Text ( String ( Int ( round ( day. maxTemperature * 1.8 + 32 ) ) ) + " ° " )
116- Text ( String ( Int ( round ( day. minTemperature * 1.8 + 32 ) ) ) + " ° " )
117- }
118- }
87+ . padding ( )
88+ VStack ( spacing: 10 ) {
89+ ForEach ( bleManagerVal. weatherForecastDays, id: \. name) { day in
90+ HStack ( spacing: 6 ) {
91+ Text ( day. name)
92+ . font ( . body. weight ( . medium) )
93+ Image ( systemName: getIcon ( icon: Int ( day. icon) ) )
94+ . imageScale ( . large)
95+ . font ( . body. weight ( . medium) )
96+ Spacer ( )
97+ HStack ( spacing: 6 ) {
98+ Text ( temp ( day. maxTemperature) )
99+ . foregroundColor ( . lightGray)
100+ Rectangle ( )
101+ . frame ( height: 3 )
102+ . frame ( width: {
103+ let temperatureRange = day. maxTemperature - day. minTemperature
104+ let relativeWidth = CGFloat ( temperatureRange) / 40.0 * 60
105+ return relativeWidth
106+ } ( ) )
107+ . cornerRadius ( 30 )
108+ . background ( Material . thin)
109+ Text ( temp ( day. minTemperature) )
110+ . foregroundColor ( . lightGray)
119111 }
120- . padding ( 12 )
121- . frame ( width: 95 )
122- . background ( Color . gray. opacity ( 0.3 ) )
123- . cornerRadius ( 12 )
124112 }
113+ . frame ( maxWidth: . infinity)
114+ . padding ( )
115+ . background ( Color . gray. opacity ( 0.3 ) )
116+ . cornerRadius ( 15 )
125117 }
126- . padding ( )
127118 }
119+ . padding ( )
128120 }
129- Spacer ( )
130121 }
131122 }
132123 }
@@ -142,5 +133,7 @@ struct WeatherDetailView: View {
142133 BLEManagerVal . shared. weatherInformation. maxTemperature = 3
143134 BLEManagerVal . shared. weatherInformation. maxTemperature = 5
144135 BLEManagerVal . shared. weatherForecastDays. append ( WeatherForecastDay ( maxTemperature: 3 , minTemperature: 2 , icon: 2 , name: " Sat " ) )
136+ BLEManagerVal . shared. weatherForecastDays. append ( WeatherForecastDay ( maxTemperature: 1.6 , minTemperature: 1.3 , icon: 6 , name: " Sun " ) )
137+ BLEManagerVal . shared. weatherForecastDays. append ( WeatherForecastDay ( maxTemperature: 2.6 , minTemperature: 1.9 , icon: 3 , name: " Mon " ) )
145138 }
146139}
0 commit comments