diff --git a/GUT.Schedule/GUTSchedule.Droid/Resources/values/strings.xml b/GUT.Schedule/GUTSchedule.Droid/Resources/values/strings.xml index 2ac0657..559620c 100644 --- a/GUT.Schedule/GUTSchedule.Droid/Resources/values/strings.xml +++ b/GUT.Schedule/GUTSchedule.Droid/Resources/values/strings.xml @@ -37,7 +37,7 @@ For semester Set reminders for - (i) Attention, for cloud-based Google calendars Google automatically sets reminders for 30 minutes if there\'s no reminder set by user + (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 None At the start of event 5 minutes diff --git a/GUT.Schedule/GUTSchedule.UWP/Calendar.cs b/GUT.Schedule/GUTSchedule.UWP/Calendar.cs index 2f0192a..b10e01d 100644 --- a/GUT.Schedule/GUTSchedule.UWP/Calendar.cs +++ b/GUT.Schedule/GUTSchedule.UWP/Calendar.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Collections.Generic; using System.Threading.Tasks; using Windows.ApplicationModel.Appointments; +using Windows.ApplicationModel.Resources; namespace GUTSchedule.UWP { @@ -11,21 +12,24 @@ namespace GUTSchedule.UWP { public static async Task> GetCalendars() { - AppointmentStore calendarStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadWrite); + AppointmentStore calendarStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AppCalendarsReadWrite); return await calendarStore.FindAppointmentCalendarsAsync(); } - public static async Task Export(List schedule, bool addGroupToTitle, int reminder, string calendar) + public static async Task Export(List schedule, bool addGroupToTitle, int reminder) { 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) { Appointment appointment = new Appointment { BusyStatus = AppointmentBusyStatus.Busy, - Details = item.Opponent + "\xFEFF", + Details = item.Opponent, DetailsKind = AppointmentDetailsKind.PlainText, Location = item.Cabinet, 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 targets, bool keepPrevious) { - AppointmentStore appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AppCalendarsReadWrite); - - List appointments = (await appointmentStore.FindAppointmentsAsync(keepPrevious ? DateTime.Today : DateTime.Today.Subtract(TimeSpan.FromDays(3000)), TimeSpan.FromDays(10000))).ToList(); - - foreach(Appointment i in appointments) - if (i.Details.Contains('\xFEFF')) - { - AppointmentCalendar cal = await appointmentStore.GetAppointmentCalendarAsync(i.CalendarId); - await cal.DeleteAppointmentAsync(i.LocalId); - } + foreach (AppointmentCalendar calendar in targets) + if(keepPrevious) + foreach (Appointment appointment in await calendar.FindAppointmentsAsync(DateTime.Now, TimeSpan.FromDays(365))) + await calendar.DeleteAppointmentAsync(appointment.LocalId); + else + await calendar.DeleteAsync(); } } } diff --git a/GUT.Schedule/GUTSchedule.UWP/ClearCalendarControl.xaml b/GUT.Schedule/GUTSchedule.UWP/ClearCalendarControl.xaml new file mode 100644 index 0000000..2a8ca7c --- /dev/null +++ b/GUT.Schedule/GUTSchedule.UWP/ClearCalendarControl.xaml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/GUT.Schedule/GUTSchedule.UWP/ClearCalendarControl.xaml.cs b/GUT.Schedule/GUTSchedule.UWP/ClearCalendarControl.xaml.cs new file mode 100644 index 0000000..9ae3401 --- /dev/null +++ b/GUT.Schedule/GUTSchedule.UWP/ClearCalendarControl.xaml.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using Windows.UI.Xaml.Controls; + +namespace GUTSchedule.UWP +{ + public sealed partial class ClearCalendarControl : ContentDialog + { + public IEnumerable 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(); + } +} \ No newline at end of file diff --git a/GUT.Schedule/GUTSchedule.UWP/GUTSchedule.UWP.csproj b/GUT.Schedule/GUTSchedule.UWP/GUTSchedule.UWP.csproj index e4ddc49..1f42fee 100644 --- a/GUT.Schedule/GUTSchedule.UWP/GUTSchedule.UWP.csproj +++ b/GUT.Schedule/GUTSchedule.UWP/GUTSchedule.UWP.csproj @@ -131,6 +131,9 @@ App.xaml + + ClearCalendarControl.xaml + MainPage.xaml @@ -200,6 +203,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + MSBuild:Compile Designer diff --git a/GUT.Schedule/GUTSchedule.UWP/MainPage.xaml b/GUT.Schedule/GUTSchedule.UWP/MainPage.xaml index d4e27db..e5a3067 100644 --- a/GUT.Schedule/GUTSchedule.UWP/MainPage.xaml +++ b/GUT.Schedule/GUTSchedule.UWP/MainPage.xaml @@ -114,8 +114,6 @@ - -