Skip to content

Commit

Permalink
Amend changes set by PR for Issues - #1 #2 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottBTR committed Oct 31, 2019
1 parent f8a17ca commit d58d862
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 67 deletions.
4 changes: 2 additions & 2 deletions Samples/Samples.iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
<key>NSLocationWhenInUseUsageDescription</key>
<string>Access to your location is required for cool things to happen!</string>
<key>NSCalendarsUsageDescription</key>
<string>Add calendar events</string>
<string>Access to view and create calendar events</string>
<key>NSRemindersUsageDescription</key>
<string>Add calendar events</string>
<string>Access to view and create reminders</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand Down
1 change: 0 additions & 1 deletion Samples/Samples.iOS/Samples.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<None Include="Entitlements.plist" />
Expand Down
8 changes: 2 additions & 6 deletions Samples/Samples/ViewModel/CalendarViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using Xamarin.Essentials;
using Xamarin.Forms;
Expand All @@ -10,8 +8,6 @@ namespace Samples.ViewModel
{
public class CalendarViewModel : BaseViewModel
{
// public ObservableCollection<Calendar> calendars;

public CalendarViewModel()
{
GetCalendars = new Command(OnClickGetCalendars);
Expand Down Expand Up @@ -45,11 +41,11 @@ async void OnRequestCalendarWriteAccess()
}
catch (PermissionException ex)
{
await DisplayAlertAsync($"Unable to request calendar read access: {ex.Message}");
await DisplayAlertAsync($"Unable to request calendar write access: {ex.Message}");
}
catch (Exception ex)
{
await DisplayAlertAsync($"Unable to request calendar read access: {ex.Message}");
await DisplayAlertAsync($"Unable to request calendar write access: {ex.Message}");
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/Calendar_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Tests
public class Calendar_Tests
{
[Fact]
public async Task Calendar_IsSupported_Fail_On_NetStandard() =>
await Assert.ThrowsAsync<NotImplementedInReferenceAssemblyException>(() => Task.FromResult<bool>(Calendar.PlatformIsSupported));
public void Calendar_IsSupported_Fail_On_NetStandard() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => Calendar.IsSupported);
}
}
20 changes: 10 additions & 10 deletions Xamarin.Essentials/Calendar/Calendar.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Xamarin.Essentials
{
public static partial class Calendar
{
public static bool PlatformIsSupported => true;
static bool PlatformIsSupported => true;

public static async Task<IReadOnlyList<ICalendar>> PlatformGetCalendarsAsync()
static async Task<IReadOnlyList<ICalendar>> PlatformGetCalendarsAsync()
{
await Permissions.RequireAsync(PermissionType.CalendarRead);

Expand All @@ -28,29 +28,29 @@ public static async Task<IReadOnlyList<ICalendar>> PlatformGetCalendarsAsync()
{
Id = cur.GetString(calendarsProjection.IndexOf(CalendarContract.Calendars.InterfaceConsts.Id)),
Name = cur.GetString(calendarsProjection.IndexOf(CalendarContract.Calendars.InterfaceConsts.CalendarDisplayName)),
IsReadOnly = IsCalendarReadOnly(cur.GetInt(calendarsProjection.IndexOf(CalendarContract.Calendars.InterfaceConsts.CalendarAccessLevel)))
IsReadOnly = IsCalendarReadOnly((CalendarAccess)cur.GetInt(calendarsProjection.IndexOf(CalendarContract.Calendars.InterfaceConsts.CalendarAccessLevel)))
});
}

return calendars.AsReadOnly();
}

static bool IsCalendarReadOnly(int accessLevel)
static bool IsCalendarReadOnly(CalendarAccess accessLevel)
{
switch (accessLevel)
{
case (int)CalendarAccess.AccessContributor:
case (int)CalendarAccess.AccessRoot:
case (int)CalendarAccess.AccessOwner:
case (int)CalendarAccess.AccessEditor:
case CalendarAccess.AccessContributor:
case CalendarAccess.AccessRoot:
case CalendarAccess.AccessOwner:
case CalendarAccess.AccessEditor:
return false;
default:
return true;
}
}

public static async Task PlatformRequestCalendarReadAccess() => await Permissions.RequireAsync(PermissionType.CalendarRead);
static async Task PlatformRequestCalendarReadAccess() => await Permissions.RequireAsync(PermissionType.CalendarRead);

public static async Task PlatformRequestCalendarWriteAccess() => await Permissions.RequireAsync(PermissionType.CalendarWrite);
static async Task PlatformRequestCalendarWriteAccess() => await Permissions.RequireAsync(PermissionType.CalendarWrite);
}
}
17 changes: 4 additions & 13 deletions Xamarin.Essentials/Calendar/Calendar.ios.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using EventKit;
using Foundation;
using UIKit;

namespace Xamarin.Essentials
{
public static partial class Calendar
{
public static bool PlatformIsSupported => true;
static bool PlatformIsSupported => true;

public static async Task<IReadOnlyList<ICalendar>> PlatformGetCalendarsAsync()
static async Task<IReadOnlyList<ICalendar>> PlatformGetCalendarsAsync()
{
await Permissions.RequireAsync(PermissionType.CalendarRead);

Expand All @@ -25,23 +22,17 @@ public static async Task<IReadOnlyList<ICalendar>> PlatformGetCalendarsAsync()
Name = t.Title,
IsReadOnly = !t.AllowsContentModifications
});
/*
To get Events:
var mySavedEvent = CalendarRequest.Instance.EventFromIdentifier(t.CalendarIdentifier);
*/
}
return calendarList.AsReadOnly();
}

public static async Task PlatformRequestCalendarReadAccess()
static async Task PlatformRequestCalendarReadAccess()
{
await Permissions.RequireAsync(PermissionType.CalendarRead);
await Permissions.RequireAsync(PermissionType.CalendarWrite);
}

public static async Task PlatformRequestCalendarWriteAccess()
static async Task PlatformRequestCalendarWriteAccess()
{
await Permissions.RequireAsync(PermissionType.CalendarRead);
await Permissions.RequireAsync(PermissionType.CalendarWrite);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ namespace Xamarin.Essentials
{
public static partial class Calendar
{
public static bool PlatformIsSupported => false;
static bool PlatformIsSupported => false;

public static Task<IReadOnlyList<ICalendar>> PlatformGetCalendarsAsync() => throw new NotImplementedException();
static Task<IReadOnlyList<ICalendar>> PlatformGetCalendarsAsync() => throw new NotImplementedException();

public static Task PlatformRequestCalendarReadAccess() => throw new NotImplementedException();
static Task PlatformRequestCalendarReadAccess() => throw new NotImplementedException();

public static Task PlatformRequestCalendarWriteAccess() => throw new NotImplementedException();
static Task PlatformRequestCalendarWriteAccess() => throw new NotImplementedException();
}
}
6 changes: 2 additions & 4 deletions Xamarin.Essentials/Calendar/Calendar.shared.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Xamarin.Essentials
{
public static partial class Calendar
{
// public static List<Calendar> CalendarList { get; set; }
public static bool IsSupported()
public static bool IsSupported
=> PlatformIsSupported;

public static Task<IReadOnlyList<ICalendar>> GetCalendarsAsync()
Expand Down
2 changes: 0 additions & 2 deletions Xamarin.Essentials/Calendar/CalendarRequest.ios.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using EventKit;

namespace Xamarin.Essentials
Expand Down
6 changes: 0 additions & 6 deletions Xamarin.Essentials/GlobalSuppressions.cs

This file was deleted.

6 changes: 0 additions & 6 deletions Xamarin.Essentials/GlobalSuppressions2.cs

This file was deleted.

8 changes: 1 addition & 7 deletions Xamarin.Essentials/Permissions/Permissions.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,7 @@ static Task<PermissionStatus> RequestCalendarAsync()
EKEntityType.Event,
(bool granted, NSError e) =>
{
if (granted)
{
}
else
{
throw new PermissionException($"{e} was not granted.");
}
tcs.SetResult(granted ? PermissionStatus.Granted : PermissionStatus.Denied);
});
return tcs.Task;
}
Expand Down
4 changes: 0 additions & 4 deletions Xamarin.Essentials/Types/DeviceCalendar.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public class DeviceCalendar : ICalendar
public string Name { get; set; }

public bool IsReadOnly { get; set; }

// public List<Event> EventList { get; set; }
}

public interface ICalendar
Expand Down Expand Up @@ -84,8 +82,6 @@ public class Attendee
public string Name { get; set; }

public string Email { get; set; }

// public IAttendeeDetails AttendeeDetails => DeviceSpecificAttendeeDetails;
}

public interface IAttendeeDetails
Expand Down

0 comments on commit d58d862

Please sign in to comment.