Skip to content

Commit

Permalink
Merge pull request #15 from Khiro95/dev
Browse files Browse the repository at this point in the history
Update to v3.1
  • Loading branch information
Khiro95 committed May 19, 2024
2 parents a9ad308 + 9ad69ec commit 617662c
Show file tree
Hide file tree
Showing 122 changed files with 4,742 additions and 367 deletions.
990 changes: 990 additions & 0 deletions AwqatSalaat.Common/Assets/countries.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions AwqatSalaat.Common/AwqatSalaat.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
<RootNamespace>AwqatSalaat</RootNamespace>
</PropertyGroup>

<ItemGroup>
<None Remove="Assets\countries.json" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Assets\countries.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down
17 changes: 17 additions & 0 deletions AwqatSalaat.Common/Data/Country.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Newtonsoft.Json;

namespace AwqatSalaat.Data
{
public class Country
{
public string Name { get; }
public string Code { get; }

[JsonConstructor]
private Country(string name, string code)
{
Name = name;
Code = code;
}
}
}
9 changes: 9 additions & 0 deletions AwqatSalaat.Common/Data/LocationDetectionMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace AwqatSalaat.Data
{
public enum LocationDetectionMode
{
ByCountryCode,
ByCoordinates,
ByQuery
}
}
8 changes: 8 additions & 0 deletions AwqatSalaat.Common/Data/School.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace AwqatSalaat.Data
{
public enum School
{
Standard = 0,
Hanafi = 1,
}
}
38 changes: 38 additions & 0 deletions AwqatSalaat.Common/Helpers/CountriesProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using AwqatSalaat.Data;
using Newtonsoft.Json;
using System.IO;

namespace AwqatSalaat.Helpers
{
public static class CountriesProvider
{
private static Country[] s_countries;

public static Country[] GetCountries()
{
if (s_countries is null)
{
var asm = typeof(CountriesProvider).Assembly;
using (Stream stream = asm.GetManifestResourceStream("AwqatSalaat.Assets.countries.json"))
{
s_countries = DeserializeFromStream<Country[]>(stream);
}
}

return s_countries;
}

private static T DeserializeFromStream<T>(Stream stream)
{
var serializer = new JsonSerializer();

using (var reader = new StreamReader(stream))
{
using (var jsonTextReader = new JsonTextReader(reader))
{
return serializer.Deserialize<T>(jsonTextReader);
}
}
}
}
}
10 changes: 7 additions & 3 deletions AwqatSalaat.Common/Helpers/LocaleManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;

namespace AwqatSalaat.Helpers
Expand All @@ -15,6 +16,7 @@ public class LocaleManager : INotifyPropertyChanged
private string _current;

public string Current { get => _current; set => SetLocale(value); }
public CultureInfo CurrentCulture { get; private set; }

public event EventHandler CurrentChanged;
public event PropertyChangedEventHandler PropertyChanged;
Expand All @@ -25,7 +27,7 @@ private LocaleManager()

if (string.IsNullOrEmpty(lang))
{
lang = System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
lang = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
}

SetLocale(lang);
Expand Down Expand Up @@ -61,11 +63,13 @@ private void SetLocale(string locale)
locale = "en";
}

string previous = _current;
_current = locale;
Properties.Resources.Culture = new System.Globalization.CultureInfo(locale);
CurrentCulture = new CultureInfo(locale);
Properties.Resources.Culture = CurrentCulture;
Properties.Settings.Default.DisplayLanguage = locale;

PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Current)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentCulture)));
CurrentChanged?.Invoke(this, EventArgs.Empty);
}
}
Expand Down
5 changes: 4 additions & 1 deletion AwqatSalaat.Common/Helpers/ObservableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
}
}

protected void SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
if (!Equals(field, value))
{
field = value;
OnPropertyChanged(propertyName);
return true;
}

return false;
}
}
}
16 changes: 15 additions & 1 deletion AwqatSalaat.Common/Helpers/RelayCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Windows.Input;

namespace AwqatSalaat.Helpers
Expand All @@ -14,6 +15,7 @@ public class RelayCommand : ICommand
{
private readonly Action<object> _execute;
private readonly Predicate<object> _canExecute;
private readonly SynchronizationContext _syncContext;
/// <summary>
/// Raised when RaiseCanExecuteChanged is called.
/// </summary>
Expand All @@ -35,6 +37,7 @@ public RelayCommand(Action<object> execute, Predicate<object> canExecute)
{
_execute = execute ?? throw new ArgumentNullException("execute");
_canExecute = canExecute;
_syncContext = SynchronizationContext.Current;
}
/// <summary>
/// Determines whether this RelayCommand can execute in its current state.
Expand Down Expand Up @@ -66,7 +69,18 @@ public void Execute(object parameter)
/// </summary>
public void RaiseCanExecuteChanged()
{
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
if (_syncContext is null)
{
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
else
{
_syncContext.Post(arg =>
{
var _this = (RelayCommand)arg;
_this.CanExecuteChanged?.Invoke(_this, EventArgs.Empty);
}, this);
}
}
}
}
2 changes: 1 addition & 1 deletion AwqatSalaat.Common/Helpers/SystemInfos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static bool IsTaskBarCentered()
{
if (key != null)
{
int value = Convert.ToInt32(key.GetValue("TaskbarAl", 0));
int value = Convert.ToInt32(key.GetValue("TaskbarAl", 1));
return value == 1;
}

Expand Down
47 changes: 47 additions & 0 deletions AwqatSalaat.Common/Helpers/TimeZoneHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using TimeZoneConverter;

namespace AwqatSalaat.Helpers
{
internal static class TimeZoneHelper
{
private static readonly Dictionary<string, TimeZoneInfo> tzInfoCache = new Dictionary<string, TimeZoneInfo>();

public static string GetIanaTimeZone()
{
var id = TimeZoneInfo.Local.Id;

if (TZConvert.TryWindowsToIana(id, out string ianaTimeZone))
{
return ianaTimeZone;
}

return null;
}

public static DateTime ConvertDateTimeToLocal(DateTime dateTime, string ianaTimeZone)
{
TimeZoneInfo timeZoneInfo = null;

if (!string.IsNullOrEmpty(ianaTimeZone) && !tzInfoCache.TryGetValue(ianaTimeZone, out timeZoneInfo))
{
if (TZConvert.TryIanaToWindows(ianaTimeZone, out string timeZoneId))
{
timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);

tzInfoCache[ianaTimeZone] = timeZoneInfo;
}
}

if (timeZoneInfo is null || timeZoneInfo.BaseUtcOffset == TimeZoneInfo.Local.BaseUtcOffset)
{
return dateTime;
}

dateTime = TimeZoneInfo.ConvertTimeToUtc(dateTime, timeZoneInfo);

return TimeZoneInfo.ConvertTimeFromUtc(dateTime, TimeZoneInfo.Local);
}
}
}
24 changes: 23 additions & 1 deletion AwqatSalaat.Common/Interop/Native.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Runtime.InteropServices;
using System.Text;

namespace AwqatSalaat.Interop
{
public delegate IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
public delegate bool EnumWindowProc(IntPtr hwnd, IntPtr lParam);

public static class User32
{
Expand All @@ -14,6 +16,9 @@ public static int MessageBox(IntPtr HWND, string lpText, string lpCaption, Messa
public static int MessageBox(IntPtr HWND, string lpText, string lpCaption, MessageBoxButtons buttons, MessageBoxIcon icon)
=> MessageBox(HWND, lpText, lpCaption, (uint)buttons | (uint)icon);

[DllImport("user32.dll")]
public static extern uint GetDpiForWindow([In] IntPtr hWnd);

[DllImport("user32.dll")]
public static extern bool GetWindowRect([In] IntPtr hWnd, [Out] out RECT lpRect);

Expand Down Expand Up @@ -60,6 +65,15 @@ public static int MessageBox(IntPtr HWND, string lpText, string lpCaption, Messa

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool DestroyWindow(IntPtr hwnd);

[DllImport("user32.dll")]
public static extern bool EnumChildWindows(IntPtr hWndParent, EnumWindowProc lpEnumFunc, IntPtr lParam);

[DllImport("user32.dll")]
public static extern IntPtr GetAncestor(IntPtr hwnd, GetAncestorFlags gaFlags);

[DllImport("user32.dll", CharSet = CharSet.Ansi)]
public static extern int GetClassName(IntPtr hwnd, [Out] StringBuilder lpClassName, int nMaxCount);
}

public static class Dwmapi
Expand Down Expand Up @@ -146,6 +160,13 @@ public enum MessageBoxIcon : uint
MB_ICONSTOP = MB_ICONHAND,
}

public enum GetAncestorFlags
{
GA_PARENT = 1,
GA_ROOT = 2,
GA_ROOTOWNER = 3,
}

public enum AccentState
{
ACCENT_DISABLED = 0,
Expand Down Expand Up @@ -288,7 +309,8 @@ public enum AlphaFormat : byte

public enum WindowMessage : uint
{
WM_SETREDRAW = 0x000B
WM_SETREDRAW = 0x000B,
WM_SETTINGCHANGE = 0x001A
}

[Flags]
Expand Down
Loading

0 comments on commit 617662c

Please sign in to comment.