Commit e5533185 by Dmitriy Stepanets

Merge commit 'e38fdf8f' into feature/IOS-123-widget-promotion-sheet

# Conflicts:
#	1Weather.xcodeproj/project.pbxproj
#	1Weather/Resources/en.lproj/Localizable.strings
#	OneWeatherUI/OneWeatherUI/Widgets/SmallTemperatureWidgetView.swift
#	OneWeatherWidget/ViewModels/ForecastWidgetViewModel.swift
#	Podfile
#	Podfile.lock
#	Pods/Manifest.lock
#	Pods/Pods.xcodeproj/project.pbxproj
parents 1e355fe6 e38fdf8f
......@@ -287,3 +287,4 @@
//Widget
"widget.small.title" = "Temperature Forecast";
"widget.small.description" = "";
"widget.lastUpdatedTemplate" = "Last updated #LAST_UPDATED ago.";
......@@ -11,6 +11,7 @@
CD259C02268DE109008D205E /* OneWeatherUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD259BF8268DE109008D205E /* OneWeatherUI.framework */; };
CD259C07268DE109008D205E /* OneWeatherUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD259C06268DE109008D205E /* OneWeatherUITests.swift */; };
CD259C09268DE109008D205E /* OneWeatherUI.h in Headers */ = {isa = PBXBuildFile; fileRef = CD259BFB268DE109008D205E /* OneWeatherUI.h */; settings = {ATTRIBUTES = (Public, ); }; };
CD3C83C326933ABD0087A225 /* MediumTemperatureWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3C83C226933ABC0087A225 /* MediumTemperatureWidgetView.swift */; };
CD7D3161268EEF49000D01FA /* CityNameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD7D315F268EEF48000D01FA /* CityNameView.swift */; };
CD7D3162268EEF49000D01FA /* HighLowTemperatureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD7D3160268EEF49000D01FA /* HighLowTemperatureView.swift */; };
CD7D3164268EEF56000D01FA /* SmallTemperatureWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD7D3163268EEF56000D01FA /* SmallTemperatureWidgetView.swift */; };
......@@ -47,6 +48,7 @@
CD259C01268DE109008D205E /* OneWeatherUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OneWeatherUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
CD259C06268DE109008D205E /* OneWeatherUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OneWeatherUITests.swift; sourceTree = "<group>"; };
CD259C08268DE109008D205E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CD3C83C226933ABC0087A225 /* MediumTemperatureWidgetView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MediumTemperatureWidgetView.swift; sourceTree = "<group>"; };
CD7D315F268EEF48000D01FA /* CityNameView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CityNameView.swift; sourceTree = "<group>"; };
CD7D3160268EEF49000D01FA /* HighLowTemperatureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HighLowTemperatureView.swift; sourceTree = "<group>"; };
CD7D3163268EEF56000D01FA /* SmallTemperatureWidgetView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SmallTemperatureWidgetView.swift; sourceTree = "<group>"; };
......@@ -144,6 +146,7 @@
CD7D316E268EF2BC000D01FA /* WidgetViewModel.swift */,
CD7D3177268EFB9E000D01FA /* WidgetViewModelMock.swift */,
CD7D3163268EEF56000D01FA /* SmallTemperatureWidgetView.swift */,
CD3C83C226933ABC0087A225 /* MediumTemperatureWidgetView.swift */,
CD7D315E268EEF37000D01FA /* SharedViews */,
CD7D3175268EF8A9000D01FA /* WidgetFont.swift */,
);
......@@ -330,6 +333,7 @@
CD7D3162268EEF49000D01FA /* HighLowTemperatureView.swift in Sources */,
CD7D3161268EEF49000D01FA /* CityNameView.swift in Sources */,
CD7D3164268EEF56000D01FA /* SmallTemperatureWidgetView.swift in Sources */,
CD3C83C326933ABD0087A225 /* MediumTemperatureWidgetView.swift in Sources */,
CD7D3168268EF167000D01FA /* UIFont+Font.swift in Sources */,
CD7D3187268F1F2E000D01FA /* UIImage+Resize.swift in Sources */,
CD7D3178268EFB9E000D01FA /* WidgetViewModelMock.swift in Sources */,
......
//
// MediumTemperatureWidgetView.swift
// OneWeatherWidgetExtension
//
// Created by Demid Merzlyakov on 28.06.2021.
//
import SwiftUI
import WidgetKit
@available (iOS 14, *)
struct MediumTemperatureWidgetView: View {
//Public
let widgetViewModel: WidgetViewModel
@Environment(\.colorScheme) private var colorScheme
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",
bundle: OneWeatherUI.frameworkBundle))
Divider()
.padding(.top, 8)
.padding(.bottom, 8)
Text(widgetViewModel.weatherType)
.font(WidgetFont.SFProDisplay.regular(size: 12).font)
.foregroundColor(Color("PrimaryTextColor",
bundle: OneWeatherUI.frameworkBundle))
.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(WidgetFont.SFProDisplay.regular(size: 12).font)
Spacer()
if widgetViewModel.showLastTimeUpdated {
Text(widgetViewModel.lastTimeUpdatedText)
.font(WidgetFont.SFProDisplay.regular(size: 9).font)
}
}
Spacer()
// TODO: implement
}
.padding([.leading, .trailing], 10)
}
}
}
@available(iOS 14, *)
public struct MediumTemperatureWidgetView_Preview: PreviewProvider {
public static var previews: some View {
MediumTemperatureWidgetView(widgetViewModel: WidgetViewModelMock())
.frame(width: 338, height: 158)
}
}
......@@ -9,6 +9,8 @@ import UIKit
@available(iOS 14, *)
public protocol WidgetViewModel {
var showLastTimeUpdated: Bool { get }
var lastTimeUpdatedText: String { get }
var cityName: String { get }
var temperature: String { get }
var weatherType: String { get }
......
......@@ -10,6 +10,8 @@ import UIKit
@available(iOS 14, *)
struct WidgetViewModelMock: WidgetViewModel {
private class OneWeatherUIClass {}
let showLastTimeUpdated = false
let lastTimeUpdatedText = "Last update text"
let cityName = "New York"
let temperature = "96°"
let weatherType = "Partly Cloudy"
......
{
"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
struct WeatherEntry: TimelineEntry {
static let defaultLocation = Location(deviceLocation: true,
lastWeatherUpdateDate: Date(timeIntervalSinceNow: -4 * 3600),
coordinates: .init(latitude: 37.3230, longitude: -122.0322),
countryName: "USA",
region: "US",
cityName: "Cupertino", // Cupertino
timeZone: TimeZone(abbreviation: "PST")!,
today: .init(lastTimeUpdated: Date(),
today: .init(lastTimeUpdated: Date(timeIntervalSinceNow: -4 * 3600),
date: Date(),
timeZone: TimeZone.current,
weekDay: .monday,
......
......@@ -11,5 +11,6 @@ import SwiftUI
struct OneWeatherWidgets: WidgetBundle {
var body: some Widget {
SmallTemperatureWidget()
MediumTemperatureWidget()
}
}
......@@ -10,6 +10,8 @@ import OneWeatherCore
import OneWeatherUI
struct ForecastWidgetViewModel: WidgetViewModel {
let showLastTimeUpdated: Bool
let lastTimeUpdatedText: String
let cityName: String
let temperature: String
let weatherType: String
......@@ -26,5 +28,24 @@ struct ForecastWidgetViewModel: WidgetViewModel {
self.highTemperature = location.today?.maxTemp?.shortString ?? "--"
self.lowTemperature = location.today?.minTemp?.shortString ?? "--"
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 = ""
}
}
}
//
// MediumTemperatureWidget.swift
// OneWeatherWidgetExtension
//
// Created by Demid Merzlyakov on 28.06.2021.
//
import SwiftUI
import WidgetKit
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))
}
.supportedFamilies([.systemMedium])
}
}
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