Commit e8b2c07d by Dmitriy Stepanets

Merge branch 'master' into forecast-controller

# Conflicts:
#	1Weather.xcworkspace/xcuserdata/dstepanets.xcuserdatad/UserInterfaceState.xcuserstate
#	1Weather/UI/View controllers/Today/Cells/CityForecastTimePeriod/CityForecastTimePeriodCell.swift
parents 5faf43ad 81e13891
......@@ -27,6 +27,8 @@
CD6B303B2572680C004B34B3 /* SelfSizingButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6B303A2572680C004B34B3 /* SelfSizingButton.swift */; };
CD6B303E25726960004B34B3 /* ThemeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6B303D25726960004B34B3 /* ThemeProtocol.swift */; };
CD6B304325726AD1004B34B3 /* DefaultTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6B304225726AD1004B34B3 /* DefaultTheme.swift */; };
CD71709025FA317700A63C27 /* ForecastTimePeriodView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD71708F25FA317700A63C27 /* ForecastTimePeriodView.swift */; };
CD71709325FA31C200A63C27 /* ForecastTimePeriod.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD71709225FA31C200A63C27 /* ForecastTimePeriod.swift */; };
CD80917B2578E4A8003541A4 /* UIViewController+Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD80917A2578E4A8003541A4 /* UIViewController+Alert.swift */; };
CD822FF525D6817000A05501 /* CityForecastCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD822FF425D6817000A05501 /* CityForecastCell.swift */; };
CD822FFA25D6890900A05501 /* OneWeatherColorsAsset.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CD822FF925D6890900A05501 /* OneWeatherColorsAsset.xcassets */; };
......@@ -113,6 +115,8 @@
CD6B303A2572680C004B34B3 /* SelfSizingButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelfSizingButton.swift; sourceTree = "<group>"; };
CD6B303D25726960004B34B3 /* ThemeProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeProtocol.swift; sourceTree = "<group>"; };
CD6B304225726AD1004B34B3 /* DefaultTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultTheme.swift; sourceTree = "<group>"; };
CD71708F25FA317700A63C27 /* ForecastTimePeriodView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastTimePeriodView.swift; sourceTree = "<group>"; };
CD71709225FA31C200A63C27 /* ForecastTimePeriod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastTimePeriod.swift; sourceTree = "<group>"; };
CD80917A2578E4A8003541A4 /* UIViewController+Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Alert.swift"; sourceTree = "<group>"; };
CD822FF425D6817000A05501 /* CityForecastCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CityForecastCell.swift; sourceTree = "<group>"; };
CD822FF925D6890900A05501 /* OneWeatherColorsAsset.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = OneWeatherColorsAsset.xcassets; sourceTree = "<group>"; };
......@@ -435,6 +439,7 @@
CDC6126525E9085600188DA7 /* GraphLine.swift */,
CD86246B25E6826A0097F3FB /* InnerShadowLayer.swift */,
CDC6126925E90C8800188DA7 /* GraphLineSettings.swift */,
CD71708F25FA317700A63C27 /* ForecastTimePeriodView.swift */,
);
path = Helpers;
sourceTree = "<group>";
......@@ -508,6 +513,7 @@
CEAFF08B25DFC6BC00DF4EBF /* DailyWeather.swift */,
CEAFF08E25DFC6ED00DF4EBF /* HourlyWeather.swift */,
CE578FD225F7E89400E8B85D /* DayTimeWeather.swift */,
CD71709225FA31C200A63C27 /* ForecastTimePeriod.swift */,
);
path = ModelObjects;
sourceTree = "<group>";
......@@ -679,6 +685,7 @@
CD9B6B1425DBCDE2001D9B80 /* GraphView.swift in Sources */,
CD39F2EE25DE858D009FE398 /* NotificationName+Localization.swift in Sources */,
CEAFF08F25DFC6ED00DF4EBF /* HourlyWeather.swift in Sources */,
CD71709025FA317700A63C27 /* ForecastTimePeriodView.swift in Sources */,
CDE18DD825D16CB200C80ED9 /* NavigationCityButton.swift in Sources */,
CD17C60225D15C8500EE884E /* CoordinatorProtocol.swift in Sources */,
CDA5542825EF734200A2E08C /* TodayCellFactory.swift in Sources */,
......@@ -692,6 +699,7 @@
CDEE8AD725DA882200C289DE /* PeriodForecastButton.swift in Sources */,
CDE18DD125D166F900C80ED9 /* ForecastViewController.swift in Sources */,
CD39F2F525DE9571009FE398 /* ArrowButton.swift in Sources */,
CD71709325FA31C200A63C27 /* ForecastTimePeriod.swift in Sources */,
CEDE4E8325EEFD56007457E9 /* WdtLocationResponse.swift in Sources */,
CD8E041625F8F91B001785B6 /* ForecastCellFactory.swift in Sources */,
CDC6125325E79C8F00188DA7 /* DayTimeView.swift in Sources */,
......
......@@ -7,7 +7,7 @@
<key>1Weather.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>5</integer>
<integer>6</integer>
</dict>
<key>PG (Playground) 1.xcscheme</key>
<dict>
......
......@@ -33,6 +33,8 @@ extension Measurement {
extension Temperature {
var localeValue:Double {
#warning("Hardcoded value!")
// TODO: replace .fahrenheit with a value from Settings.
return self.converted(to: .fahrenheit).value.rounded(.down)
}
}
//
// ForecastTimePeriod.swift
// 1Weather
//
// Created by Dmitry Stepanets on 11.03.2021.
//
import UIKit
struct ForecastTimePeriod {
let daily:[DailyWeather]
let hourly:[HourlyWeather]
}
......@@ -7,43 +7,21 @@
import UIKit
private struct DailyGraphPoints {
let maxTempPoints: [CGPoint]
let minTempPoints: [CGPoint]
}
private struct HourlyGraphPoints {
let points: [CGPoint]
}
class ForecastTimePeriodCell: UITableViewCell {
//Private
private let periodSegmentedControl = ForecastTimePeriodControl(items: ["forecast.timePeriod.daily".localized(),
"forecast.timePeriod.hourly".localized()])
private let kMinGraphHeight:CGFloat = 20
private let gradientView = GradientView(startColor: UIColor(hex: 0xffffff).withAlphaComponent(0),
endColor: UIColor(hex: 0xdaddec),
opacity: 0.5)
private let scrollView = UIScrollView()
private let stackView = UIStackView()
private var location:Location?
private var currentTimePeriod = TimePeriod.daily
private var dailyGraphPoints: DailyGraphPoints?
private var hourlyGraphPoints: HourlyGraphPoints?
private let graphView = GraphView()
private var graphIsDrawn = false
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
prepareCell()
prepareSegmentedControl()
prepareGradient()
prepareScrollView()
prepareStackView()
prepareGraphView()
}
required init?(coder: NSCoder) {
......@@ -52,64 +30,6 @@ class ForecastTimePeriodCell: UITableViewCell {
//Public
public func configure(with location:Location) {
self.location = location
rebuildStackButtons()
}
public func drawGraphIfNeeded() {
guard graphIsDrawn == false else { return }
//Checking for correct height
guard
let periodButton = stackView.arrangedSubviews.first as? PeriodForecastButton,
periodButton.graphRect.height >= kMinGraphHeight
else {
return
}
graphView.frame = .init(x: 0,
y: periodButton.graphRect.origin.y,
width: stackView.frame.width,
height: periodButton.graphRect.height)
updateGraphPoints()
drawGraph()
graphIsDrawn = true
}
//Private
private func rebuildStackButtons() {
//Update graph buttons
stackView.arrangedSubviews.forEach {
stackView.removeArrangedSubview($0)
$0.removeFromSuperview()
}
guard let location = self.location else { return }
switch currentTimePeriod {
case .daily:
for index in 0..<location.daily.count {
let conditionButton = PeriodForecastButton()
conditionButton.configure(dailyWeather: location.daily[index])
conditionButton.index = index
conditionButton.addTarget(self, action: #selector(handleConditionButton(button:)), for: .touchUpInside)
conditionButton.isSelected = index == 1
stackView.addArrangedSubview(conditionButton)
}
case .hourly:
for index in 0..<location.hourly.count {
let conditionButton = PeriodForecastButton()
conditionButton.configure(hourlyWeather: location.hourly[index])
conditionButton.index = index
conditionButton.addTarget(self, action: #selector(handleConditionButton(button:)), for: .touchUpInside)
conditionButton.isSelected = index == 1
stackView.addArrangedSubview(conditionButton)
}
}
stackView.layoutIfNeeded()
graphIsDrawn = false
drawGraphIfNeeded()
}
@objc private func handleSegmentDidChange() {
......@@ -142,41 +62,4 @@ private extension ForecastTimePeriodCell {
make.height.equalTo(172)
}
}
func prepareScrollView() {
scrollView.showsVerticalScrollIndicator = false
scrollView.showsHorizontalScrollIndicator = false
scrollView.clipsToBounds = false
contentView.addSubview(scrollView)
scrollView.snp.makeConstraints { (make) in
make.left.equalToSuperview()
make.right.equalToSuperview()
make.top.equalTo(periodSegmentedControl.snp.bottom).offset(20).priority(.medium)
make.bottom.equalToSuperview().inset(15)
make.height.equalTo(267)
}
}
func prepareStackView() {
stackView.axis = .horizontal
stackView.distribution = .equalSpacing
stackView.alignment = .center
stackView.spacing = 10
stackView.clipsToBounds = false
stackView.isLayoutMarginsRelativeArrangement = true
stackView.layoutMargins = .init(top: 0, left: 6, bottom: 0, right: 6)
scrollView.addSubview(stackView)
stackView.snp.makeConstraints { (make) in
make.edges.height.equalToSuperview()
}
}
func prepareGraphView() {
//Graph view
graphView.frame = .zero
graphView.backgroundColor = .clear
scrollView.addSubview(graphView)
}
}
......@@ -83,7 +83,8 @@ class TodayCellFactory {
public func willDisplay(cell:UITableViewCell) {
switch cell {
case let timePeriodCell as CityForecastTimePeriodCell:
timePeriodCell.drawGraphIfNeeded()
break
// timePeriodCell.drawGraphIfNeeded()
case let sunCell as CitySunCell:
sunCell.updateSunPosition()
case let moonCell as CityMoonCell:
......
......@@ -52,7 +52,7 @@
<key>XMLCoder.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>6</integer>
<integer>5</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
......
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