Commit a6eedde5 by Dmitriy Stepanets

Moved MediumWidget to OneWeatherUI module

parent e5533185
...@@ -287,4 +287,6 @@ ...@@ -287,4 +287,6 @@
//Widget //Widget
"widget.small.title" = "Temperature Forecast"; "widget.small.title" = "Temperature Forecast";
"widget.small.description" = ""; "widget.small.description" = "";
"widget.medium.title" = "Temperature Forecast";
"widget.medium.description" = "";
"widget.lastUpdatedTemplate" = "Last updated #LAST_UPDATED ago."; "widget.lastUpdatedTemplate" = "Last updated #LAST_UPDATED ago.";
...@@ -9,20 +9,25 @@ import SwiftUI ...@@ -9,20 +9,25 @@ import SwiftUI
import WidgetKit import WidgetKit
@available (iOS 14, *) @available (iOS 14, *)
struct MediumTemperatureWidgetView: View { public struct MediumTemperatureWidgetView: View {
//Public //Public
let widgetViewModel: WidgetViewModel let widgetViewModel: WidgetViewModel
public init(widgetViewModel: WidgetViewModel?) {
self.widgetViewModel = widgetViewModel ?? WidgetViewModelMock()
}
//Private
@Environment(\.colorScheme) private var colorScheme @Environment(\.colorScheme) private var colorScheme
var body: some View { public var body: some View {
GeometryReader { geometry in GeometryReader { geometry in
VStack(alignment: .leading) { VStack(alignment: .leading) {
HStack { HStack {
HStack(spacing: 8) { HStack(spacing: 8) {
Text(widgetViewModel.temperature) Text(widgetViewModel.temperature)
.font(WidgetFont.SFProDisplay.light(size: 32).font) .font(WidgetFont.SFProDisplay.light(size: 32).font)
foregroundColor(Color("PrimaryTextColor", .foregroundColor(Color("PrimaryTextColor",
bundle: OneWeatherUI.frameworkBundle)) bundle: OneWeatherUI.frameworkBundle))
Divider() Divider()
.padding(.top, 8) .padding(.top, 8)
...@@ -34,17 +39,15 @@ struct MediumTemperatureWidgetView: View { ...@@ -34,17 +39,15 @@ struct MediumTemperatureWidgetView: View {
bundle: OneWeatherUI.frameworkBundle)) bundle: OneWeatherUI.frameworkBundle))
.lineLimit(2) .lineLimit(2)
Image(uiImage: widgetViewModel.weatherIcon) weatherImage(uiImage: widgetViewModel.weatherIcon)
.resizable()
.aspectRatio(contentMode: .fit) .aspectRatio(contentMode: .fit)
.frame(width: 30, height: 30, alignment: .center) .frame(width: 30, height: 30, alignment: .center)
.shadow(color: Color.black.opacity(0.23), radius: 16, x: 2, y: 0) .shadow(for: colorScheme)
.padding(.trailing, 4) .padding(.trailing, 4)
} }
Spacer() Spacer()
VStack (spacing: 2) { VStack (spacing: 2) {
CityNameView(cityName: widgetViewModel.cityName, isDeviceLocation: widgetViewModel.isDeviceLocation) CityNameView(cityName: widgetViewModel.cityName, isDeviceLocation: widgetViewModel.isDeviceLocation)
HighLowTemperatureView(highTemperature: widgetViewModel.highTemperature, lowTemperature: widgetViewModel.lowTemperature) HighLowTemperatureView(highTemperature: widgetViewModel.highTemperature, lowTemperature: widgetViewModel.lowTemperature)
} }
.frame(height: 35) .frame(height: 35)
...@@ -69,7 +72,24 @@ struct MediumTemperatureWidgetView: View { ...@@ -69,7 +72,24 @@ struct MediumTemperatureWidgetView: View {
.padding([.leading, .trailing], 10) .padding([.leading, .trailing], 10)
} }
} }
}
@available(iOS 14, *)
private extension View {
func shadow(for colorScheme: ColorScheme) -> some View {
switch colorScheme {
case .light:
return self.shadow(color: Color.black.opacity(0.5), radius: 16, x: 2, y: 0)
case .dark:
return self.shadow(color: Color.white.opacity(0.24), radius: 16, x: 2, y: 0)
@unknown default:
return self.shadow(color: Color.black.opacity(0.5), radius: 16, x: 2, y: 0)
}
}
func weatherImage(uiImage: UIImage) -> Image {
return Image(uiImage: uiImage.scalePreservingAspectRatio(targetSize: .init(width: 30, height: 30)))
}
} }
@available(iOS 14, *) @available(iOS 14, *)
......
...@@ -17,6 +17,9 @@ struct WidgetPlaceholderView: View { ...@@ -17,6 +17,9 @@ struct WidgetPlaceholderView: View {
case .systemSmall: case .systemSmall:
SmallTemperatureWidgetView(widgetViewModel: ForecastWidgetViewModel(location: WeatherEntry.defaultLocation)) SmallTemperatureWidgetView(widgetViewModel: ForecastWidgetViewModel(location: WeatherEntry.defaultLocation))
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
case .systemMedium:
MediumTemperatureWidgetView(widgetViewModel: ForecastWidgetViewModel(location: WeatherEntry.defaultLocation))
.redacted(reason: .placeholder)
default: default:
SmallTemperatureWidgetView(widgetViewModel: ForecastWidgetViewModel(location: WeatherEntry.defaultLocation)) SmallTemperatureWidgetView(widgetViewModel: ForecastWidgetViewModel(location: WeatherEntry.defaultLocation))
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
......
...@@ -7,13 +7,25 @@ ...@@ -7,13 +7,25 @@
import SwiftUI import SwiftUI
import WidgetKit import WidgetKit
import OneWeatherUI
struct MediumTemperatureWidget: Widget { struct MediumTemperatureWidget: Widget {
private let kind = "com.onelouder.oneweather.widget.medium.temperature" private let kind = "com.onelouder.oneweather.widget.medium.temperature"
var body: some WidgetConfiguration { var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: WeatherProvider()) { weatherEntry in StaticConfiguration(kind: kind, provider: WeatherProvider()) { weatherEntry in
MediumTemperatureWidgetView(widgetViewModel: .init(location: weatherEntry.location)) MediumTemperatureWidgetView(widgetViewModel: ForecastWidgetViewModel(location: weatherEntry.location))
} }
.configurationDisplayName("widget.medium.title".localized())
.description("widget.medium.description".localized())
.supportedFamilies([.systemMedium]) .supportedFamilies([.systemMedium])
} }
} }
struct MediumTemperatureWidgetView_Preview: PreviewProvider {
public static var previews: some View {
MediumTemperatureWidgetView(widgetViewModel: nil)
.previewContext(WidgetPreviewContext(family: .systemMedium))
}
}
...@@ -11,7 +11,7 @@ import OneWeatherUI ...@@ -11,7 +11,7 @@ import OneWeatherUI
import Localize_Swift import Localize_Swift
struct SmallTemperatureWidget: Widget { struct SmallTemperatureWidget: Widget {
private let kind = "com.onelouder.oneweather.widget.small" private let kind = "com.onelouder.oneweather.widget.small.temperature"
var body: some WidgetConfiguration { var body: some WidgetConfiguration {
// We currently display selectedLocation, so it's not really configurable, but we'll probably need to switch to an IntentConfiguration at some point. // We currently display selectedLocation, so it's not really configurable, but we'll probably need to switch to an IntentConfiguration at some point.
......
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