mirror of
https://github.com/XFox111/GUTSchedule.git
synced 2026-04-22 06:58:01 +03:00
Updated UWP app to work with local in-app calendars
This commit is contained in:
@@ -37,7 +37,7 @@
|
|||||||
<string name="forSemesterButton">For semester</string>
|
<string name="forSemesterButton">For semester</string>
|
||||||
|
|
||||||
<string name="reminderSpinner">Set reminders for</string>
|
<string name="reminderSpinner">Set reminders for</string>
|
||||||
<string name="reminderNote">(i) Attention, for cloud-based Google calendars Google automatically sets reminders for 30 minutes if there\'s no reminder set by user</string>
|
<string name="reminderNote">(i) Attention, if you choose \"None\" for cloud-based Google calendars Google sets default reminder for events automatically sets reminders for 30 minutes if there\'s no reminder set by user</string>
|
||||||
<string name="noReminderOption">None</string>
|
<string name="noReminderOption">None</string>
|
||||||
<string name="inTimeReminderOption">At the start of event</string>
|
<string name="inTimeReminderOption">At the start of event</string>
|
||||||
<string name="fiveMinuteReminderOption">5 minutes</string>
|
<string name="fiveMinuteReminderOption">5 minutes</string>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Windows.ApplicationModel.Appointments;
|
using Windows.ApplicationModel.Appointments;
|
||||||
|
using Windows.ApplicationModel.Resources;
|
||||||
|
|
||||||
namespace GUTSchedule.UWP
|
namespace GUTSchedule.UWP
|
||||||
{
|
{
|
||||||
@@ -11,21 +12,24 @@ namespace GUTSchedule.UWP
|
|||||||
{
|
{
|
||||||
public static async Task<IReadOnlyList<AppointmentCalendar>> GetCalendars()
|
public static async Task<IReadOnlyList<AppointmentCalendar>> GetCalendars()
|
||||||
{
|
{
|
||||||
AppointmentStore calendarStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadWrite);
|
AppointmentStore calendarStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AppCalendarsReadWrite);
|
||||||
return await calendarStore.FindAppointmentCalendarsAsync();
|
return await calendarStore.FindAppointmentCalendarsAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task Export(List<Occupation> schedule, bool addGroupToTitle, int reminder, string calendar)
|
public static async Task Export(List<Occupation> schedule, bool addGroupToTitle, int reminder)
|
||||||
{
|
{
|
||||||
AppointmentStore calendarStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadWrite);
|
AppointmentStore calendarStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadWrite);
|
||||||
AppointmentCalendar cal = await calendarStore.GetAppointmentCalendarAsync(calendar);
|
string calendarName = schedule.Any(i => string.IsNullOrWhiteSpace(i.Group)) ? ResourceLoader.GetForCurrentView().GetString("mySchedule") : schedule.FirstOrDefault().Group;
|
||||||
|
AppointmentCalendar cal =
|
||||||
|
(await calendarStore.FindAppointmentCalendarsAsync()).FirstOrDefault(i => i.DisplayName == calendarName) ??
|
||||||
|
await calendarStore.CreateAppointmentCalendarAsync(calendarName);
|
||||||
|
|
||||||
foreach (Occupation item in schedule)
|
foreach (Occupation item in schedule)
|
||||||
{
|
{
|
||||||
Appointment appointment = new Appointment
|
Appointment appointment = new Appointment
|
||||||
{
|
{
|
||||||
BusyStatus = AppointmentBusyStatus.Busy,
|
BusyStatus = AppointmentBusyStatus.Busy,
|
||||||
Details = item.Opponent + "\xFEFF",
|
Details = item.Opponent,
|
||||||
DetailsKind = AppointmentDetailsKind.PlainText,
|
DetailsKind = AppointmentDetailsKind.PlainText,
|
||||||
Location = item.Cabinet,
|
Location = item.Cabinet,
|
||||||
Reminder = reminder < 0 ? (TimeSpan?)null : TimeSpan.FromMinutes(reminder),
|
Reminder = reminder < 0 ? (TimeSpan?)null : TimeSpan.FromMinutes(reminder),
|
||||||
@@ -42,18 +46,14 @@ namespace GUTSchedule.UWP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task Clear(bool keepPrevious = true)
|
public static async Task Clear(IEnumerable<object> targets, bool keepPrevious)
|
||||||
{
|
{
|
||||||
AppointmentStore appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AppCalendarsReadWrite);
|
foreach (AppointmentCalendar calendar in targets)
|
||||||
|
if(keepPrevious)
|
||||||
List<Appointment> appointments = (await appointmentStore.FindAppointmentsAsync(keepPrevious ? DateTime.Today : DateTime.Today.Subtract(TimeSpan.FromDays(3000)), TimeSpan.FromDays(10000))).ToList();
|
foreach (Appointment appointment in await calendar.FindAppointmentsAsync(DateTime.Now, TimeSpan.FromDays(365)))
|
||||||
|
await calendar.DeleteAppointmentAsync(appointment.LocalId);
|
||||||
foreach(Appointment i in appointments)
|
else
|
||||||
if (i.Details.Contains('\xFEFF'))
|
await calendar.DeleteAsync();
|
||||||
{
|
|
||||||
AppointmentCalendar cal = await appointmentStore.GetAppointmentCalendarAsync(i.CalendarId);
|
|
||||||
await cal.DeleteAppointmentAsync(i.LocalId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<ContentDialog
|
||||||
|
x:Class="GUTSchedule.UWP.ClearCalendarControl"
|
||||||
|
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:appointments="using:Windows.ApplicationModel.Appointments"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
x:Uid="clearScheduleTitle"
|
||||||
|
Loaded="ContentDialog_Loaded"
|
||||||
|
Title="Clear schedule calendar"
|
||||||
|
|
||||||
|
SecondaryButtonText="Cancel"
|
||||||
|
PrimaryButtonText="Clear">
|
||||||
|
|
||||||
|
<StackPanel>
|
||||||
|
<ListView SelectionMode="Multiple" x:Name="targetsList">
|
||||||
|
<ListView.ItemTemplate>
|
||||||
|
<DataTemplate x:DataType="appointments:AppointmentCalendar">
|
||||||
|
<TextBlock Text="{Binding DisplayName}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListView.ItemTemplate>
|
||||||
|
</ListView>
|
||||||
|
<CheckBox x:Uid="clearUpcoming" Content="Remove only upcoming events" x:Name="clearUpcoming"/>
|
||||||
|
</StackPanel>
|
||||||
|
</ContentDialog>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Windows.UI.Xaml.Controls;
|
||||||
|
|
||||||
|
namespace GUTSchedule.UWP
|
||||||
|
{
|
||||||
|
public sealed partial class ClearCalendarControl : ContentDialog
|
||||||
|
{
|
||||||
|
public IEnumerable<object> SelectedCalendars => targetsList.SelectedItems;
|
||||||
|
public bool ClearUpcomingOnly => clearUpcoming.IsChecked.Value;
|
||||||
|
|
||||||
|
public ClearCalendarControl() =>
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
private async void ContentDialog_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) =>
|
||||||
|
targetsList.ItemsSource = await Calendar.GetCalendars();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -131,6 +131,9 @@
|
|||||||
<DependentUpon>App.xaml</DependentUpon>
|
<DependentUpon>App.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Calendar.cs" />
|
<Compile Include="Calendar.cs" />
|
||||||
|
<Compile Include="ClearCalendarControl.xaml.cs">
|
||||||
|
<DependentUpon>ClearCalendarControl.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="MainPage.xaml.cs">
|
<Compile Include="MainPage.xaml.cs">
|
||||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -200,6 +203,10 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Include="ClearCalendarControl.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
<Page Include="MainPage.xaml">
|
<Page Include="MainPage.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
|
|||||||
@@ -114,8 +114,6 @@
|
|||||||
<CheckBox x:Uid="addGroupToTitle" Content="Add group number to event title" x:Name="addGroupToTitle" Checked="AddGroupToTitle_Checked" Unchecked="AddGroupToTitle_Checked"/>
|
<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 x:Uid="titleNote" Style="{StaticResource CaptionTextBlockStyle}" Text="note"/>
|
||||||
|
|
||||||
<ComboBox x:Uid="destinationCalendar" Header="Destination calendar" x:Name="calendar" SelectionChanged="Calendar_SelectionChanged"/>
|
|
||||||
|
|
||||||
<TextBlock Foreground="Red" Visibility="Collapsed" Text="Error" x:Name="errorPlaceholder"/>
|
<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"/>
|
<Button x:Uid="addScheduleButton" Content="Add schedule" Background="{StaticResource SystemAccentColor}" Foreground="White" FontWeight="Bold" Margin="0,10" Click="Export"/>
|
||||||
|
|
||||||
|
|||||||
@@ -58,23 +58,6 @@ namespace GUTSchedule.UWP
|
|||||||
|
|
||||||
reminder.SelectedIndex = (int?)settings.Values["Reminder"] ?? 2;
|
reminder.SelectedIndex = (int?)settings.Values["Reminder"] ?? 2;
|
||||||
addGroupToTitle.IsChecked = (bool?)settings.Values["AddGroupToTitle"] ?? false;
|
addGroupToTitle.IsChecked = (bool?)settings.Values["AddGroupToTitle"] ?? false;
|
||||||
|
|
||||||
calendar.ItemsSource = (await Calendar.GetCalendars()).Select(i => new ComboBoxItem
|
|
||||||
{
|
|
||||||
Content = i.DisplayName,
|
|
||||||
Tag = i.LocalId,
|
|
||||||
IsSelected = (string)settings.Values["Calendar"] == i.LocalId
|
|
||||||
}).ToList();
|
|
||||||
calendar.SelectedIndex = (calendar.ItemsSource as List<ComboBoxItem>).FindIndex(i => i.IsSelected);
|
|
||||||
if((calendar.ItemsSource as List<ComboBoxItem>).Count < 1)
|
|
||||||
{
|
|
||||||
MessageDialog dialog = new MessageDialog(resources.GetString("createCalendarMessage"), resources.GetString("createCalendarTitle"));
|
|
||||||
dialog.Commands.Add(new UICommand("OK", (command) => CoreApplication.Exit()));
|
|
||||||
|
|
||||||
await dialog.ShowAsync();
|
|
||||||
}
|
|
||||||
if (calendar.SelectedIndex < 0)
|
|
||||||
calendar.SelectedIndex = 0;
|
|
||||||
}
|
}
|
||||||
catch (HttpRequestException e)
|
catch (HttpRequestException e)
|
||||||
{
|
{
|
||||||
@@ -95,15 +78,13 @@ namespace GUTSchedule.UWP
|
|||||||
switch (((FrameworkElement)sender).Tag)
|
switch (((FrameworkElement)sender).Tag)
|
||||||
{
|
{
|
||||||
case "clear":
|
case "clear":
|
||||||
MessageDialog dialog = new MessageDialog(resources.GetString("clearScheduleMessage"), resources.GetString("clearScheduleTitle"));
|
ClearCalendarControl clearControl = new ClearCalendarControl();
|
||||||
dialog.Commands.Add(new UICommand(resources.GetString("clearUpcomingOption"), (command) => Clear()));
|
ContentDialogResult result = await clearControl.ShowAsync();
|
||||||
dialog.Commands.Add(new UICommand(resources.GetString("clearAllOption"), (command) => Clear(true)));
|
if(result == ContentDialogResult.Primary)
|
||||||
dialog.Commands.Add(new UICommand(resources.GetString("cancelOption")));
|
{
|
||||||
|
await Calendar.Clear(clearControl.SelectedCalendars, clearControl.ClearUpcomingOnly);
|
||||||
dialog.CancelCommandIndex = 2;
|
await new MessageDialog(resources.GetString("clearScheduleDone"), resources.GetString("clearScheduleTitle/Title")).ShowAsync();
|
||||||
dialog.DefaultCommandIndex = 0;
|
}
|
||||||
|
|
||||||
await dialog.ShowAsync();
|
|
||||||
break;
|
break;
|
||||||
case "about":
|
case "about":
|
||||||
Frame.Navigate(typeof(AboutPage));
|
Frame.Navigate(typeof(AboutPage));
|
||||||
@@ -220,7 +201,7 @@ namespace GUTSchedule.UWP
|
|||||||
List<Occupation> schedule = await Parser.GetSchedule(exportParameters);
|
List<Occupation> schedule = await Parser.GetSchedule(exportParameters);
|
||||||
|
|
||||||
status.Text = resources.GetString("calendarExportStatus");
|
status.Text = resources.GetString("calendarExportStatus");
|
||||||
await Calendar.Export(schedule, addGroupToTitle.IsChecked.Value, (reminder.SelectedIndex - 1) * 5, ((ComboBoxItem)calendar.SelectedItem).Tag as string);
|
await Calendar.Export(schedule, addGroupToTitle.IsChecked.Value, (reminder.SelectedIndex - 1) * 5);
|
||||||
|
|
||||||
status.Text = resources.GetString("doneStatus");
|
status.Text = resources.GetString("doneStatus");
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
@@ -242,26 +223,6 @@ namespace GUTSchedule.UWP
|
|||||||
TopAppBar.Visibility = Visibility.Visible;
|
TopAppBar.Visibility = Visibility.Visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Clear(bool keepPrevious = true)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await Calendar.Clear(keepPrevious);
|
|
||||||
|
|
||||||
MessageDialog dialog = new MessageDialog(resources.GetString("clearScheduleDone"), resources.GetString("clearScheduleTitle"));
|
|
||||||
dialog.Commands.Add(new UICommand("OK", (command) => loading.Visibility = Visibility.Collapsed));
|
|
||||||
|
|
||||||
await dialog.ShowAsync();
|
|
||||||
}
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Faculty_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void Faculty_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
UpdateGroupsList();
|
UpdateGroupsList();
|
||||||
@@ -277,9 +238,6 @@ namespace GUTSchedule.UWP
|
|||||||
private void Reminder_SelectionChanged(object sender, SelectionChangedEventArgs e) =>
|
private void Reminder_SelectionChanged(object sender, SelectionChangedEventArgs e) =>
|
||||||
settings.Values["Reminder"] = reminder.SelectedIndex;
|
settings.Values["Reminder"] = reminder.SelectedIndex;
|
||||||
|
|
||||||
private void Calendar_SelectionChanged(object sender, SelectionChangedEventArgs e) =>
|
|
||||||
settings.Values["Calendar"] = (calendar.SelectedItem as ComboBoxItem).Tag;
|
|
||||||
|
|
||||||
private void Group_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void Group_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if(group.SelectedItem != null)
|
if(group.SelectedItem != null)
|
||||||
|
|||||||
@@ -47,6 +47,5 @@
|
|||||||
<Capabilities>
|
<Capabilities>
|
||||||
<Capability Name="internetClient" />
|
<Capability Name="internetClient" />
|
||||||
<uap:Capability Name="appointments"/>
|
<uap:Capability Name="appointments"/>
|
||||||
<rescap:Capability Name="appointmentSystem"/>
|
|
||||||
</Capabilities>
|
</Capabilities>
|
||||||
</Package>
|
</Package>
|
||||||
@@ -162,9 +162,18 @@
|
|||||||
<data name="clearScheduleMessage" xml:space="preserve">
|
<data name="clearScheduleMessage" xml:space="preserve">
|
||||||
<value>This action will purge exported schedule from all available calendars.
|
<value>This action will purge exported schedule from all available calendars.
|
||||||
It will affect only events created by the app.
|
It will affect only events created by the app.
|
||||||
'All' - will purge all timetable events including the past ones
|
'All' - will purge all timetable events including the past ones
|
||||||
'Upcoming' - will affect only upcoming timetable events</value>
|
'Upcoming' - will affect only upcoming timetable events</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="clearScheduleTitle.PrimaryButtonText" xml:space="preserve">
|
||||||
|
<value>Clear schedule</value>
|
||||||
|
</data>
|
||||||
|
<data name="clearScheduleTitle.SecondaryButtonText" xml:space="preserve">
|
||||||
|
<value>Cancel</value>
|
||||||
|
</data>
|
||||||
|
<data name="clearScheduleTitle.Title" xml:space="preserve">
|
||||||
|
<value>Clear schedule</value>
|
||||||
|
</data>
|
||||||
<data name="clearUpcoming.Content" xml:space="preserve">
|
<data name="clearUpcoming.Content" xml:space="preserve">
|
||||||
<value>Remove only upcoming events</value>
|
<value>Remove only upcoming events</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -258,6 +267,9 @@
|
|||||||
<data name="linksTitle.Text" xml:space="preserve">
|
<data name="linksTitle.Text" xml:space="preserve">
|
||||||
<value>Useful links</value>
|
<value>Useful links</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="loadingStatus" xml:space="preserve">
|
||||||
|
<value>Loading</value>
|
||||||
|
</data>
|
||||||
<data name="mySchedule" xml:space="preserve">
|
<data name="mySchedule" xml:space="preserve">
|
||||||
<value>My schedule</value>
|
<value>My schedule</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
@@ -162,9 +162,18 @@
|
|||||||
<data name="clearScheduleMessage" xml:space="preserve">
|
<data name="clearScheduleMessage" xml:space="preserve">
|
||||||
<value>Это действие удалит экспортированное расписание из всех доступных календарей.
|
<value>Это действие удалит экспортированное расписание из всех доступных календарей.
|
||||||
Данное действие затронет только расписание, экспортированное этим приложением
|
Данное действие затронет только расписание, экспортированное этим приложением
|
||||||
'Все' - удалит все события расписания, включая прошедшие
|
'Все' - удалит все события расписания, включая прошедшие
|
||||||
|
'Только новые' - удалит будущие события расписания</value>
|
||||||
|
</data>
|
||||||
|
<data name="clearScheduleTitle.PrimaryButtonText" xml:space="preserve">
|
||||||
|
<value>Очистить расписание</value>
|
||||||
|
</data>
|
||||||
|
<data name="clearScheduleTitle.SecondaryButtonText" xml:space="preserve">
|
||||||
<value>Отмена</value>
|
<value>Отмена</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="clearScheduleTitle.Title" xml:space="preserve">
|
||||||
|
<value>Очистка расписания</value>
|
||||||
|
</data>
|
||||||
<data name="clearUpcoming.Content" xml:space="preserve">
|
<data name="clearUpcoming.Content" xml:space="preserve">
|
||||||
<value>Удалить только будущие события</value>
|
<value>Удалить только будущие события</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -258,6 +267,9 @@
|
|||||||
<data name="linksTitle.Text" xml:space="preserve">
|
<data name="linksTitle.Text" xml:space="preserve">
|
||||||
<value>Полезные ссылки</value>
|
<value>Полезные ссылки</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="loadingStatus" xml:space="preserve">
|
||||||
|
<value>Загрузка</value>
|
||||||
|
</data>
|
||||||
<data name="mySchedule" xml:space="preserve">
|
<data name="mySchedule" xml:space="preserve">
|
||||||
<value>Мое расписание</value>
|
<value>Мое расписание</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
Reference in New Issue
Block a user