115 lines
3.5 KiB
Swift
115 lines
3.5 KiB
Swift
//
|
|
// FavoriteHeaderView.swift
|
|
// app
|
|
//
|
|
// Created by Tobias Stottrop on 27.01.20.
|
|
// Copyright © 2020 Marcus Handte. All rights reserved.
|
|
//
|
|
import SwiftUI
|
|
import MowestaApi
|
|
|
|
struct FavoriteHeaderView: View {
|
|
var location: CDLocation
|
|
@UIState var condition: WeatherCondition = moc_condition_empty
|
|
|
|
func getWeatherCondition(condition: WeatherCondition?, error: Error?) {
|
|
if (condition != nil) {
|
|
//NSLog("condition: \(condition)")
|
|
self.condition = condition!
|
|
}
|
|
}
|
|
|
|
func updateCondition() {
|
|
//NSLog("update condition: \(location.id)")
|
|
WeatherAPI.getCityCondition(_id: location.id, completion: getWeatherCondition)
|
|
}
|
|
|
|
var body: some View {
|
|
VStack (alignment: .leading) {
|
|
HStack {
|
|
Image(systemName: condition.getWeatherTypeImageName())
|
|
Spacer()
|
|
Text("LVActualWeather")
|
|
.font(.title)
|
|
.bold()
|
|
}
|
|
Divider()
|
|
Spacer()
|
|
HStack {
|
|
Text("LVTemperature")
|
|
.font(.subheadline)
|
|
.bold()
|
|
Spacer()
|
|
Text("\(MeasurementDataConverter.toTemperature(condition.temperature))")
|
|
.font(.caption)
|
|
.bold()
|
|
}
|
|
HStack {
|
|
Text("LVWindStrength")
|
|
.font(.subheadline)
|
|
.bold()
|
|
Spacer()
|
|
Image(systemName: condition.getWindDirectionImageName())
|
|
Text("\(condition.windSpeed.round(to: 0).removeZerosFromEnd()) m/s")
|
|
.font(.caption)
|
|
.bold()
|
|
}
|
|
HStack {
|
|
Text("LVHumidity")
|
|
.font(.subheadline)
|
|
.bold()
|
|
Spacer()
|
|
Text("\(condition.humidity.round(to: 0).removeZerosFromEnd()) %")
|
|
.font(.caption)
|
|
.bold()
|
|
}
|
|
HStack {
|
|
Text("LVSnowDepth")
|
|
.font(.subheadline)
|
|
.bold()
|
|
Spacer()
|
|
Text("\(condition.snowDepth.round(to: 2).removeZerosFromEnd()) m")
|
|
.font(.caption)
|
|
.bold()
|
|
}
|
|
HStack {
|
|
Text("LVCloudy")
|
|
.font(.subheadline)
|
|
.bold()
|
|
Spacer()
|
|
Text("\(condition.cloudCoverage.round(to: 2).removeZerosFromEnd()) %")
|
|
.font(.caption)
|
|
.bold()
|
|
}
|
|
HStack {
|
|
Text("LVRainfall")
|
|
.font(.subheadline)
|
|
.bold()
|
|
Spacer()
|
|
Text("\(condition.precipitation.round(to: 2).removeZerosFromEnd()) kg/hm²")
|
|
.font(.caption)
|
|
.bold()
|
|
}
|
|
HStack {
|
|
Text("LVPressure")
|
|
.font(.subheadline)
|
|
.bold()
|
|
Spacer()
|
|
Text("\(condition.pressure.round(to: 2).removeZerosFromEnd()) hPa")
|
|
.font(.caption)
|
|
.bold()
|
|
}
|
|
}
|
|
.padding()
|
|
.onAppear(perform: self.updateCondition)
|
|
}
|
|
|
|
}
|
|
|
|
|
|
struct FavoriteHeaderView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
FavoriteHeaderView(location: DataManager.locationMock, condition: moc_condition_wolfsburg)
|
|
}
|
|
}
|