Skip to content

Commit 12ecccc

Browse files
committed
Improve weather condition mapping
1 parent e7b6905 commit 12ecccc

File tree

5 files changed

+53
-78
lines changed

5 files changed

+53
-78
lines changed

DatWeatherDoe.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
20D8571B2A831D62005727BB /* WeatherRepositoryType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20D8571A2A831D62005727BB /* WeatherRepositoryType.swift */; };
7171
20D8571D2A831F40005727BB /* WeatherRepositoryFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20D8571C2A831F40005727BB /* WeatherRepositoryFactory.swift */; };
7272
20D8571F2A832AC6005727BB /* TemperatureUnit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20D8571E2A832AC6005727BB /* TemperatureUnit.swift */; };
73-
20E4E18529AC719E00860C18 /* WeatherConditionImageMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20E4E18429AC719E00860C18 /* WeatherConditionImageMapper.swift */; };
7473
20E8A1A62C2B3C5A007E8733 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 20E8A1A52C2B3C5A007E8733 /* Localizable.xcstrings */; };
7574
20E8A1AB2C2B3FE6007E8733 /* TestData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20E8A1AA2C2B3FE6007E8733 /* TestData.swift */; };
7675
20F17D3A26597A02003A164E /* WeatherData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20F17D3926597A02003A164E /* WeatherData.swift */; };
@@ -155,7 +154,6 @@
155154
20D8571A2A831D62005727BB /* WeatherRepositoryType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherRepositoryType.swift; sourceTree = "<group>"; };
156155
20D8571C2A831F40005727BB /* WeatherRepositoryFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherRepositoryFactory.swift; sourceTree = "<group>"; };
157156
20D8571E2A832AC6005727BB /* TemperatureUnit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemperatureUnit.swift; sourceTree = "<group>"; };
158-
20E4E18429AC719E00860C18 /* WeatherConditionImageMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherConditionImageMapper.swift; sourceTree = "<group>"; };
159157
20E8A1A52C2B3C5A007E8733 /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
160158
20E8A1AA2C2B3FE6007E8733 /* TestData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestData.swift; sourceTree = "<group>"; };
161159
20F17D3926597A02003A164E /* WeatherData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherData.swift; sourceTree = "<group>"; };
@@ -239,7 +237,6 @@
239237
2039B3EE2C28996D006A6B6D /* WeatherCondition.swift */,
240238
202B1014278D46AB00ED6D42 /* WeatherConditionBuilder.swift */,
241239
2077BC51278DF98800E0453C /* WeatherConditionTextMapper.swift */,
242-
20E4E18429AC719E00860C18 /* WeatherConditionImageMapper.swift */,
243240
);
244241
path = Condition;
245242
sourceTree = "<group>";
@@ -709,7 +706,6 @@
709706
2039B3EB2C2896D7006A6B6D /* ForecastTemperatureData.swift in Sources */,
710707
20F17D3A26597A02003A164E /* WeatherData.swift in Sources */,
711708
202B1015278D46AB00ED6D42 /* WeatherConditionBuilder.swift in Sources */,
712-
20E4E18529AC719E00860C18 /* WeatherConditionImageMapper.swift in Sources */,
713709
206E152F2A7C544D0096D33C /* ConfigureOptionsView.swift in Sources */,
714710
2039B3E92C2896CF006A6B6D /* ForecastData.swift in Sources */,
715711
209F8A3D27914A5900EB5C45 /* NetworkClient.swift in Sources */,

DatWeatherDoe/UI/Decorator/Condition/WeatherCondition.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,54 @@ enum WeatherCondition {
2020
static func getFallback(isDay: Bool) -> WeatherCondition {
2121
isDay ? .sunny : .clearNight
2222
}
23+
24+
var symbolName: String {
25+
switch self {
26+
case .cloudy:
27+
"cloud"
28+
case .partlyCloudy:
29+
"cloud.sun"
30+
case .partlyCloudyNight:
31+
"cloud.moon"
32+
case .sunny:
33+
"sun.max"
34+
case .clearNight:
35+
"moon"
36+
case .snow:
37+
"cloud.snow"
38+
case .lightRain, .heavyRain, .freezingRain:
39+
"cloud.rain"
40+
case .partlyCloudyRain:
41+
"cloud.sun.rain"
42+
case .thunderstorm:
43+
"cloud.bolt.rain"
44+
case .mist, .fog:
45+
"cloud.fog"
46+
}
47+
}
48+
49+
var accessibilityLabel: String {
50+
switch self {
51+
case .cloudy:
52+
"Cloudy"
53+
case .partlyCloudy:
54+
"Partly Cloudy"
55+
case .partlyCloudyNight:
56+
"Partly Cloudy"
57+
case .sunny:
58+
"Sunny"
59+
case .clearNight:
60+
"Clear"
61+
case .snow:
62+
"Snow"
63+
case .lightRain, .heavyRain, .freezingRain:
64+
"Rainy"
65+
case .partlyCloudyRain:
66+
"Partly cloudy with rain"
67+
case .thunderstorm:
68+
"Thunderstorm"
69+
case .mist, .fog:
70+
"Cloudy with Fog"
71+
}
72+
}
2373
}

DatWeatherDoe/UI/Decorator/Condition/WeatherConditionImageMapper.swift

Lines changed: 0 additions & 68 deletions
This file was deleted.

DatWeatherDoe/UI/Status Bar/StatusBarView.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ struct StatusBarView: View {
1616
switch weatherResult {
1717
case let .success(success):
1818
HStack {
19-
if success.showWeatherIcon,
20-
let image = WeatherConditionImageMapper().map(success.weatherCondition)
21-
{
22-
Image(nsImage: image)
19+
if success.showWeatherIcon {
20+
Image(systemName: success.weatherCondition.symbolName)
2321
.renderingMode(.template)
24-
.accessibilityLabel(WeatherConditionTextMapper().map(success.weatherCondition))
22+
.accessibilityLabel(success.weatherCondition.accessibilityLabel)
2523
}
2624
if let text = success.textualRepresentation {
2725
Text(text)

DatWeatherDoe/ViewModel/WeatherViewModel.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ final class WeatherViewModel: WeatherViewModelType, ObservableObject {
9999

100100
private func getWeatherWithSelectedSource() {
101101
let weatherSource = WeatherSource(rawValue: configManager.weatherSource) ?? .location
102-
103102
switch weatherSource {
104103
case .location:
105104
getWeatherAfterUpdatingLocation()

0 commit comments

Comments
 (0)