diff --git a/pg.DarkSky.Wpf/App.xaml.cs b/pg.DarkSky.Wpf/App.xaml.cs index 227c689..409cae6 100644 --- a/pg.DarkSky.Wpf/App.xaml.cs +++ b/pg.DarkSky.Wpf/App.xaml.cs @@ -12,6 +12,7 @@ public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { + //ha a verziószámok változnának, akkor ez segít a korábbi beállításokat áthozni a legújabb properties állományba Settings.Default.Upgrade(); CultureInfo.DefaultThreadCurrentCulture = diff --git a/pg.DarkSky.Wpf/Helpers/ExtendedBinding.cs b/pg.DarkSky.Wpf/Helpers/ExtendedBinding.cs new file mode 100644 index 0000000..5878b8e --- /dev/null +++ b/pg.DarkSky.Wpf/Helpers/ExtendedBinding.cs @@ -0,0 +1,63 @@ +using System; +using System.Windows; +using System.Windows.Data; + +namespace pg.DarkSky.Wpf.Helpers +{ + /// + /// Segít az ikonok megjelenítésében, hogy ne kelljen DependencyProperty-t implementálni + /// + /// Loptam: https://www.codeproject.com/Articles/71348/Binding-on-a-Property-which-is-not-a-DependencyPro + /// + public class ExtendedBinding : FrameworkElement + { + #region Source DP + //We don't know what will be the Source/target type so we keep 'object'. + public static readonly DependencyProperty SourceProperty = + DependencyProperty.Register("Source", typeof(object), typeof(ExtendedBinding), + new FrameworkPropertyMetadata() + { + BindsTwoWayByDefault = true, + DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, + }); + public Object Source + { + get { return GetValue(ExtendedBinding.SourceProperty); } + set { SetValue(ExtendedBinding.SourceProperty, value); } + } + #endregion + + #region Target DP + //We don't know what will be the Source/target type so we keep 'object'. + public static readonly DependencyProperty TargetProperty = + DependencyProperty.Register("Target", typeof(object), typeof(ExtendedBinding), + new FrameworkPropertyMetadata() + { + BindsTwoWayByDefault = true, + DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, + }); + public Object Target + { + get { return GetValue(ExtendedBinding.TargetProperty); } + set { SetValue(ExtendedBinding.TargetProperty, value); } + } + #endregion + + protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) + { + base.OnPropertyChanged(e); + if (e.Property.Name == ExtendedBinding.SourceProperty.Name) + { + //no loop wanted + if (!object.ReferenceEquals(Source, Target)) + Target = Source; + } + else if (e.Property.Name == ExtendedBinding.TargetProperty.Name) + { + //no loop wanted + if (!object.ReferenceEquals(Source, Target)) + Source = Target; + } + } + } +} diff --git a/pg.DarkSky.Wpf/Helpers/IconHelpers.cs b/pg.DarkSky.Wpf/Helpers/IconHelpers.cs new file mode 100644 index 0000000..cc0d110 --- /dev/null +++ b/pg.DarkSky.Wpf/Helpers/IconHelpers.cs @@ -0,0 +1,113 @@ +using MahApps.Metro.IconPacks; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace pg.DarkSky.Wpf.Helpers +{ + public static class IconHelpers + { + /// + /// A SkyCons icon azonosítókat átforgatjuk mahapps.Icon.wehater azonosítókká + /// + /// + /// + public static PackIconWeatherIconsKind IconToWeatherIcon(this string icon) + { + switch (icon) + { + case "clear-day": + return PackIconWeatherIconsKind.DaySunny; + case "clear-night": + return PackIconWeatherIconsKind.NightClear; + case "partly-cloudy-day": + return PackIconWeatherIconsKind.DayCloudy; + case "partly-cloudy-night": + return PackIconWeatherIconsKind.NightCloudy; + case "cloudy": + return PackIconWeatherIconsKind.Cloudy; + case "rain": + return PackIconWeatherIconsKind.Rain; + case "sleet": + return PackIconWeatherIconsKind.Sleet; + case "snow": + return PackIconWeatherIconsKind.Snow; + case "wind": + return PackIconWeatherIconsKind.StrongWind; + case "fog": + return PackIconWeatherIconsKind.Fog; + default: + return PackIconWeatherIconsKind.Na; + } + } + + /// + /// Átalakítja a szélsebességet, ami m/s-ban jön (SI) Beaufort skálává + /// https://hu.wikipedia.org/wiki/Beaufort-sk%C3%A1la + /// + /// todo: a wikipédia alapján a szél jellemzőit meg lehetne tooltip-ben jeleníteni + /// + /// + /// + public static PackIconWeatherIconsKind WindSpeedToBeaufortIcon(this double windspeed) + { + if (windspeed <= 0.3d) + { + return PackIconWeatherIconsKind.WindBeaufort0; + } + if (windspeed <= 1.7d) + { + return PackIconWeatherIconsKind.WindBeaufort1; + } + if (windspeed <= 3.1d) + { + return PackIconWeatherIconsKind.WindBeaufort2; + } + if (windspeed <= 5.3d) + { + return PackIconWeatherIconsKind.WindBeaufort3; + } + if (windspeed <= 8.1d) + { + return PackIconWeatherIconsKind.WindBeaufort4; + } + if (windspeed <= 10.9d) + { + return PackIconWeatherIconsKind.WindBeaufort5; + } + if (windspeed <= 13.3d) + { + return PackIconWeatherIconsKind.WindBeaufort6; + } + if (windspeed <= 16.9d) + { + return PackIconWeatherIconsKind.WindBeaufort7; + } + if (windspeed <= 20.0d) + { + return PackIconWeatherIconsKind.WindBeaufort8; + } + if (windspeed <= 23.7d) + { + return PackIconWeatherIconsKind.WindBeaufort9; + } + if (windspeed <= 27.9d) + { + return PackIconWeatherIconsKind.WindBeaufort10; + } + if (windspeed <= 31.9d) + { + return PackIconWeatherIconsKind.WindBeaufort11; + } + if (windspeed <= 33.3d) + { + return PackIconWeatherIconsKind.WindBeaufort12; + } + + //ha kifutottunk a skálából, jelezzük az érvénytelen értéket + return PackIconWeatherIconsKind.Na; + } + } +} diff --git a/pg.DarkSky.Wpf/Helpers/LanguageHelpers.cs b/pg.DarkSky.Wpf/Helpers/LanguageHelpers.cs index 4372dd9..c68f719 100644 --- a/pg.DarkSky.Wpf/Helpers/LanguageHelpers.cs +++ b/pg.DarkSky.Wpf/Helpers/LanguageHelpers.cs @@ -1,11 +1,10 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace pg.DarkSky.Wpf.Helpers { + /// + /// A lokalizáció neve és az API language code között konvertál oda/vissza. + /// public static class LanguageHelpers { /// diff --git a/pg.DarkSky.Wpf/MainWindow.xaml b/pg.DarkSky.Wpf/MainWindow.xaml index 62be5d4..4eca34b 100644 --- a/pg.DarkSky.Wpf/MainWindow.xaml +++ b/pg.DarkSky.Wpf/MainWindow.xaml @@ -1,15 +1,16 @@  + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:local="clr-namespace:pg.DarkSky.Wpf" + xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" + xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" + xmlns:vm="clr-namespace:pg.DarkSky.Wpf.ViewModels" + xmlns:helpers="clr-namespace:pg.DarkSky.Wpf.Helpers" + mc:Ignorable="d" + DataContext="{x:Static vm:ViewModelLocator.MainViewModel }" + Title="pg.DarkSky" Height="450" Width="800"> @@ -45,25 +46,57 @@ Command="{Binding RefreshDataCommand}" /> + Visibility="{Binding HasSuccess, Converter={StaticResource VisibleIfTrueConverter} }" + IsEnabled="{Binding IsNotBusy}"> + + + - - + + + + + + + + + + + + + + + + + + + + + /// Ez alapján: https://www.met.hu/idojaras/humanmeteorologia/uv-b/ismerteto/ + /// + /// todo: a weboldalon meglévő szöveg alapján lehetne többet mondani az adott értékről + /// + public SolidColorBrush UvIndexBackgroundColor + { + get + { + if (UvIndex<=2.9d) + { + return new SolidColorBrush(Colors.DeepSkyBlue); + } + + if (UvIndex <= 4.9d) + { + return new SolidColorBrush(Colors.Green); + } + if (UvIndex <= 6.9d) + { + return new SolidColorBrush(Colors.Yellow); + } + if (UvIndex <= 7.9d) + { + return new SolidColorBrush(Colors.Orange); //ez a weboldalon #FFC400 + } + + return new SolidColorBrush(Colors.Red); + } + } + + + } } diff --git a/pg.DarkSky.Wpf/ViewModels/MainViewModel.cs b/pg.DarkSky.Wpf/ViewModels/MainViewModel.cs index 15381cc..f00718a 100644 --- a/pg.DarkSky.Wpf/ViewModels/MainViewModel.cs +++ b/pg.DarkSky.Wpf/ViewModels/MainViewModel.cs @@ -51,7 +51,19 @@ public MainViewModel(ForecastRepository forecastRepository, IMapper mapper, ILog public bool HasSuccess { get { return _hasSuccess; } set { SetProperty(value, ref _hasSuccess); } } private bool _isBusy; - public bool IsBusy { get { return _isBusy; } set { SetProperty(value, ref _isBusy); } } + public bool IsBusy + { + get { return _isBusy; } + set + { + if (SetProperty(value, ref _isBusy)) + { + OnPropertyChanged(nameof(IsNotBusy)); + } + } + } + + public bool IsNotBusy { get { return !IsBusy; } } public bool IsWorking { diff --git a/pg.DarkSky.Wpf/ViewModels/ViewModelBase.cs b/pg.DarkSky.Wpf/ViewModels/ViewModelBase.cs index 92fcb9d..2334f6a 100644 --- a/pg.DarkSky.Wpf/ViewModels/ViewModelBase.cs +++ b/pg.DarkSky.Wpf/ViewModels/ViewModelBase.cs @@ -17,13 +17,26 @@ protected void OnPropertyChanged(string propertyName) PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } - protected virtual void SetProperty(T value, ref T backingField, [CallerMemberName]string propertyName = null) + /// + /// Az INotifyPropertyChanged alap implementáció. + /// Kap egy értéket, és ellenőrzi, hogy ez a property jelenlegi értékéhez képest változást jelent-e? + /// Ha igen, akkor módosítja a mezőt, ami a property értékóét tárolja, + /// és dob egy PropertyChanged eseményt a property nevével + /// + /// + /// az új érték, amire a property értékét változtatni szeretnénk. + /// a property mögötti mező, amit módosítani kell, ha változik a property + /// a property, amit változtatunk. Ha nem adjuk meg, akkor a hívó eljárás nevét használja + /// igaz, ha változott, a property értéke, hamis, ha az új érték ugyanaz, mint a régi + protected virtual bool SetProperty(T value, ref T backingField, [CallerMemberName]string propertyName = null) { - if (EqualityComparer.Default.Equals(backingField, value)) { return; } + if (EqualityComparer.Default.Equals(backingField, value)) { return false; } backingField = value; OnPropertyChanged(propertyName); + + return true; } } diff --git a/pg.DarkSky.Wpf/pg.DarkSky.Wpf.csproj b/pg.DarkSky.Wpf/pg.DarkSky.Wpf.csproj index 76c66ef..879f1fd 100644 --- a/pg.DarkSky.Wpf/pg.DarkSky.Wpf.csproj +++ b/pg.DarkSky.Wpf/pg.DarkSky.Wpf.csproj @@ -55,7 +55,9 @@ MSBuild:Compile Designer + + @@ -137,6 +139,9 @@ 3.0.0-alpha0096 + + 3.0.0-alpha0096 + 2.7.2-dev-01033