Skip to content

Commit

Permalink
Merge pull request #55 from 3rob3/Weather-fixes,-warning-fixes
Browse files Browse the repository at this point in the history
Weather fixes/changes
  • Loading branch information
JW-CH authored Apr 17, 2024
2 parents 81384ec + aa9fa01 commit 0978dcd
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
17 changes: 9 additions & 8 deletions ImmichFrame/Helpers/WeatherHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ImmichFrame.Models;
using Microsoft.Extensions.Options;
using OpenWeatherMap;
using OpenWeatherMap.Models;
using System.Threading.Tasks;
Expand All @@ -7,18 +8,18 @@ namespace ImmichFrame.Helpers
{
public class WeatherHelper
{
private static readonly OpenWeatherMapOptions Options = new OpenWeatherMapOptions
{
ApiKey = Settings.CurrentSettings.WeatherApiKey,
UnitSystem = Settings.CurrentSettings.UnitSystem,
Language = Settings.CurrentSettings.Language,
};
public static Task<WeatherInfo?> GetWeather()
{
var settings = Settings.CurrentSettings;
return GetWeather(settings.WeatherLat, settings.WeatherLong);
OpenWeatherMapOptions options = new OpenWeatherMapOptions
{
ApiKey = Settings.CurrentSettings.WeatherApiKey,
UnitSystem = Settings.CurrentSettings.UnitSystem,
Language = Settings.CurrentSettings.Language,
};
return GetWeather(settings.WeatherLat, settings.WeatherLong, options);
}
public static async Task<WeatherInfo?> GetWeather(double latitude, double longitude)
public static async Task<WeatherInfo?> GetWeather(double latitude, double longitude, OpenWeatherMapOptions Options)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion ImmichFrame/Models/AssetResponseDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private async Task<Stream> ServeImage()
var localDir = Path.GetDirectoryName(localPath);
if (!Directory.Exists(localDir))
{
Directory.CreateDirectory(localDir);
Directory.CreateDirectory(localDir!);
}

if (File.Exists(localPath))
Expand Down
8 changes: 4 additions & 4 deletions ImmichFrame/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private static Settings ParseSettings(Dictionary<string, object> SettingsValues)
switch (SettingsValue.Key)
{
case "ImmichServerUrl":
var url = value.ToString().TrimEnd('/');
var url = value.ToString()!.TrimEnd('/');
// Match URL or IP
if (!Regex.IsMatch(url, @"^(https?:\/\/)?(([a-zA-Z0-9\.\-_]+(\.[a-zA-Z]{2,})+)|(\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b))(\:\d{1,5})?$"))
throw new SettingsNotValidException($"Value of '{SettingsValue.Key}' is not valid. (' {value} ')");
Expand Down Expand Up @@ -263,14 +263,14 @@ private static Settings ParseSettings(Dictionary<string, object> SettingsValues)
property.SetValue(settings, value);
break;
case "UnitSystem":
if (!Regex.IsMatch(value.ToString(), @"^(?i)(metric|imperial)$"))
if (!Regex.IsMatch(value.ToString()!, @"^(?i)(metric|imperial)$"))
throw new SettingsNotValidException($"Value of '{SettingsValue.Key}' is not valid. ('{value}')");
value = value.ToString().ToLower() == "metric" ? OpenWeatherMap.UnitSystem.Metric : OpenWeatherMap.UnitSystem.Imperial;
value = value.ToString()!.ToLower() == "metric" ? OpenWeatherMap.UnitSystem.Metric : OpenWeatherMap.UnitSystem.Imperial;
property.SetValue(settings, value);
break;
case "WeatherLatLong":
// Regex match Lat/Lon
if (!Regex.IsMatch(value.ToString(), @"^(-?\d+(\.\d+)?),\s*(-?\d+(\.\d+)?)$"))
if (!Regex.IsMatch(value.ToString()!, @"^(-?\d+(\.\d+)?),\s*(-?\d+(\.\d+)?)$"))
throw new SettingsNotValidException($"Value of '{SettingsValue.Key}' is not valid. ('{value}')");
property.SetValue(settings, value);
break;
Expand Down
4 changes: 2 additions & 2 deletions ImmichFrame/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void AddPersonAction()

public void RemovePersonAction(object param)
{
var item = PeopleList.First(x => x.Id == Guid.Parse(param.ToString()));
var item = PeopleList.First(x => x.Id == Guid.Parse(param.ToString()!));
PeopleList?.Remove(item);
}

Expand All @@ -67,7 +67,7 @@ public void AddAlbumAction()

public void RemoveAlbumAction(object param)
{
var item = AlbumList.First(x => x.Id == Guid.Parse(param.ToString()));
var item = AlbumList.First(x => x.Id == Guid.Parse(param.ToString()!));
AlbumList?.Remove(item);
}

Expand Down
2 changes: 1 addition & 1 deletion ImmichFrame/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void btnSettings_Click(object? sender, RoutedEventArgs args)
if (!Settings.IsFromXmlFile)
{
ExitView();
((NavigatableViewModelBase)this.DataContext).Navigate(new SettingsViewModel());
((NavigatableViewModelBase)this.DataContext!).Navigate(new SettingsViewModel());
}
}

Expand Down
4 changes: 0 additions & 4 deletions ImmichFrame/Views/SettingsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@
<TextBlock Text="ImageDescFontSize"/>
<TextBox Text="{Binding Settings.ImageDescFontSize}"/>
</StackPanel>
<StackPanel>
<TextBlock Text="ShowWeather"/>
<CheckBox IsChecked="{Binding Settings.ShowWeather}"/>
</StackPanel>
<StackPanel>
<TextBlock Text="WeatherFontSize"/>
<TextBox Text="{Binding Settings.WeatherFontSize}"/>
Expand Down

0 comments on commit 0978dcd

Please sign in to comment.