-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from samir-dahal/feat/events
Feat/events
- Loading branch information
Showing
20 changed files
with
217 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using NepDate; | ||
using SambatWidget.Core.Models; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.Json; | ||
|
||
namespace SambatWidget.Core | ||
{ | ||
public static class EventParser | ||
{ | ||
private static Dictionary<string, EventDataModel> _events = new Dictionary<string, EventDataModel>(); | ||
private static Dictionary<string, string[]> _cachedEvents = new Dictionary<string, string[]>(); | ||
public static void ParseEventsJson(string path) | ||
{ | ||
try | ||
{ | ||
if (_cachedEvents.Count <= 0) | ||
{ | ||
_cachedEvents = JsonSerializer.Deserialize<Dictionary<string, string[]>>(File.ReadAllText(path), new JsonSerializerOptions | ||
{ | ||
PropertyNameCaseInsensitive = true | ||
}); | ||
foreach (KeyValuePair<string, string[]> kvp in _cachedEvents) | ||
{ | ||
int day = NepaliDate.Parse(kvp.Key).Day; | ||
_events.Add(kvp.Key, new EventDataModel(bool.Parse(kvp.Value[0]), kvp.Value[1], kvp.Value[2], day)); | ||
} | ||
_cachedEvents = null; | ||
} | ||
} | ||
catch { } | ||
} | ||
/// <summary> | ||
/// Get event data by Nepali date format as param yyyy-m-d | ||
/// </summary> | ||
/// <param name="date"></param> | ||
/// <returns></returns> | ||
public static EventDataModel GetEventByDate(string date) | ||
{ | ||
EventDataModel result = null; | ||
if (_events != null) | ||
{ | ||
_events.TryGetValue(date, out result); | ||
} | ||
return result; | ||
} | ||
public static bool HasEvent(string date) | ||
{ | ||
if (_events != null) | ||
{ | ||
return _events.ContainsKey(date); | ||
} | ||
return false; | ||
} | ||
public static bool HasEventHoliday(string date) | ||
{ | ||
return GetEventByDate(date)?.IsHoliday ?? false; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace SambatWidget.Core.Models | ||
{ | ||
public class EventDataModel | ||
{ | ||
public EventDataModel(bool isHoliday, string nepaliName, string englishName, int date) | ||
{ | ||
IsHoliday = isHoliday; | ||
NepaliName = nepaliName; | ||
EnglishName = englishName; | ||
Date = date; | ||
} | ||
public int Date { get; set; } | ||
public bool IsHoliday { get; } | ||
public string NepaliName { get; } | ||
public string EnglishName { get; } | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<UserControl | ||
x:Class="SambatWidget.UI.Controls.WidgetCalendarEventPopup" | ||
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:local="clr-namespace:SambatWidget.UI.Controls" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
d:DesignHeight="450" | ||
d:DesignWidth="800" | ||
mc:Ignorable="d"> | ||
<Popup | ||
IsOpen="{Binding EventPopupVisible, Mode=OneWay}" | ||
Placement="MousePoint" | ||
PopupAnimation="Fade" | ||
StaysOpen="False"> | ||
<Border Padding="5" Background="#fff3cd"> | ||
<StackPanel Width="150"> | ||
<StackPanel.Resources> | ||
<Style TargetType="TextBlock"> | ||
<Setter Property="TextWrapping" Value="Wrap" /> | ||
<Style.Triggers> | ||
<DataTrigger Binding="{Binding EventInfo.IsHoliday}" Value="True"> | ||
<Setter Property="Foreground" Value="{DynamicResource DangerColor}" /> | ||
</DataTrigger> | ||
</Style.Triggers> | ||
</Style> | ||
</StackPanel.Resources> | ||
<TextBlock | ||
FontFamily="{StaticResource FontBold}" | ||
FontSize="15" | ||
Text="{Binding EventInfo.Date}" /> | ||
<TextBlock | ||
Margin="0,8" | ||
FontFamily="{StaticResource FontSemiBold}" | ||
FontSize="10" | ||
Text="{Binding EventInfo.EnglishName}" /> | ||
<TextBlock FontSize="10" Text="{Binding EventInfo.NepaliName}" /> | ||
</StackPanel> | ||
</Border> | ||
</Popup> | ||
</UserControl> |
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,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace SambatWidget.UI.Controls | ||
{ | ||
/// <summary> | ||
/// Interaction logic for WidgetCalendarEventPopup.xaml | ||
/// </summary> | ||
public partial class WidgetCalendarEventPopup : UserControl | ||
{ | ||
public WidgetCalendarEventPopup() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
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
Large diffs are not rendered by default.
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
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
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