Skip to content

Commit

Permalink
finished the wind graphic, redid the UVView for iPad, added 2 more pr…
Browse files Browse the repository at this point in the history
…operties to the WeatherKitData struct, minor change to test the new windDirectionAngle and UVCategory properties
  • Loading branch information
Sendeky committed Dec 24, 2024
1 parent b801b7a commit ceefe4e
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 22 deletions.
2 changes: 2 additions & 0 deletions programmatic-ui-weather-app/Utils/WeatherKitCallUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extension MainViewController {

MF0.numberFormatter.maximumFractionDigits = 3
let uv = result.0.uvIndex.value
let uvCategory = result.0.uvIndex.category.description
let windSpeed = MF0.string(from: result.0.wind.speed)
print(windSpeed)
let windDirection = result.0.wind.compassDirection
Expand Down Expand Up @@ -143,6 +144,7 @@ extension MainViewController {
WeatherKitData.TempMax = tempMax
WeatherKitData.TempMin = tempMin
WeatherKitData.UV = uv
WeatherKitData.UVCategory = uvCategory
WeatherKitData.WindSpeed = windSpeed
WeatherKitData.WindDirection = "\(windDirection)"
WeatherKitData.Symbol = symbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ extension MainViewController {

// Function to update the UVIndex
func updateUVIndex(_ value: Int) {
print("skibb: \(WeatherKitData.UVCategory)")
// Create a mask layer to achieve the progress bar effect
let maskLayer = CALayer()
let clampedValue = min(max(value, 0), 11)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct WeatherKitData: Codable{
static var TempFeels = 0

static var UV = 0
static var UVCategory = ""

static var WindDirection = ""
static var WindDirectionAngle = 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,34 @@ class iPadUVView: UIView {
stack.axis = .vertical
stack.backgroundColor = cyanColor
stack.isLayoutMarginsRelativeArrangement = true
stack.layoutMargins = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
stack.spacing = 20
stack.layoutMargins = UIEdgeInsets(top: 0, left: 10, bottom: 10, right: 10)
stack.spacing = 6
return stack
}()

private let UVViewTitleLabel: UILabel = {
let label = UILabel()
label.text = "UV Index"
label.text = "UV"
label.textAlignment = .center
label.heightAnchor.constraint(equalToConstant: 30).isActive = true
label.font = .boldSystemFont(ofSize: 18.0)
return label
}()

private let UVLabel: UILabel = {
let label = UILabel()
label.text = "--"
label.numberOfLines = 2
label.textAlignment = .left
return label
}()

private let UVLabel: UILabel = {
private let UVStatus: UILabel = {
let label = UILabel()
label.text = "--"
label.textAlignment = .center
label.heightAnchor.constraint(equalToConstant: 40).isActive = true
label.font = .boldSystemFont(ofSize: 32.0)
return label
}()

Expand Down Expand Up @@ -147,8 +158,9 @@ class iPadUVView: UIView {

// Add subviews to stack
uvStackView.addArrangedSubview(UVViewTitleLabel)
uvStackView.addArrangedSubview(UVLabel)
uvStackView.addArrangedSubview(UVStatus)
uvStackView.addArrangedSubview(uvProgressView)
uvStackView.addArrangedSubview(UVLabel)

// Add stack to view
addSubview(uvStackView)
Expand All @@ -163,7 +175,7 @@ class iPadUVView: UIView {
uvProgressView.heightAnchor.constraint(equalToConstant: 6)
])

updateUVIndex(WeatherKitData.UV)
updateUVIndex(WeatherKitData.UV, WeatherKitData.UVCategory)
}

override func layoutSubviews() {
Expand All @@ -172,12 +184,14 @@ class iPadUVView: UIView {
}

// MARK: - Public Methods
func updateUVIndex(_ value: Int) {
UVLabel.text = "\(value)"
func updateUVIndex(_ value1: Int, _ value2: String) {
UVLabel.text = "The UV Index is currently \(value2)"
print("skibb: \(value2)")
UVStatus.text = "\(value1)"

// Create a mask layer to achieve the progress bar effect
let maskLayer = CALayer()
let clampedValue = min(max(value, 0), 11)
let clampedValue = min(max(value1, 0), 11)
let percentage = CGFloat(clampedValue) / 11.0

// The gradient layer should always be full width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import UIKit
import SwiftUI


class WindCompassView: UIView {
Expand Down Expand Up @@ -69,6 +70,7 @@ class WindCompassView: UIView {
let fontSize = min(bounds.width, bounds.height) * 0.15 // Makes font size relative to view size
let attrs: [NSAttributedString.Key: Any] = [
.font: UIFont.systemFont(ofSize: fontSize),
// .font: customFont,
.foregroundColor: UIColor.white
]

Expand Down Expand Up @@ -123,6 +125,17 @@ class WindCompassView: UIView {

context.restoreGState()
}

func setupFont() -> UIFont {
guard let customFont = UIFont(name: "SpaceX", size: 20.0) else {
fatalError("""
Failed to load the "SpaceX" font.
Make sure the font file is included in the project and the font name is spelled correctly.
"""
)
}
return customFont
}
}


Expand All @@ -136,7 +149,7 @@ class iPadWindView: UIView {
stack.backgroundColor = cyanColor
stack.isLayoutMarginsRelativeArrangement = true
stack.layoutMargins = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
stack.spacing = 20
stack.spacing = 0
return stack
}()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class iPadMainViewController: UIViewController, UICollectionViewDelegate, UIColl
humidityView.topAnchor.constraint(equalTo: mainScrollView.topAnchor, constant: 15),
humidityView.heightAnchor.constraint(equalToConstant: 100),
humidityView.leadingAnchor.constraint(equalTo: mainScrollView.leadingAnchor),
humidityView.widthAnchor.constraint(equalToConstant: 150),
humidityView.widthAnchor.constraint(equalToConstant: 180),
//rocketView constraints
rocketView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
rocketView.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.5),
Expand All @@ -202,8 +202,8 @@ class iPadMainViewController: UIViewController, UICollectionViewDelegate, UIColl
// UVView constraints
UVView.topAnchor.constraint(equalTo: dailyForecastView.bottomAnchor, constant: 15),
UVView.leadingAnchor.constraint(equalTo: dailyForecastView.leadingAnchor),
UVView.widthAnchor.constraint(equalToConstant: 150),
UVView.heightAnchor.constraint(equalToConstant: 150),
UVView.widthAnchor.constraint(equalToConstant: 180),
UVView.heightAnchor.constraint(equalToConstant: 180),
// precipitationView constraints
precipitationView.topAnchor.constraint(equalTo: sunsetView.bottomAnchor, constant: 15),
precipitationView.leadingAnchor.constraint(equalTo: sunsetView.leadingAnchor),
Expand All @@ -212,8 +212,8 @@ class iPadMainViewController: UIViewController, UICollectionViewDelegate, UIColl
// windView constraints
windView.topAnchor.constraint(equalTo: dailyForecastView.bottomAnchor, constant: 15),
windView.leadingAnchor.constraint(equalTo: precipitationView.leadingAnchor),
windView.widthAnchor.constraint(equalToConstant: 150),
windView.heightAnchor.constraint(equalToConstant: 150),
windView.widthAnchor.constraint(equalToConstant: 180),
windView.heightAnchor.constraint(equalToConstant: 180),
])
}

Expand Down Expand Up @@ -422,7 +422,7 @@ class iPadMainViewController: UIViewController, UICollectionViewDelegate, UIColl
self.precipitationView.updatePrecipitationLabel(WeatherKitData.PrecipitationChance)
self.sunsetView.updateSunsetLabels(WeatherKitData.Sunrise, WeatherKitData.Sunset)
self.windView.updateWindLabel(WeatherKitData.WindSpeed)
self.UVView.updateUVIndex(WeatherKitData.UV)
self.UVView.updateUVIndex(WeatherKitData.UV, WeatherKitData.UVCategory)
// self.windLabel.text = "\(WeatherKitData.WindSpeed)"
// self.precipitationLabel.text = "\(WeatherKitData.PrecipitationChance)% Chance"
DateConverter().timeArrayMaker()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extension iPadMainViewController {

MF0.numberFormatter.maximumFractionDigits = 3
let uv = result.0.uvIndex.value
let uvCategory = result.0.uvIndex.category.description
let windSpeed = MF0.string(from: result.0.wind.speed)
print(windSpeed)
let windDirection = result.0.wind.compassDirection
Expand Down Expand Up @@ -145,6 +146,7 @@ extension iPadMainViewController {
WeatherKitData.TempMax = tempMax
WeatherKitData.TempMin = tempMin
WeatherKitData.UV = uv
WeatherKitData.UVCategory = uvCategory
WeatherKitData.WindSpeed = windSpeed
WeatherKitData.WindDirection = "\(windDirection)"
WeatherKitData.WindDirectionAngle = windDirectionAngle.value
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@
filePath = "programmatic-ui-weather-app/Utils/WeatherKitCallUtil.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "126"
endingLineNumber = "126"
startingLineNumber = "127"
endingLineNumber = "127"
landmarkName = "getWeather(location:)"
landmarkType = "7">
</BreakpointContent>
Expand Down Expand Up @@ -224,8 +224,8 @@
filePath = "programmatic-ui-weather-app/Utils/WeatherKitCallUtil.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "147"
endingLineNumber = "147"
startingLineNumber = "149"
endingLineNumber = "149"
landmarkName = "getWeather(location:)"
landmarkType = "7">
</BreakpointContent>
Expand Down Expand Up @@ -272,8 +272,8 @@
filePath = "programmatic-ui-weather-app/Utils/WeatherKitCallUtil.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "191"
endingLineNumber = "191"
startingLineNumber = "193"
endingLineNumber = "193"
landmarkName = "updateLabelsAfterAwait()"
landmarkType = "7">
</BreakpointContent>
Expand Down

0 comments on commit ceefe4e

Please sign in to comment.