Commit e38fdf8f by Demid Merzlyakov

IOS-101: WIP: top part of the medium temperature widget.

parent 25fcd8d2
...@@ -272,3 +272,6 @@ ...@@ -272,3 +272,6 @@
// Ads // Ads
"ads.native.sponsored" = "Sponsored"; "ads.native.sponsored" = "Sponsored";
"ads.placeholder" = "Advertisement"; "ads.placeholder" = "Advertisement";
// Widget
"widget.lastUpdatedTemplate" = "Last updated #LAST_UPDATED ago.";
{
"colors" : [
{
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0.827",
"green" : "0.815",
"red" : "0.812"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0.839",
"green" : "0.839",
"red" : "0.839"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
...@@ -11,12 +11,13 @@ import OneWeatherCore ...@@ -11,12 +11,13 @@ import OneWeatherCore
struct WeatherEntry: TimelineEntry { struct WeatherEntry: TimelineEntry {
static let defaultLocation = Location(deviceLocation: true, static let defaultLocation = Location(deviceLocation: true,
lastWeatherUpdateDate: Date(timeIntervalSinceNow: -4 * 3600),
coordinates: .init(latitude: 37.3230, longitude: -122.0322), coordinates: .init(latitude: 37.3230, longitude: -122.0322),
countryName: "USA", countryName: "USA",
region: "US", region: "US",
cityName: "Cupertino", // Cupertino cityName: "Cupertino", // Cupertino
timeZone: TimeZone(abbreviation: "PST")!, timeZone: TimeZone(abbreviation: "PST")!,
today: .init(lastTimeUpdated: Date(), today: .init(lastTimeUpdated: Date(timeIntervalSinceNow: -4 * 3600),
date: Date(), date: Date(),
timeZone: TimeZone.current, timeZone: TimeZone.current,
weekDay: .monday, weekDay: .monday,
......
...@@ -16,13 +16,57 @@ struct MediumTemperatureWidgetView: View { ...@@ -16,13 +16,57 @@ struct MediumTemperatureWidgetView: View {
var body: some View { var body: some View {
GeometryReader { geometry in GeometryReader { geometry in
VStack { VStack(alignment: .leading) {
HStack { HStack {
HStack(spacing: 8) {
Text(widgetViewModel.temperature)
.font(AppFont.SFProDisplay.light(size: 32).font)
.textColor(for: colorScheme)
Divider()
.padding(.top, 8)
.padding(.bottom, 8)
Text(widgetViewModel.weatherType)
.font(AppFont.SFProDisplay.regular(size: 12).font)
.textColor(for: colorScheme)
.lineLimit(2)
Image(uiImage: widgetViewModel.weatherIcon)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 30, height: 30, alignment: .center)
.shadow(color: Color.black.opacity(0.23), radius: 16, x: 2, y: 0)
.padding(.trailing, 4)
}
Spacer()
VStack (spacing: 2) {
CityNameView(cityName: widgetViewModel.cityName, isDeviceLocation: widgetViewModel.isDeviceLocation)
HighLowTemperatureView(highTemperature: widgetViewModel.highTemperature, lowTemperature: widgetViewModel.lowTemperature)
}
.frame(height: 35)
} }
.frame(height: 35)
.padding(.top, 12)
HStack(alignment: .top) {
Text("SmartText")
.font(AppFont.SFProDisplay.regular(size: 12).font)
Spacer()
if widgetViewModel.showLastTimeUpdated {
Text(widgetViewModel.lastTimeUpdatedText)
.font(AppFont.SFProDisplay.regular(size: 9).font)
}
}
Spacer()
// TODO: implement // TODO: implement
} }
.padding([.leading, .trailing], 10)
} }
} }
......
...@@ -74,8 +74,8 @@ struct SmallTemperatureWidgetView: View { ...@@ -74,8 +74,8 @@ struct SmallTemperatureWidgetView: View {
} }
//MARK: Appearence extension //MARK: Appearence extension
private extension View { extension View {
func shadow(for colorScheme: ColorScheme) -> some View { public func shadow(for colorScheme: ColorScheme) -> some View {
switch colorScheme { switch colorScheme {
case .light: case .light:
return self.shadow(color: Color.black.opacity(0.5), radius: 16, x: 2, y: 0) return self.shadow(color: Color.black.opacity(0.5), radius: 16, x: 2, y: 0)
...@@ -86,7 +86,7 @@ private extension View { ...@@ -86,7 +86,7 @@ private extension View {
} }
} }
func textColor(for colorScheme: ColorScheme) -> some View { public func textColor(for colorScheme: ColorScheme) -> some View {
switch colorScheme { switch colorScheme {
case .light: case .light:
return self.foregroundColor(ThemeManager.currentTheme.secondaryTextColor.color) return self.foregroundColor(ThemeManager.currentTheme.secondaryTextColor.color)
......
...@@ -9,6 +9,8 @@ import SwiftUI ...@@ -9,6 +9,8 @@ import SwiftUI
import OneWeatherCore import OneWeatherCore
struct ForecastWidgetViewModel { struct ForecastWidgetViewModel {
let showLastTimeUpdated: Bool
let lastTimeUpdatedText: String
let cityName: String let cityName: String
let temperature: String let temperature: String
let weatherType: String let weatherType: String
...@@ -25,5 +27,24 @@ struct ForecastWidgetViewModel { ...@@ -25,5 +27,24 @@ struct ForecastWidgetViewModel {
self.highTemperature = location.today?.maxTemp?.shortString ?? "--" self.highTemperature = location.today?.maxTemp?.shortString ?? "--"
self.lowTemperature = location.today?.minTemp?.shortString ?? "--" self.lowTemperature = location.today?.minTemp?.shortString ?? "--"
self.isDeviceLocation = location.deviceLocation self.isDeviceLocation = location.deviceLocation
if let lastTimeUpdated = location.lastWeatherUpdateDate {
let oneHour = TimeInterval(3600)
let timeSinceLastUpdate = Date().timeIntervalSince(lastTimeUpdated)
self.showLastTimeUpdated = timeSinceLastUpdate > 3 * oneHour
let dateComponentsFormatter = DateComponentsFormatter()
dateComponentsFormatter.allowedUnits = [.hour, .day]
dateComponentsFormatter.zeroFormattingBehavior = .dropAll
dateComponentsFormatter.unitsStyle = .short
let formattedTimeAgo = dateComponentsFormatter.string(from: timeSinceLastUpdate) ?? "--"
self.lastTimeUpdatedText = "widget.lastUpdatedTemplate".localized().replacingOccurrences(of: "#LAST_UPDATED", with: formattedTimeAgo)
}
else {
self.showLastTimeUpdated = false
lastTimeUpdatedText = ""
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment