Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ios/DPIPWidgets/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
35 changes: 35 additions & 0 deletions ios/DPIPWidgets/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "tinted"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions ios/DPIPWidgets/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
233 changes: 233 additions & 0 deletions ios/DPIPWidgets/CurrentWeatherWidgetSnapshot.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
import Foundation
import SwiftUI

enum CurrentWeatherWidgetCondition: String, Decodable {
case clear
case cloudy
case overcast
case rain
case thunderstorm
case snow
case fog
case unknown

var localizedDisplayName: LocalizedStringKey {
LocalizedStringKey(displayNameLocalizationKey)
}

var displayNameLocalizationKey: String {
switch self {
case .clear:
return "weather.clear"
case .cloudy:
return "weather.cloudy"
case .overcast:
return "weather.overcast"
case .rain:
return "weather.rain"
case .thunderstorm:
return "weather.thunderstorm"
case .snow:
return "weather.snow"
case .fog:
return "weather.fog"
case .unknown:
return "weather.unknown"
}
}

func systemImageName(isNight: Bool) -> String {
switch self {
case .clear:
return isNight
? "moon.stars.fill"
: "sun.max.fill"

case .cloudy:
return isNight
? "cloud.moon.fill"
: "cloud.sun.fill"

case .overcast:
return "cloud.fill"

case .rain:
return "cloud.rain.fill"

case .thunderstorm:
return "cloud.bolt.rain.fill"

case .snow:
return "cloud.snow.fill"

case .fog:
return "cloud.fog.fill"

case .unknown:
return "cloud.fill"
}
}
}

struct CurrentWeatherWidgetSnapshot: Decodable {
let schemaVersion: Int

let regionCode: String
let regionName: String

let observationTime: Int

let stationName: String

let weather: String
let weatherCode: Int
let condition: CurrentWeatherWidgetCondition
let isNight: Bool

/// The one next solar transition carried by this snapshot.
let nextDayNightTransitionTime: Int

/// Calibrated/server time minus device time, in milliseconds.
let calibratedTimeOffsetMilliseconds: Int

let temperature: Double?
let humidity: Int?
let rain: Double?

private enum CodingKeys: String, CodingKey {
case schemaVersion
case regionCode
case regionName
case observationTime
case stationName
case weather
case weatherCode
case condition
case isNight
case nextDayNightTransitionTime
case calibratedTimeOffsetMilliseconds
case temperature
case humidity
case rain
}

init(
schemaVersion: Int,
regionCode: String,
regionName: String,
observationTime: Int,
stationName: String,
weather: String,
weatherCode: Int,
condition: CurrentWeatherWidgetCondition,
isNight: Bool,
nextDayNightTransitionTime: Int,
calibratedTimeOffsetMilliseconds: Int,
temperature: Double?,
humidity: Int?,
rain: Double?
) {
self.schemaVersion = schemaVersion
self.regionCode = regionCode
self.regionName = regionName
self.observationTime = observationTime
self.stationName = stationName
self.weather = weather
self.weatherCode = weatherCode
self.condition = condition
self.isNight = isNight
self.nextDayNightTransitionTime = nextDayNightTransitionTime
self.calibratedTimeOffsetMilliseconds =
calibratedTimeOffsetMilliseconds
self.temperature = temperature
self.humidity = humidity
self.rain = rain
}

init(from decoder: Decoder) throws {
let container = try decoder.container(
keyedBy: CodingKeys.self
)

schemaVersion = try container.decode(
Int.self,
forKey: .schemaVersion
)

regionCode = try container.decode(
String.self,
forKey: .regionCode
)

regionName = try container.decode(
String.self,
forKey: .regionName
)

observationTime = try container.decode(
Int.self,
forKey: .observationTime
)

stationName = try container.decode(
String.self,
forKey: .stationName
)

weather = try container.decode(
String.self,
forKey: .weather
)

weatherCode = try container.decode(
Int.self,
forKey: .weatherCode
)

let conditionRawValue = try container.decodeIfPresent(
String.self,
forKey: .condition
)

condition = conditionRawValue
.flatMap(CurrentWeatherWidgetCondition.init(rawValue:))
?? .unknown

isNight = try container.decodeIfPresent(
Bool.self,
forKey: .isNight
) ?? false

nextDayNightTransitionTime = try container.decodeIfPresent(
Int.self,
forKey: .nextDayNightTransitionTime
) ?? 0

if schemaVersion >= 4 {
calibratedTimeOffsetMilliseconds = try container.decode(
Int.self,
forKey: .calibratedTimeOffsetMilliseconds
)
} else {
calibratedTimeOffsetMilliseconds = try container.decodeIfPresent(
Int.self,
forKey: .calibratedTimeOffsetMilliseconds
) ?? 0
}

temperature = try container.decodeIfPresent(
Double.self,
forKey: .temperature
)

humidity = try container.decodeIfPresent(
Int.self,
forKey: .humidity
)

rain = try container.decodeIfPresent(
Double.self,
forKey: .rain
)
}
}
Loading
Loading