Skip to content

Commit

Permalink
#3. #11: megjelenítünk egyelőre mindent favágó módon az aktuális érté…
Browse files Browse the repository at this point in the history
…kekből
  • Loading branch information
gplesz committed Dec 28, 2018
1 parent 4a3e924 commit e1d9b81
Show file tree
Hide file tree
Showing 9 changed files with 402 additions and 27 deletions.
1 change: 1 addition & 0 deletions pg.DarkSky.Wpf/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
63 changes: 63 additions & 0 deletions pg.DarkSky.Wpf/Helpers/ExtendedBinding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Windows;
using System.Windows.Data;

namespace pg.DarkSky.Wpf.Helpers
{
/// <summary>
/// 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
/// </summary>
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;
}
}
}
}
113 changes: 113 additions & 0 deletions pg.DarkSky.Wpf/Helpers/IconHelpers.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// A SkyCons icon azonosítókat átforgatjuk mahapps.Icon.wehater azonosítókká
/// </summary>
/// <param name="icon"></param>
/// <returns></returns>
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;
}
}

/// <summary>
/// Á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
/// </summary>
/// <param name="windspeed"></param>
/// <returns></returns>
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;
}
}
}
7 changes: 3 additions & 4 deletions pg.DarkSky.Wpf/Helpers/LanguageHelpers.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// A lokalizáció neve és az API language code között konvertál oda/vissza.
/// </summary>
public static class LanguageHelpers
{
/// <summary>
Expand Down
61 changes: 47 additions & 14 deletions pg.DarkSky.Wpf/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<Controls:MetroWindow x:Class="pg.DarkSky.Wpf.MainWindow"
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"
mc:Ignorable="d"
DataContext="{x:Static vm:ViewModelLocator.MainViewModel }"
Title="pg.DarkSky" Height="450" Width="800">
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">
<Window.Resources>
<BooleanToVisibilityConverter x:Key="VisibleIfTrueConverter" />
</Window.Resources>
Expand Down Expand Up @@ -45,25 +46,57 @@
Command="{Binding RefreshDataCommand}" />
</Grid>
<Grid Grid.Row="1"
Visibility="{Binding HasSuccess, Converter={StaticResource VisibleIfTrueConverter} }">
Visibility="{Binding HasSuccess, Converter={StaticResource VisibleIfTrueConverter} }"
IsEnabled="{Binding IsNotBusy}">
<Grid.Resources>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedSingleRowTabControl.xaml" />
</Grid.Resources>
<TabControl>
<TabItem Header="{DynamicResource MainWindow.Current}"
ToolTip="{DynamicResource MainWindow.Current.Tooltip}">
<StackPanel>
<TextBlock Text="{Binding Current.Summary}" />
<TextBlock Text="{Binding Current.Icon}" />
<iconPacks:PackIconWeatherIcons x:Name="SummaryIcon"
Width="32" Height="32"
ToolTip="{Binding Current.Summary}"/>
<iconPacks:PackIconWeatherIcons x:Name="WindspeedIcon" Width="32" Height="32"
ToolTip="{Binding Current.WindSpeedText}"/>
<helpers:ExtendedBinding Source="{Binding Current.WeatherIcon, Mode=TwoWay}"
Target="{Binding ElementName=SummaryIcon,Path=Kind,Mode=TwoWay}"/>
<helpers:ExtendedBinding Source="{Binding Current.WindspeedIcon, Mode=TwoWay}"
Target="{Binding ElementName=WindspeedIcon,Path=Kind,Mode=TwoWay}"/>

<TextBlock Text="{Binding Current.AtmosphericPressureText}" />
<TextBlock Text="{Binding Current.HumidityText}" />

<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Current.Temperature}" />
<iconPacks:PackIconWeatherIcons Kind="Celsius"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Current.ApparentTemperature}" />
<iconPacks:PackIconWeatherIcons Kind="Celsius"/>
</StackPanel>

<TextBlock Text="{Binding Current.UvIndex}"
Background="{Binding Current.UvIndexBackgroundColor}"/>
</StackPanel>
</TabItem>
<TabItem Header="{DynamicResource MainWindow.Forecast}"
ToolTip="{DynamicResource MainWindow.Forecast.Tooltip}" >
</TabItem>
</TabControl>

</Grid>
<Controls:ProgressRing Grid.Row="1"
IsActive="{Binding IsBusy}"
IsLarge="True"
Visibility="{Binding IsBusy, Converter={StaticResource VisibleIfTrueConverter} }"/>
<StatusBar Grid.Row="2"
Visibility="{Binding HasSuccess, Converter={StaticResource VisibleIfTrueConverter} }">
<Grid>
<ProgressBar Grid.Column="0"
Width="100" Height="15"
Maximum="1000"
ToolTip="{DynamicResource MainWindow.ForecastApiCalls}"
Value="{Binding ForecastApiCalls}" />
<TextBlock Text="{Binding ForecastApiCalls}"
Expand Down
Loading

0 comments on commit e1d9b81

Please sign in to comment.