Commit 12ff1437 by Demid Merzlyakov

IOS-183: minutely general smart text support.

parent 27623f2a
{
"images" : [
{
"filename" : "bitmapCopy.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "bitmapCopy@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "bitmapCopy@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "bitmapCopy20.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "bitmapCopy20@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "bitmapCopy20@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -8,6 +8,7 @@
import UIKit
import OneWeatherCore
import Accelerate
import SnapKit
enum MinutelyForecastType {
case temperature
......@@ -16,6 +17,9 @@ enum MinutelyForecastType {
private let kTemperatureColors = [UIColor(hex: 0xff934f), UIColor(hex: 0xff414a)]
private let kPrecipitationColors = [UIColor(hex: 0x2d99ff), UIColor(hex: 0x8fc6fb)]
private let kSmartTextBackgroundColorTemperature = UIColor(hex: 0xfaedda80)
private let kSmartTextBackgroundColorPrecipitation = UIColor(hex: 0xd9ebfe)
private let kSmartTextAreaHeight = CGFloat(40)
private class MinutelyLevelView: UIView {
private let gradient = CAGradientLayer()
......@@ -67,6 +71,10 @@ class MinutelyForecastView: UIView {
private let levelsStackView = UIStackView()
private let verticalStackView = UIStackView()
private let scrollView = UIScrollView()
private let smartTextBackgroundView = UIView()
private var smartTextBackgroundViewHeightContraint: Constraint?
private let smartTextLabel = UILabel()
private let smartTextIcon = UIImageView()
private let centerDashline = CAShapeLayer()
private var levelsDashline = [CAShapeLayer]()
private let feedbackGenerator = UISelectionFeedbackGenerator()
......@@ -75,6 +83,8 @@ class MinutelyForecastView: UIView {
private var lastSelectedLevelIndex = 0
private var minutelyForecast = [MinutelyItem]()
private var forecastType = MinutelyForecastType.temperature
private var smartTextProvider: SmartTextProvider = SmartTextProvider(prioritizedSmartTexts: [])
private lazy var dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "h:mm a"
......@@ -88,6 +98,7 @@ class MinutelyForecastView: UIView {
prepareDetailView()
prepareCenterDashLine()
prepareScrollView()
prepareSmartTextView()
prepareVerticalStackView()
}
......@@ -128,6 +139,7 @@ class MinutelyForecastView: UIView {
centerDashline.strokeColor = forecastType == .temperature ? kTemperatureColors.last?.cgColor
: kPrecipitationColors.last?.cgColor
updateSmartText()
prepareMinutelyItems()
if let firstMinutelyItem = minutelyForecast.first {
......@@ -136,6 +148,29 @@ class MinutelyForecastView: UIView {
updateChart()
}
private func updateSmartText() {
smartTextBackgroundView.backgroundColor = self.forecastType == .temperature ? kSmartTextBackgroundColorTemperature : kSmartTextBackgroundColorPrecipitation
smartTextIcon.image = UIImage(named: forecastType == .temperature ? "minutely_smart_text_temperature" : "minutely_smart_text_precipitation")
var smartText = ""
if let location = self.location {
smartText = smartTextProvider.smartText(for: location)
}
smartTextLabel.text = smartText
let newHeight: CGFloat
if smartText.isEmpty {
newHeight = 0
smartTextBackgroundView.isHidden = true
}
else {
newHeight = kSmartTextAreaHeight
smartTextBackgroundView.isHidden = false
}
smartTextBackgroundViewHeightContraint?.deactivate()
smartTextBackgroundView.snp.makeConstraints { make in
smartTextBackgroundViewHeightContraint = make.height.equalTo(newHeight).constraint
}
}
private func updateDetailsView(minutelyItem: MinutelyItem) {
switch forecastType {
case .temperature:
......@@ -382,10 +417,41 @@ private extension MinutelyForecastView {
make.left.equalToSuperview().inset(42)
make.top.equalTo(detailsInfoView.snp.bottom).offset(8)
make.right.equalToSuperview().inset(20)
make.bottom.equalToSuperview().inset(40)
}
}
func prepareSmartTextView() {
smartTextBackgroundView.translatesAutoresizingMaskIntoConstraints = false
smartTextBackgroundView.layer.cornerRadius = 12
smartTextBackgroundView.clipsToBounds = true
addSubview(smartTextBackgroundView)
smartTextBackgroundView.snp.makeConstraints { make in
make.top.equalTo(scrollView.snp.bottom).offset(18)
make.left.right.equalToSuperview().inset(20)
make.bottom.equalToSuperview()
}
smartTextLabel.font = AppFont.SFPro.regular(size: 13)
smartTextLabel.numberOfLines = 0
smartTextBackgroundView.addSubview(smartTextIcon)
smartTextBackgroundView.addSubview(smartTextLabel)
smartTextIcon.snp.makeConstraints { make in
make.leading.equalToSuperview().inset(18)
make.width.height.equalTo(12)
make.centerY.equalToSuperview()
}
smartTextLabel.snp.makeConstraints { make in
make.leading.equalTo(smartTextIcon.snp.trailing).offset(7)
make.centerY.equalToSuperview()
make.trailing.lessThanOrEqualToSuperview().inset(18)
}
updateSmartText()
}
func prepareCenterDashLine() {
centerDashline.lineWidth = 1
centerDashline.lineDashPattern = [4,2]
......
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