mirror of
https://github.com/XFox111/GUTSchedule.git
synced 2026-04-22 06:58:01 +03:00
Code cleanup and optimizing
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<Page
|
||||
x:Class="GUTSchedule.UWP.Pages.AboutPage"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
|
||||
Loaded="Page_Loaded">
|
||||
|
||||
<Page.TopAppBar>
|
||||
<CommandBar ClosedDisplayMode="Compact" Background="{StaticResource SystemAccentColor}" RequestedTheme="Dark">
|
||||
<CommandBar.Content>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Width="48" Height="48" Margin="0" Background="Transparent" Click="BackRequested">
|
||||
<SymbolIcon Symbol="Back"/>
|
||||
</Button>
|
||||
<TextBlock x:Uid="aboutTitle" Text="About application" Style="{StaticResource TitleTextBlockStyle}" Margin="10,6" Grid.Column="1"/>
|
||||
</Grid>
|
||||
</CommandBar.Content>
|
||||
</CommandBar>
|
||||
</Page.TopAppBar>
|
||||
|
||||
<ScrollViewer>
|
||||
<StackPanel Margin="10">
|
||||
<TextBlock x:Uid="appName" Style="{StaticResource TitleTextBlockStyle}" Text="GUT.Schedule"/>
|
||||
<TextBlock Style="{StaticResource CaptionTextBlockStyle}" Text="v$(Build.BuildNumber) (ci-id #$(Build.BuildId))" Foreground="DarkGray" Margin="0,0,0,10" x:Name="version"/>
|
||||
|
||||
<TextBlock x:Uid="appDescription" Text="appDescription"/>
|
||||
|
||||
<TextBlock x:Uid="developedBy" Text="developedBy"/>
|
||||
|
||||
<TextBlock x:Uid="contributorsTitle" x:Name="contributorsTitle" Style="{StaticResource SubtitleTextBlockStyle}" Text="Contributors" Margin="0,10,0,0" Visibility="Collapsed"/>
|
||||
<TextBlock x:Name="contributors" Visibility="Collapsed"/>
|
||||
|
||||
<TextBlock x:Uid="specialThanksTitle" Style="{StaticResource SubtitleTextBlockStyle}" Text="Special thanks" Margin="0,10,0,0"/>
|
||||
<TextBlock x:Uid="specialThanksPeople"/>
|
||||
|
||||
<TextBlock x:Uid="contactsTitle" Style="{StaticResource SubtitleTextBlockStyle}" Text="Contacts" Margin="0,10,0,0"/>
|
||||
<TextBlock>
|
||||
<Run x:Uid="websiteContact">Website</Run>: <Hyperlink NavigateUri="https://xfox111.net">https://xfox111.net</Hyperlink><LineBreak/>
|
||||
<Run x:Uid="twitterContact">Twitter</Run>: <Hyperlink NavigateUri="https://twitter.com/xfox111">@xfox111</Hyperlink><LineBreak/>
|
||||
<Run x:Uid="vkontakteContact">VKontakte</Run>: <Hyperlink NavigateUri="https://vk.com/xfox.mike">@xfox.mike</Hyperlink><LineBreak/>
|
||||
<Run>LinkedIn</Run>: <Hyperlink NavigateUri="https://linkedin.com/in/xfox">@xfox</Hyperlink><LineBreak/>
|
||||
<Run>GitHub</Run>: <Hyperlink NavigateUri="https://github.com/xfox111">@xfox111</Hyperlink>
|
||||
</TextBlock>
|
||||
|
||||
<TextBlock x:Uid="linksTitle" Style="{StaticResource SubtitleTextBlockStyle}" Text="Useful links" Margin="0,10,0,0"/>
|
||||
<TextBlock>
|
||||
<Hyperlink NavigateUri="https://xfox111.net/Projects/GUTSchedule/PrivacyPolicy.txt"><Run x:Uid="privacyPolicyLink">Privacy policy</Run></Hyperlink><LineBreak/>
|
||||
<Hyperlink NavigateUri="https://www.gnu.org/licenses/gpl-3.0">General Public License v3</Hyperlink><LineBreak/>
|
||||
<Hyperlink NavigateUri="https://github.com/xfox111/gutschedule"><Run x:Uid="repositoryLink">GitHub repository</Run></Hyperlink><LineBreak/>
|
||||
<Hyperlink NavigateUri="http://tios.spbgut.ru/index.php"><Run x:Uid="notsLink">"TIES" RF</Run></Hyperlink><LineBreak/>
|
||||
<Hyperlink NavigateUri="https://sut.ru"><Run x:Uid="sutLink">SPbSUT</Run></Hyperlink>
|
||||
</TextBlock>
|
||||
|
||||
<TextBlock Style="{StaticResource CaptionTextBlockStyle}" Text="©2020 Michael "XFox" Gordeev" Margin="0,10,0,0"/>
|
||||
<Button x:Uid="leaveFeedback" Content="Leave feedback" HorizontalAlignment="Left" Margin="5" Click="Feedback_Click"/>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Page>
|
||||
@@ -0,0 +1,88 @@
|
||||
using Microsoft.Services.Store.Engagement;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.Data.Json;
|
||||
using Windows.System;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Documents;
|
||||
|
||||
namespace GUTSchedule.UWP.Pages
|
||||
{
|
||||
public sealed partial class AboutPage : Page
|
||||
{
|
||||
public AboutPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
KeyDown += (s, e) =>
|
||||
{
|
||||
if (e.Key == VirtualKey.Back || e.Key == VirtualKey.GoBack)
|
||||
BackRequested(s, null);
|
||||
};
|
||||
}
|
||||
|
||||
private async void Page_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
PackageVersion ver = Package.Current.Id.Version;
|
||||
version.Text = $"v{ver.Major}{(ver.Minor < 1000 ? "0" + ver.Minor : ver.Minor.ToString())}.{ver.Revision} (ci-id #{ver.Build})";
|
||||
|
||||
List<string> contributorsList = new List<string>();
|
||||
try
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "https://api.github.com/repos/xfox111/gutschedule/contributors");
|
||||
request.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0");
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(request);
|
||||
string resposeContent = await response.Content.ReadAsStringAsync();
|
||||
JsonObject parsedResponse = JsonObject.Parse(resposeContent);
|
||||
|
||||
foreach (var i in parsedResponse)
|
||||
if (i.Value.GetObject()["type"].GetString() == "User" && i.Value.GetObject()["login"].GetString().ToLower() != "xfox111")
|
||||
contributorsList.Add(i.Value.GetObject()["login"].GetString());
|
||||
|
||||
request.Dispose();
|
||||
client.Dispose();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (contributorsList.Count > 0)
|
||||
{
|
||||
foreach(string i in contributorsList)
|
||||
{
|
||||
Hyperlink link = new Hyperlink
|
||||
{
|
||||
NavigateUri = new Uri("https://github.com.i")
|
||||
};
|
||||
link.Inlines.Add(new Run
|
||||
{
|
||||
Text = "@" + i
|
||||
});
|
||||
contributors.Inlines.Add(link);
|
||||
contributors.Inlines.Add(new Run
|
||||
{
|
||||
Text = ", "
|
||||
});
|
||||
}
|
||||
contributors.Inlines.RemoveAt(contributors.Inlines.Count - 1);
|
||||
|
||||
contributorsTitle.Visibility = Visibility.Visible;
|
||||
contributors.Visibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void Feedback_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (StoreServicesFeedbackLauncher.IsSupported())
|
||||
await StoreServicesFeedbackLauncher.GetDefault().LaunchAsync();
|
||||
else
|
||||
await Launcher.LaunchUriAsync(new Uri("mailto:feedback@xfox111.net"));
|
||||
}
|
||||
|
||||
private void BackRequested(object sender, RoutedEventArgs e) =>
|
||||
Frame.GoBack();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<Page
|
||||
x:Class="GUTSchedule.UWP.Pages.MainPage"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
Loaded="Page_Loaded">
|
||||
|
||||
<Page.Background>
|
||||
<ImageBrush ImageSource="https://cabs.itut.ru/cabinet/ini/general/0/cabinet/img/bg_n.jpg" Stretch="UniformToFill"/>
|
||||
</Page.Background>
|
||||
|
||||
<Page.TopAppBar>
|
||||
<CommandBar ClosedDisplayMode="Compact" Background="{StaticResource SystemAccentColor}" RequestedTheme="Dark">
|
||||
<CommandBar.Content>
|
||||
<TextBlock x:Uid="appName" Text="GUT.Schedule" Style="{StaticResource TitleTextBlockStyle}" Margin="10,6"/>
|
||||
</CommandBar.Content>
|
||||
<CommandBar.SecondaryCommands>
|
||||
<AppBarButton x:Uid="clearCalendarOption" Icon="Delete" Label="Clear schedule" Tag="clear" Click="AppBarButton_Click"/>
|
||||
<AppBarButton x:Uid="reportErrorOption" Label="Report error" Tag="report" Click="AppBarButton_Click">
|
||||
<AppBarButton.Icon>
|
||||
<FontIcon Glyph=""/>
|
||||
</AppBarButton.Icon>
|
||||
</AppBarButton>
|
||||
<AppBarButton x:Uid="aboutOption" Label="About application" Tag="about" Click="AppBarButton_Click">
|
||||
<AppBarButton.Icon>
|
||||
<FontIcon Glyph=""/>
|
||||
</AppBarButton.Icon>
|
||||
</AppBarButton>
|
||||
</CommandBar.SecondaryCommands>
|
||||
</CommandBar>
|
||||
</Page.TopAppBar>
|
||||
|
||||
<Grid>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup>
|
||||
<VisualState>
|
||||
<VisualState.StateTriggers>
|
||||
<AdaptiveTrigger MinWindowWidth="800"/>
|
||||
</VisualState.StateTriggers>
|
||||
<VisualState.Setters>
|
||||
<Setter Target="grid.ColumnDefinitions[1].Width" Value="*"/>
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState>
|
||||
<VisualState.StateTriggers>
|
||||
<AdaptiveTrigger MinWindowWidth="1200"/>
|
||||
</VisualState.StateTriggers>
|
||||
<VisualState.Setters>
|
||||
<Setter Target="grid.ColumnDefinitions[1].Width" Value="2*"/>
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
|
||||
<ScrollViewer>
|
||||
<Grid x:Name="grid">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="0"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Padding="10" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<TextBlock x:Uid="scheduleParametersTitle" Style="{StaticResource SubtitleTextBlockStyle}" Text="Schedule parameters"/>
|
||||
|
||||
<CheckBox x:Uid="authorizeCheckbox" Content="Authorize via personal cabinet" Checked="ChangeAuthorizationMethod" Unchecked="ChangeAuthorizationMethod" IsChecked="True" x:Name="authorize"/>
|
||||
<StackPanel x:Name="credentialMethod">
|
||||
<TextBox x:Uid="email" PlaceholderText="E-mail" x:Name="email"/>
|
||||
<PasswordBox x:Uid="password" PlaceholderText="Password" x:Name="password"/>
|
||||
<CheckBox x:Uid="remember" Content="Remember" x:Name="rememberCredential" Checked="RememberCredential_Checked" Unchecked="RememberCredential_Checked"/>
|
||||
</StackPanel>
|
||||
<StackPanel x:Name="defaultMethod" Visibility="Collapsed">
|
||||
<ComboBox x:Uid="facultySpinner" x:Name="faculty" PlaceholderText="No schedule is available" Header="Course" SelectionChanged="Faculty_SelectionChanged"/>
|
||||
<ComboBox x:Uid="courseSpinner" x:Name="course" Header="Course" SelectionChanged="Course_SelectionChanged">
|
||||
<ComboBoxItem Content="1"/>
|
||||
<ComboBoxItem Content="2"/>
|
||||
<ComboBoxItem Content="3"/>
|
||||
<ComboBoxItem Content="4"/>
|
||||
</ComboBox>
|
||||
<ComboBox x:Uid="groupSpinner" x:Name="group" PlaceholderText="No schedule is available" Header="Group" SelectionChanged="Group_SelectionChanged"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock x:Uid="exportParametersTitle" Style="{StaticResource SubtitleTextBlockStyle}" Text="Export parameters"/>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<CalendarDatePicker x:Uid="dateRangeFrom" Header="Export from" x:Name="startDate"/>
|
||||
<CalendarDatePicker x:Uid="dateRangeTo" Grid.Row="1" Header="Export to" VerticalAlignment="Top" x:Name="endDate"/>
|
||||
|
||||
<Button x:Uid="today" Content="Today" Grid.Column="1" VerticalAlignment="Bottom" Click="SetTodayDate" />
|
||||
<StackPanel Grid.Column="1" Grid.Row="1" Margin="0,28,0,0">
|
||||
<Button x:Uid="forDay" Content="For day" Click="SetEndDate" Tag="0"/>
|
||||
<Button x:Uid="forWeek" Content="For week" Click="SetEndDate" Tag="6"/>
|
||||
<Button x:Uid="forMonth" Content="For month" Click="SetEndDate" Tag="30"/>
|
||||
<Button x:Uid="forSemester" Content="For semester" Click="SetForSemester"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<ComboBox x:Uid="reminderSpinner" Header="Set reminder for:" x:Name="reminder" SelectionChanged="Reminder_SelectionChanged">
|
||||
<ComboBoxItem x:Uid="noReminder" Content="None"/>
|
||||
<ComboBoxItem x:Uid="inTimeReminder" Content="At the begining of event"/>
|
||||
<ComboBoxItem x:Uid="fiveMinuteReminder" Content="5 minutes"/>
|
||||
<ComboBoxItem x:Uid="tenMinuteReminder" Content="10 minutes"/>
|
||||
</ComboBox>
|
||||
|
||||
<CheckBox x:Uid="addGroupToTitle" Content="Add group number to event title" x:Name="addGroupToTitle" Checked="AddGroupToTitle_Checked" Unchecked="AddGroupToTitle_Checked"/>
|
||||
<TextBlock x:Uid="titleNote" Style="{StaticResource CaptionTextBlockStyle}" Text="note"/>
|
||||
|
||||
<TextBlock Foreground="Red" Visibility="Collapsed" Text="Error" x:Name="errorPlaceholder"/>
|
||||
<Button x:Uid="addScheduleButton" Content="Add schedule" Background="{StaticResource SystemAccentColor}" Foreground="White" FontWeight="Bold" Margin="0,10" Click="Export"/>
|
||||
|
||||
<TextBlock x:Uid="copyrights" Style="{StaticResource CaptionTextBlockStyle}" Text="©2020 Michael Gordeev, INS, ICT-907"/>
|
||||
<TextBlock Style="{StaticResource CaptionTextBlockStyle}" Text="v$(Build.BuildNumber) (ci-id #$(Build.BuildId))" x:Name="version"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
|
||||
<Grid Background="{StaticResource SystemAccentColor}" x:Name="loading" Visibility="Collapsed">
|
||||
<StackPanel VerticalAlignment="Center">
|
||||
<ProgressRing Width="100" Height="100" Foreground="White" IsActive="True" HorizontalAlignment="Center"/>
|
||||
<TextBlock Style="{StaticResource TitleTextBlockStyle}" x:Name="status" Text="Processing..." HorizontalAlignment="Center" Foreground="White" Margin="0,20"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Page>
|
||||
@@ -0,0 +1,280 @@
|
||||
using GUTSchedule.Models;
|
||||
using GUTSchedule.UWP.Controls;
|
||||
using System;
|
||||
using Windows.Security.Credentials;
|
||||
using Windows.System;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using Windows.UI.Popups;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.ApplicationModel.Resources;
|
||||
using Windows.Storage;
|
||||
using Microsoft.Services.Store.Engagement;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.Core;
|
||||
|
||||
namespace GUTSchedule.UWP.Pages
|
||||
{
|
||||
public sealed partial class MainPage : Page
|
||||
{
|
||||
private readonly PasswordVault vault = new PasswordVault();
|
||||
private readonly ResourceLoader resources = ResourceLoader.GetForCurrentView();
|
||||
static readonly ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
|
||||
|
||||
public MainPage() =>
|
||||
InitializeComponent();
|
||||
|
||||
private async void Page_Loaded(object sender, RoutedEventArgs args)
|
||||
{
|
||||
try
|
||||
{
|
||||
PackageVersion ver = Package.Current.Id.Version;
|
||||
version.Text = $"v{ver.Major}{(ver.Minor < 1000 ? "0" + ver.Minor : ver.Minor.ToString())}.{ver.Revision} (ci-id #{ver.Build})";
|
||||
|
||||
authorize.IsChecked = (bool?)settings.Values["Authorize"] ?? true;
|
||||
if (vault.RetrieveAll() is IReadOnlyList<PasswordCredential> credentials && credentials.Count > 0)
|
||||
{
|
||||
email.Text = credentials.First().UserName;
|
||||
credentials.First().RetrievePassword();
|
||||
password.Password = credentials.First().Password;
|
||||
}
|
||||
rememberCredential.IsChecked = (bool?)settings.Values["RememberCredential"] ?? true;
|
||||
|
||||
faculty.ItemsSource = (await Parser.GetFaculties()).Select(i => new ComboBoxItem
|
||||
{
|
||||
Content = i.name,
|
||||
Tag = i.id,
|
||||
IsSelected = (string)settings.Values["Faculty"] == i.id
|
||||
}).ToList();
|
||||
faculty.SelectedIndex = (faculty.ItemsSource as List<ComboBoxItem>).FindIndex(i => i.IsSelected);
|
||||
if (faculty.SelectedIndex < 0)
|
||||
faculty.SelectedIndex = 0;
|
||||
course.SelectedIndex = (int?)settings.Values["Course"] ?? 0;
|
||||
|
||||
startDate.Date = DateTime.Today;
|
||||
endDate.Date = startDate.Date.Value.AddDays(6);
|
||||
|
||||
reminder.SelectedIndex = (int?)settings.Values["Reminder"] ?? 2;
|
||||
addGroupToTitle.IsChecked = (bool?)settings.Values["AddGroupToTitle"] ?? false;
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
PushInternetExceptionMessage(e, () => Page_Loaded(sender, args));
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageDialog dialog = new MessageDialog(e.Message, e.GetType().ToString());
|
||||
dialog.Commands.Add(new UICommand("OK", (command) => CoreApplication.Exit()));
|
||||
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async void AppBarButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
switch (((FrameworkElement)sender).Tag)
|
||||
{
|
||||
case "clear":
|
||||
ClearCalendarControl clearControl = new ClearCalendarControl();
|
||||
ContentDialogResult result = await clearControl.ShowAsync();
|
||||
if(result == ContentDialogResult.Primary)
|
||||
{
|
||||
await Calendar.Clear(clearControl.SelectedCalendars, clearControl.ClearUpcomingOnly);
|
||||
await new MessageDialog(resources.GetString("clearScheduleDone"), resources.GetString("clearScheduleTitle/Title")).ShowAsync();
|
||||
}
|
||||
break;
|
||||
case "about":
|
||||
Frame.Navigate(typeof(AboutPage));
|
||||
break;
|
||||
case "report":
|
||||
if (StoreServicesFeedbackLauncher.IsSupported())
|
||||
await StoreServicesFeedbackLauncher.GetDefault().LaunchAsync();
|
||||
else
|
||||
await Launcher.LaunchUriAsync(new Uri("mailto:feedback@xfox111.net"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangeAuthorizationMethod(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (credentialMethod == null)
|
||||
return;
|
||||
|
||||
if (authorize.IsChecked.Value)
|
||||
{
|
||||
credentialMethod.Visibility = Visibility.Visible;
|
||||
defaultMethod.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
credentialMethod.Visibility = Visibility.Collapsed;
|
||||
defaultMethod.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
settings.Values["Authorize"] = authorize.IsChecked;
|
||||
}
|
||||
|
||||
private void SetTodayDate(object sender, RoutedEventArgs e) =>
|
||||
startDate.Date = DateTime.Today;
|
||||
|
||||
private void SetEndDate(object sender, RoutedEventArgs e) =>
|
||||
endDate.Date = startDate.Date.Value.AddDays(int.Parse(((FrameworkElement)sender).Tag as string));
|
||||
|
||||
private void SetForSemester(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DateTime.Today.Month == 1)
|
||||
endDate.Date = new DateTime(DateTime.Today.Year, 1, 31);
|
||||
else if (DateTime.Today.Month > 8)
|
||||
endDate.Date = new DateTime(DateTime.Today.Year + 1, 1, 31);
|
||||
else
|
||||
endDate.Date = new DateTime(DateTime.Today.Year, 8, 31);
|
||||
}
|
||||
|
||||
private async void Export(object sender, RoutedEventArgs args)
|
||||
{
|
||||
errorPlaceholder.Visibility = Visibility.Collapsed;
|
||||
|
||||
if (startDate.Date > endDate.Date)
|
||||
{
|
||||
errorPlaceholder.Text = resources.GetString("invalidDateRangeError");
|
||||
errorPlaceholder.Visibility = Visibility.Visible;
|
||||
return;
|
||||
}
|
||||
|
||||
ExportParameters exportParameters;
|
||||
|
||||
if (authorize.IsChecked.Value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(email.Text) || string.IsNullOrWhiteSpace(password.Password))
|
||||
{
|
||||
errorPlaceholder.Text = resources.GetString("invalidAuthorizationError");
|
||||
errorPlaceholder.Visibility = Visibility.Visible;
|
||||
return;
|
||||
}
|
||||
|
||||
exportParameters = new CabinetExportParameters
|
||||
{
|
||||
Email = email.Text,
|
||||
Password = password.Password,
|
||||
EndDate = endDate.Date.Value.DateTime,
|
||||
StartDate = startDate.Date.Value.DateTime
|
||||
};
|
||||
|
||||
if (rememberCredential.IsChecked.Value)
|
||||
vault.Add(new PasswordCredential
|
||||
{
|
||||
UserName = email.Text,
|
||||
Password = password.Password,
|
||||
Resource = "xfox111.gutschedule"
|
||||
});
|
||||
else
|
||||
foreach (PasswordCredential credential in vault.RetrieveAll())
|
||||
vault.Remove(credential);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (group.Items.Count < 1)
|
||||
{
|
||||
errorPlaceholder.Text = resources.GetString("groupSelectionError");
|
||||
errorPlaceholder.Visibility = Visibility.Visible;
|
||||
return;
|
||||
}
|
||||
|
||||
exportParameters = new DefaultExportParameters
|
||||
{
|
||||
EndDate = endDate.Date.Value.DateTime,
|
||||
StartDate = startDate.Date.Value.DateTime,
|
||||
Course = (course.SelectedIndex + 1).ToString(),
|
||||
FacultyId = ((ComboBoxItem)faculty.SelectedItem).Tag as string,
|
||||
GroupId = ((ComboBoxItem)group.SelectedItem).Tag as string
|
||||
};
|
||||
}
|
||||
|
||||
loading.Visibility = Visibility.Visible;
|
||||
TopAppBar.Visibility = Visibility.Collapsed;
|
||||
try
|
||||
{
|
||||
status.Text = resources.GetString("loadingStatus");
|
||||
List<Occupation> schedule = await Parser.GetSchedule(exportParameters);
|
||||
|
||||
status.Text = resources.GetString("calendarExportStatus");
|
||||
await Calendar.Export(schedule, addGroupToTitle.IsChecked.Value, (reminder.SelectedIndex - 1) * 5);
|
||||
|
||||
status.Text = resources.GetString("doneStatus");
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
PushInternetExceptionMessage(e, () => Export(sender, args));
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageDialog dialog = new MessageDialog(e.Message, e.GetType().ToString());
|
||||
dialog.Commands.Add(new UICommand("OK", (command) => loading.Visibility = Visibility.Collapsed));
|
||||
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
|
||||
loading.Visibility = Visibility.Collapsed;
|
||||
TopAppBar.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
private void Faculty_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
UpdateGroupsList();
|
||||
settings.Values["Faculty"] = ((ComboBoxItem)faculty.SelectedItem).Tag;
|
||||
}
|
||||
|
||||
private void Course_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
UpdateGroupsList();
|
||||
settings.Values["Course"] = course.SelectedIndex;
|
||||
}
|
||||
|
||||
private void Reminder_SelectionChanged(object sender, SelectionChangedEventArgs e) =>
|
||||
settings.Values["Reminder"] = reminder.SelectedIndex;
|
||||
|
||||
private void Group_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if(group.SelectedItem != null)
|
||||
settings.Values["Group"] = ((ComboBoxItem)group.SelectedItem).Tag;
|
||||
}
|
||||
|
||||
private void RememberCredential_Checked(object sender, RoutedEventArgs e) =>
|
||||
settings.Values["RememberCredential"] = rememberCredential.IsChecked;
|
||||
|
||||
private void AddGroupToTitle_Checked(object sender, RoutedEventArgs e) =>
|
||||
settings.Values["AddGroupToTitle"] = rememberCredential.IsChecked;
|
||||
|
||||
private async void UpdateGroupsList()
|
||||
{
|
||||
List<(string id, string name)> groups = await Parser.GetGroups(((ComboBoxItem)faculty.SelectedItem).Tag as string, (course.SelectedIndex + 1).ToString());
|
||||
group.ItemsSource = groups.Select(i => new ComboBoxItem
|
||||
{
|
||||
Content = i.name,
|
||||
Tag = i.id,
|
||||
IsSelected = (string)settings.Values["Group"] == i.id
|
||||
}).ToList();
|
||||
group.SelectedIndex = (group.ItemsSource as List<ComboBoxItem>).FindIndex(i => i.IsSelected);
|
||||
if (group.SelectedIndex < 0)
|
||||
group.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
public async void PushInternetExceptionMessage(HttpRequestException e, Action retryAction)
|
||||
{
|
||||
MessageDialog dialog = new MessageDialog(resources.GetString("connectionFailMessage"), e.Message);
|
||||
dialog.Commands.Add(new UICommand(resources.GetString("repeat"), (command) => retryAction()));
|
||||
dialog.Commands.Add(new UICommand("OK", (command) => loading.Visibility = Visibility.Collapsed));
|
||||
|
||||
dialog.CancelCommandIndex = 1;
|
||||
dialog.DefaultCommandIndex = 0;
|
||||
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user