Commit a6eedde5 by Dmitriy Stepanets

Moved MediumWidget to OneWeatherUI module

parent e5533185
......@@ -287,4 +287,6 @@
//Widget
"widget.small.title" = "Temperature Forecast";
"widget.small.description" = "";
"widget.medium.title" = "Temperature Forecast";
"widget.medium.description" = "";
"widget.lastUpdatedTemplate" = "Last updated #LAST_UPDATED ago.";
......@@ -9,20 +9,25 @@ import SwiftUI
import WidgetKit
@available (iOS 14, *)
struct MediumTemperatureWidgetView: View {
public struct MediumTemperatureWidgetView: View {
//Public
let widgetViewModel: WidgetViewModel
public init(widgetViewModel: WidgetViewModel?) {
self.widgetViewModel = widgetViewModel ?? WidgetViewModelMock()
}
//Private
@Environment(\.colorScheme) private var colorScheme
var body: some View {
public var body: some View {
GeometryReader { geometry in
VStack(alignment: .leading) {
HStack {
HStack(spacing: 8) {
Text(widgetViewModel.temperature)
.font(WidgetFont.SFProDisplay.light(size: 32).font)
foregroundColor(Color("PrimaryTextColor",
.foregroundColor(Color("PrimaryTextColor",
bundle: OneWeatherUI.frameworkBundle))
Divider()
.padding(.top, 8)
......@@ -34,17 +39,15 @@ struct MediumTemperatureWidgetView: View {
bundle: OneWeatherUI.frameworkBundle))
.lineLimit(2)
Image(uiImage: widgetViewModel.weatherIcon)
.resizable()
weatherImage(uiImage: widgetViewModel.weatherIcon)
.aspectRatio(contentMode: .fit)
.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)
}
Spacer()
VStack (spacing: 2) {
CityNameView(cityName: widgetViewModel.cityName, isDeviceLocation: widgetViewModel.isDeviceLocation)
HighLowTemperatureView(highTemperature: widgetViewModel.highTemperature, lowTemperature: widgetViewModel.lowTemperature)
}
.frame(height: 35)
......@@ -69,7 +72,24 @@ struct MediumTemperatureWidgetView: View {
.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, *)
......
......@@ -17,6 +17,9 @@ struct WidgetPlaceholderView: View {
case .systemSmall:
SmallTemperatureWidgetView(widgetViewModel: ForecastWidgetViewModel(location: WeatherEntry.defaultLocation))
.redacted(reason: .placeholder)
case .systemMedium:
MediumTemperatureWidgetView(widgetViewModel: ForecastWidgetViewModel(location: WeatherEntry.defaultLocation))
.redacted(reason: .placeholder)
default:
SmallTemperatureWidgetView(widgetViewModel: ForecastWidgetViewModel(location: WeatherEntry.defaultLocation))
.redacted(reason: .placeholder)
......
......@@ -7,13 +7,25 @@
import SwiftUI
import WidgetKit
import OneWeatherUI
struct MediumTemperatureWidget: Widget {
private let kind = "com.onelouder.oneweather.widget.medium.temperature"
var body: some WidgetConfiguration {
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])
}
}
struct MediumTemperatureWidgetView_Preview: PreviewProvider {
public static var previews: some View {
MediumTemperatureWidgetView(widgetViewModel: nil)
.previewContext(WidgetPreviewContext(family: .systemMedium))
}
}
......@@ -11,7 +11,7 @@ import OneWeatherUI
import Localize_Swift
struct SmallTemperatureWidget: Widget {
private let kind = "com.onelouder.oneweather.widget.small"
private let kind = "com.onelouder.oneweather.widget.small.temperature"
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.
......
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