Skip to content

Commit

Permalink
working fine, couple of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
meetox80 committed Sep 28, 2023
1 parent 1412189 commit 1b00b45
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 51 deletions.
37 changes: 36 additions & 1 deletion zstio-tv/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
internal class Config
{
public static bool Developer = false;
public static string TimeAPI = "http://worldtimeapi.org/api/timezone/Europe/Warsaw";
public static string ReplacementsAPI = "https://zastepstwa-zstio.netlify.app/api/getSubstitutions";

public static string SpotifyID = "859de286484544ad859832003ac4e6b4";
Expand Down Expand Up @@ -45,6 +44,42 @@ internal class Config
"19:00 - 00:00"
};


// Short lesson times
public static string[] ShortLessonTimes =
{
"8:00 - 8:30",
"8:35 - 9:05",
"9:10 - 9:40",
"9:45 - 10:15",
"10:30 - 11:00",
"11:05 - 11:35",
"11:40 - 12:10",
"12:15 - 12:45",
"12:50 - 13:20",
"13:25 - 13:55",
"14:00 - 14:30",
"14:35 - 15:05",
"15:10 - 15:40"
};

public static string[] ShortBreakTimes =
{
"8:30 - 8:35",
"9:05 - 9:10",
"9:40 - 9:45",
"10:15 - 10:30",
"11:00 - 11:05",
"11:35 - 11:40",
"12:10 - 12:15",
"12:45 - 12:50",
"13:20 - 13:25",
"13:55 - 14:00",
"14:30 - 14:35",
"15:05 - 15:10",
"15:40 - 00:00"
};

public static string Warning = "Przypominamy, że obowiązuje całkowity zakaz opuszczania terenu szkoły podczas zajęć i przerw międzylekcyjnych.";
}
}
44 changes: 44 additions & 0 deletions zstio-tv/ConfigWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<Window x:Class="zstio_tv.ConfigWindow"
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:zstio_tv"
mc:Ignorable="d"
Title="ConfigWindow" Height="450" Width="800" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" Background="#FF101010" Loaded="WindowLoaded">
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>

<!-- Fuck focusing, its a bug - rvyk -->
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
</Window.Resources>
<Grid>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Margin="15,15,0,0" Height="30" VerticalAlignment="Top">
<Label Foreground="White" FontFamily="/Font/InterBold/#Inter" FontSize="15" Content="Ostrzezenie: " Height="30"/>
<TextBox x:Name="input_warning" Width="650" Height="20" Background="#FF1B1B1B" BorderBrush="{x:Null}" Foreground="White" SelectionBrush="#FFA94646" MaxLength="125"/>
</StackPanel>

<CheckBox x:Name="checkbox_short" Content="Skrocone lekcje" Foreground="White" FontFamily="/Font/InterBold/#Inter" Height="16" Margin="20,5,0,0"/>
</StackPanel>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,10,10">
<Button Cursor="Hand" Height="30" Width="120" Content="Minimalizuj" FontFamily="/Font/InterBold/#Inter" Opacity="0.5" Foreground="White" Background="#FF151515" BorderBrush="#FF5A4343" Click="Button_Click_1" Margin="10,0,0,0"/>
<Button Cursor="Hand" Height="30" Width="90" Content="Zastosuj" FontFamily="/Font/InterBold/#Inter" Foreground="White" Background="#FF151515" BorderBrush="#FFA94646" Click="Button_Click" Margin="10,0,0,0"/>
</StackPanel>
</Grid>
</Window>
68 changes: 68 additions & 0 deletions zstio-tv/ConfigWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Runtime.InteropServices;
using System;
using System.Windows;
using System.Windows.Interop;

namespace zstio_tv
{
internal class Win32
{
public const int GWL_STYLE = -16;
public const int WS_SYSMENU = 0x80000;
[DllImport("user32.dll", SetLastError = true)]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
}

public partial class ConfigWindow : Window
{
public ConfigWindow()
{
InitializeComponent();

Check failure on line 22 in zstio-tv/ConfigWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The name 'InitializeComponent' does not exist in the current context
}

public static string[] TempLessonTimes = { }, TempBreakTimes = { };
private void Button_Click(object sender, RoutedEventArgs e)
{
if (input_warning.Text != null || input_warning.Text != "")

Check failure on line 28 in zstio-tv/ConfigWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The name 'input_warning' does not exist in the current context

Check failure on line 28 in zstio-tv/ConfigWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The name 'input_warning' does not exist in the current context
{
Config.Warning = input_warning.Text;

Check failure on line 30 in zstio-tv/ConfigWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The name 'input_warning' does not exist in the current context
MainWindow._Instance.handler_content_description_warning_label.Text = Config.Warning;

Check failure on line 31 in zstio-tv/ConfigWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

'MainWindow' does not contain a definition for 'handler_content_description_warning_label' and no accessible extension method 'handler_content_description_warning_label' accepting a first argument of type 'MainWindow' could be found (are you missing a using directive or an assembly reference?)
}

// Reload the break times if its set on short lesson times
if (checkbox_short.IsChecked == true)

Check failure on line 35 in zstio-tv/ConfigWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The name 'checkbox_short' does not exist in the current context
{
Config.LessonTimes = Config.ShortLessonTimes;
Config.BreakTimes = Config.ShortBreakTimes;
} else
{
Config.LessonTimes = TempLessonTimes;
Config.BreakTimes = TempBreakTimes;
}

ReloadReplacements();
}

public static void ReloadReplacements()
{
MainWindow.ReplacementsGETAPI_Tick(null, null);
MainWindow.ReplacementsCALC_Tick(null, null);
}

private void WindowLoaded(object sender, RoutedEventArgs e)
{
TempLessonTimes = Config.LessonTimes;
TempBreakTimes = Config.BreakTimes;

var hwnd = new WindowInteropHelper(this).Handle;
Win32.SetWindowLong(hwnd, Win32.GWL_STYLE, Win32.GetWindowLong(hwnd, Win32.GWL_STYLE) & ~Win32.WS_SYSMENU);
}

private void Button_Click_1(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
}
}
54 changes: 12 additions & 42 deletions zstio-tv/Helpers/IDateTime.cs
Original file line number Diff line number Diff line change
@@ -1,73 +1,43 @@
using Newtonsoft.Json;
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Text.RegularExpressions;
using System;

namespace zstio_tv.Helpers
{
internal class IDateTime
{
public static dynamic ProcessDynamic() { return JsonConvert.DeserializeObject(LocalMemory.DateAPIResponse); }

public static void ReloadDateAPI()
{
using (HttpClient Client = new HttpClient())
{
try
{
LocalMemory.DateAPIResponse = Client.GetStringAsync(Config.TimeAPI).Result;
} catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
}

public static string CalculateClock()
{
dynamic Data = ProcessDynamic();
string DateResult = Data.datetime;

Match RegexMatch = Regex.Match(DateResult, @"\b(\d{2}:\d{2})\b");
if (RegexMatch.Success)
return RegexMatch.Groups[1].Value;
return "--:--";
return DateTime.Now.ToString("HH:mm");
}

public static string CalculateDate()
{
dynamic Data = ProcessDynamic();
string DateResult = Data.datetime;

// Debug - i had many problems with parsing :/ Console.WriteLine(DateResult);
string Day = DateResult.Split('/')[1].Split('/')[0];
string ProcessMonth = DateResult.Split('/')[0];
string ProcessWeekDay = Data.day_of_week;
string Day = DateTime.Now.ToString("dd");
string ProcessMonth = DateTime.Now.ToString("MM");
string ProcessWeekDay = DateTime.Now.DayOfWeek.ToString();

string WeekDay = "", Month = "";

switch (ProcessWeekDay)
{
case "1":
case "Monday":
WeekDay = "Poniedzialek";
break;
case "2":
case "Tuesday":
WeekDay = "Wtorek";
break;
case "3":
case "Wednesday":
WeekDay = "Środa";
break;
case "4":
case "Thursday":
WeekDay = "Czwartek";
break;
case "5":
case "Friday":
WeekDay = "Piątek";
break;
case "6":
case "Saturday":
WeekDay = "Sobota";
break;
case "7":
case "Sunday":
WeekDay = "Niedziela";
break;
}
Expand Down
2 changes: 1 addition & 1 deletion zstio-tv/Helpers/ILesson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static string[] GetLessons()

if (NextLessonOrBreakStartTime == DateTime.MaxValue)
{
return new string[] { "Brak lekcji na dziś.", "" };
return new string[] { "Brak lekcji na dziś", "" };
}

TimeSpan TimeToNextLessonOrBreak = NextLessonOrBreakStartTime - CurrentTime;
Expand Down
2 changes: 1 addition & 1 deletion zstio-tv/Helpers/IReplacements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static void PlaceElement(string LessonNumber, string branch, string teach
ClassroomTextBlock.Text = $"{classroom}";
ClassroomTextBlock.FontFamily = new FontFamily(new Uri("pack://application:,,,/"), "./Font/InterBold/#Inter");
ClassroomTextBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFFFF"));
ReplacementTextBlock.FontSize = 16;
ClassroomTextBlock.FontSize = 16;
ClassroomTextBlock.TextAlignment = TextAlignment.Center;
ClassroomTextBlock.VerticalAlignment = VerticalAlignment.Center;
Rectangle ClassroomBackground = new Rectangle();
Expand Down
22 changes: 16 additions & 6 deletions zstio-tv/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ public MainWindow()

private void WindowLoaded(object sender, RoutedEventArgs e)
{
// Reload the API in order to start Lesson dispatcher
IDateTime.ReloadDateAPI();
// Reload the Replacements functionality, start the replacements scrolling
ReplacementsGETAPI_Tick(null, null);
ReplacementsCALC_Tick(null, null);
GetWeatherTick(null, null);
ClockTimerTick(null, null);

SpotifyAuth.AuthorizeSpotify();

ConfigWindow ConfigWindow_Manager = new ConfigWindow();
ConfigWindow_Manager.Show();

// Setup the warning display, if the warning string is empty; then hide.
if (Config.Warning == "")
handler_content_description_warning_label.Visibility = Visibility.Hidden;
Expand Down Expand Up @@ -201,9 +203,9 @@ private void SpotifyCurrentPlaying_Tick(object sender, EventArgs e)
}
}

private void ReplacementsCALC_Tick(object sender, EventArgs e) => IReplacements.ConfigureReplacements();
public static void ReplacementsCALC_Tick(object sender, EventArgs e) => IReplacements.ConfigureReplacements();

private void ReplacementsGETAPI_Tick(object sender, EventArgs e)
public static void ReplacementsGETAPI_Tick(object sender, EventArgs e)
{
// Contact with the api responsible for replacements/substitutions
using (HttpClient Client = new HttpClient())
Expand Down Expand Up @@ -276,12 +278,20 @@ private void LessonTimerTick(object sender, EventArgs e)

handler_bar_lessonwidget_title.Text = GetLessonsOutput[0];
handler_bar_lessonwidget_timer.Text = GetLessonsOutput[1];

if (handler_bar_lessonwidget_title.Text.StartsWith("Brak lekcji"))
{
handler_bar_lessonwidget_title.FontSize = 24;
handler_bar_lessonwidget_title.Margin = new Thickness(0, 16, 0, 0);
} else
{
handler_bar_lessonwidget_title.FontSize = 14;
handler_bar_lessonwidget_title.Margin = new Thickness(0, 5, 0, 0);
}
}

private void ClockTimerTick(object sender, EventArgs e)
{
IDateTime.ReloadDateAPI();

handler_bar_clock.Text = IDateTime.CalculateClock();
handler_bar_date.Text = IDateTime.CalculateDate();
}
Expand Down
7 changes: 7 additions & 0 deletions zstio-tv/zstio-tv.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="ConfigWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -219,6 +223,9 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Config.cs" />
<Compile Include="ConfigWindow.xaml.cs">
<DependentUpon>ConfigWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Helpers\IDateTime.cs" />
<Compile Include="Helpers\ILesson.cs" />
<Compile Include="Helpers\IReplacements.cs" />
Expand Down

0 comments on commit 1b00b45

Please sign in to comment.