-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ea4d59
commit a82de62
Showing
28 changed files
with
745 additions
and
227 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
Samples/Nalu.Maui.Weather/Converters/WeatherCodeToImageConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace Nalu.Maui.Weather.Converters; | ||
|
||
using System; | ||
using System.Globalization; | ||
using Microsoft.Maui.Controls; | ||
|
||
public class WeatherCodeToImageConverter : IValueConverter | ||
{ | ||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
{ | ||
if (value is int weatherCode && WeatherData.WeatherCodes.TryGetValue(weatherCode, out var weatherInfo)) | ||
{ | ||
return weatherInfo.Image; | ||
} | ||
|
||
return WeatherData.WeatherCodes[0].Image; // Default to clear sky | ||
} | ||
|
||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
=> throw new NotImplementedException(); // One-way binding, no need for ConvertBack | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Nalu.Maui.Weather.Models; | ||
|
||
public class DailyWeatherModel | ||
{ | ||
public DateTime Time { get; set; } | ||
public float WindSpeed { get; set; } | ||
public float WindDirection { get; set; } | ||
public float TemperatureMin { get; set; } | ||
public float TemperatureMax { get; set; } | ||
public float RainSum { get; set; } | ||
public int WeatherCode { get; set; } | ||
public string DayName => Time.ToString("dddd"); | ||
public string Date => Time.ToString("M"); | ||
public string TemperatureMinDegrees => $"{TemperatureMin:N0}°"; | ||
public string TemperatureMaxDegrees => $"{TemperatureMax:N0}°"; | ||
public string RainSumMm => $"{RainSum:N1}mm"; | ||
public string WindSpeedKmh => $"{WindSpeed:N0}km/h {WindDirection}°"; | ||
} |
122 changes: 122 additions & 0 deletions
122
Samples/Nalu.Maui.Weather/Models/HourlyAirQualityModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
namespace Nalu.Maui.Weather.Models; | ||
|
||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using Resources; | ||
|
||
public class HourlyAirQualityModel | ||
{ | ||
public required DateTime Time { get; set; } | ||
public required float? Pm25 { get; set; } | ||
public required float? Pm10 { get; set; } | ||
public required float? O3 { get; set; } | ||
public required float? Co { get; set; } | ||
|
||
public string Icon | ||
{ | ||
get | ||
{ | ||
if (Pm25 is > 50 || Pm10 is > 50 || Co is > 1000) | ||
{ | ||
return "\ue99a"; | ||
} | ||
|
||
if (Pm25 is > 25 || Pm10 is > 25 || Co is > 600) | ||
{ | ||
return "\uf083"; | ||
} | ||
|
||
return "\ue1d5"; | ||
} | ||
} | ||
|
||
public Color IconColor | ||
{ | ||
get | ||
{ | ||
if (Pm25 is > 50 || Pm10 is > 50 || Co is > 1000) | ||
{ | ||
return Colors.Red; | ||
} | ||
|
||
if (Pm25 is > 25 || Pm10 is > 25 || Co is > 600) | ||
{ | ||
return Colors.Orange; | ||
} | ||
|
||
return Colors.Green; | ||
} | ||
} | ||
|
||
public string DangerousUnit | ||
{ | ||
get | ||
{ | ||
var pm25Danger = Pm25.HasValue ? Pm25.Value / 50 : 0; | ||
var pm10Danger = Pm10.HasValue ? Pm10.Value / 50 : 0; | ||
var o3Danger = O3.HasValue ? O3.Value / 180 : 0; | ||
var coDanger = Co.HasValue ? Co.Value / 1000 : 0; | ||
|
||
var maxDanger = new[] { pm25Danger, pm10Danger, o3Danger, coDanger }.Max(); | ||
|
||
if (maxDanger == pm25Danger) | ||
{ | ||
return Texts.PM25; | ||
} | ||
|
||
if (maxDanger == pm10Danger) | ||
{ | ||
return Texts.PM10; | ||
} | ||
|
||
return maxDanger == o3Danger ? "O3" : "CO"; | ||
} | ||
} | ||
|
||
public string DangerousValue | ||
{ | ||
get | ||
{ | ||
var dangerousUnit = DangerousUnit; | ||
if (dangerousUnit == Texts.PM25) | ||
{ | ||
return Pm25Value; | ||
} | ||
|
||
if (dangerousUnit == Texts.PM10) | ||
{ | ||
return Pm10Value; | ||
} | ||
|
||
if (dangerousUnit == "O3") | ||
{ | ||
return O3Value; | ||
} | ||
|
||
return CoValue; | ||
} | ||
} | ||
|
||
public string DangerousLevel | ||
{ | ||
get | ||
{ | ||
if (Pm25 is > 50 || Pm10 is > 50 || Co is > 1000) | ||
{ | ||
return "Dangerous"; | ||
} | ||
|
||
if (Pm25 is > 25 || Pm10 is > 25 || Co is > 600) | ||
{ | ||
return "Unhealthy"; | ||
} | ||
|
||
return "Good"; | ||
} | ||
} | ||
|
||
public string Hour => Time.ToString("HH:mm"); | ||
public string Pm25Value => $"{Pm25 ?? 0:N0} μg/m³"; | ||
public string Pm10Value => $"{Pm10 ?? 0:N0} μg/m³"; | ||
public string O3Value => $"{O3 ?? 0:N0} μg/m³"; | ||
public string CoValue => $"{Co ?? 0:N1} mg/m³"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.