From f5f81d8e8bf6486e497d652e362b5da972e583da Mon Sep 17 00:00:00 2001 From: Betta_Fish Date: Sat, 30 Nov 2024 23:32:49 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E6=94=AF=E6=8C=81=20AQI=20=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E6=98=BE=E7=A4=BA=20#70?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Mappers/AirConditionMapper.cs | 12 +++++++- .../ValueConverters/ConverterMethods.cs | 14 ++++++++- FluentWeather.Uwp/Pages/MainPage.xaml | 29 ++++++++++++++----- .../ViewModels/RootPageViewModel.cs | 2 +- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/FluentWeather.OpenMeteoProvider/Mappers/AirConditionMapper.cs b/FluentWeather.OpenMeteoProvider/Mappers/AirConditionMapper.cs index 9ac77d8..97e58aa 100644 --- a/FluentWeather.OpenMeteoProvider/Mappers/AirConditionMapper.cs +++ b/FluentWeather.OpenMeteoProvider/Mappers/AirConditionMapper.cs @@ -8,7 +8,7 @@ public static class AirConditionMapper { public static OpenMeteoAirCondition MapToOpenMeteoWeatherNow(this AirQualityItem item) { - return new OpenMeteoAirCondition + var airCondition = new OpenMeteoAirCondition { CO = Math.Round((double)item.CarbonMonoxide!,2), NO2 = Math.Round((double)item.CarbonMonoxide!,2), @@ -18,6 +18,16 @@ public static OpenMeteoAirCondition MapToOpenMeteoWeatherNow(this AirQualityItem SO2 = Math.Round((double)item.SulphurDioxide!, 2), O3 = Math.Round((double)item.Ozone!, 2), }; + airCondition.AqiLevel = airCondition.Aqi switch + { + <= 50 => 0, + <= 100 => 1, + <= 150 => 2, + <= 200 => 3, + <= 300 => 4, + _ => 5, + }; + return airCondition; } } \ No newline at end of file diff --git a/FluentWeather.Uwp.Shared/Helpers/ValueConverters/ConverterMethods.cs b/FluentWeather.Uwp.Shared/Helpers/ValueConverters/ConverterMethods.cs index 4172183..7ae77ba 100644 --- a/FluentWeather.Uwp.Shared/Helpers/ValueConverters/ConverterMethods.cs +++ b/FluentWeather.Uwp.Shared/Helpers/ValueConverters/ConverterMethods.cs @@ -36,7 +36,19 @@ public static Brush SeverityColorToColor(SeverityColor? color) _ => new SolidColorBrush(Colors.Red) }; } - + public static Brush AqiLevelToColor(int? level) + { + return level switch + { + 0 => new SolidColorBrush(Colors.LawnGreen), + 1 => new SolidColorBrush(Colors.Yellow), + 2 => new SolidColorBrush(Colors.Orange), + 3 => new SolidColorBrush(Colors.Red), + 4 => new SolidColorBrush(Colors.Purple), + 5 => new SolidColorBrush(Colors.DarkRed), + _ => new SolidColorBrush(Colors.Transparent) + }; + } /// /// 根据应用设置自动转换温度 /// 此转换仅在UI层进行 diff --git a/FluentWeather.Uwp/Pages/MainPage.xaml b/FluentWeather.Uwp/Pages/MainPage.xaml index 72135a3..324adfe 100644 --- a/FluentWeather.Uwp/Pages/MainPage.xaml +++ b/FluentWeather.Uwp/Pages/MainPage.xaml @@ -66,7 +66,7 @@ Duration="0:0:0.8" /> - + - + @@ -158,8 +158,9 @@ - @@ -227,11 +228,18 @@ BorderBrush="Transparent" Visibility="{x:Bind ViewModel.AirCondition, Converter={StaticResource NullToVisibilityConverter}}"> + + - - + + - + - + diff --git a/FluentWeather.Uwp/ViewModels/RootPageViewModel.cs b/FluentWeather.Uwp/ViewModels/RootPageViewModel.cs index bbdacca..34d2b32 100644 --- a/FluentWeather.Uwp/ViewModels/RootPageViewModel.cs +++ b/FluentWeather.Uwp/ViewModels/RootPageViewModel.cs @@ -6,7 +6,7 @@ namespace FluentWeather.Uwp.ViewModels; public sealed partial class RootPageViewModel:ObservableObject { [ObservableProperty] - private partial bool IsPaneOpen { get; set; } + public partial bool IsPaneOpen { get; set; } [RelayCommand] private void TogglePane()