-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a970bec
commit e8d1272
Showing
25 changed files
with
388 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace MauiBells.Calendar; | ||
|
||
public partial class CalendarHandler | ||
{ | ||
public static IPropertyMapper<ICalendarView, CalendarHandler> PropertyMapper = new PropertyMapper<ICalendarView, CalendarHandler>(ViewMapper) | ||
{ | ||
[nameof(ICalendarView.FirstDayOfWeek)] = MapFirstDayOfWeek, | ||
[nameof(ICalendarView.MinDate)] = MapMinDate, | ||
[nameof(ICalendarView.MaxDate)] = MapMaxDate, | ||
[nameof(ICalendarView.SelectedDate)] = MapSelectedDate, | ||
}; | ||
|
||
public static CommandMapper<ICalendarView, CalendarHandler> CommandMapper = new(ViewCommandMapper); | ||
|
||
public CalendarHandler(IPropertyMapper mapper, CommandMapper? commandMapper = null) : base(mapper, commandMapper) | ||
{ | ||
} | ||
|
||
public CalendarHandler() : this(PropertyMapper, CommandMapper) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
namespace MauiBells.Calendar; | ||
|
||
using System.ComponentModel; | ||
|
||
public class CalendarView : View, ICalendarView | ||
{ | ||
readonly WeakEventManager calendarViewEventManager = new(); | ||
|
||
public static readonly BindableProperty FirstDayOfWeekProperty = BindableProperty.Create(nameof(FirstDayOfWeek), typeof(DayOfWeek), typeof(CalendarView), default(DayOfWeek)); | ||
public static readonly BindableProperty MinDateProperty = BindableProperty.Create(nameof(MinDate), typeof(DateTimeOffset), typeof(CalendarView), DateTimeOffset.MinValue); | ||
public static readonly BindableProperty MaxDateProperty = BindableProperty.Create(nameof(MaxDate), typeof(DateTimeOffset), typeof(CalendarView), DateTimeOffset.MaxValue); | ||
public static readonly BindableProperty SelectedDateProperty = BindableProperty.Create(nameof(SelectedDate), typeof(DateTimeOffset?), typeof(CalendarView)); | ||
|
||
public DayOfWeek FirstDayOfWeek | ||
{ | ||
get => (DayOfWeek)GetValue(FirstDayOfWeekProperty); | ||
set => SetValue(FirstDayOfWeekProperty, value); | ||
} | ||
|
||
[TypeConverter(typeof(DateTimeOffsetStringConverter))] | ||
public DateTimeOffset MinDate | ||
{ | ||
get => (DateTimeOffset)GetValue(MinDateProperty); | ||
set => SetValue(MinDateProperty, value); | ||
} | ||
|
||
[TypeConverter(typeof(DateTimeOffsetStringConverter))] | ||
public DateTimeOffset MaxDate | ||
{ | ||
get => (DateTimeOffset)GetValue(MaxDateProperty); | ||
set => SetValue(MaxDateProperty, value); | ||
} | ||
|
||
[TypeConverter(typeof(DateTimeOffsetStringConverter))] | ||
public DateTimeOffset? SelectedDate | ||
{ | ||
get => (DateTimeOffset?)GetValue(SelectedDateProperty); | ||
set => SetValue(SelectedDateProperty, value); | ||
} | ||
|
||
public event EventHandler<SelectedDateChangedEventArgs> SelectedDateChanged | ||
{ | ||
add => calendarViewEventManager.AddEventHandler(value); | ||
remove => calendarViewEventManager.RemoveEventHandler(value); | ||
} | ||
|
||
void ICalendarView.OnSelectedDateChanged(DateTimeOffset? selectedDate) | ||
{ | ||
calendarViewEventManager.HandleEvent(this, new SelectedDateChangedEventArgs(selectedDate), nameof(SelectedDateChanged)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace MauiBells.Calendar; | ||
|
||
using System.ComponentModel; | ||
using System.Globalization; | ||
|
||
public class DateTimeOffsetStringConverter : TypeConverter | ||
{ | ||
public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value) | ||
{ | ||
if (value is string valueString) | ||
{ | ||
return DateTimeOffset.Parse(valueString); | ||
} | ||
|
||
return DateTimeOffset.MinValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace MauiBells.Calendar; | ||
|
||
public interface ICalendarView : IView | ||
{ | ||
DayOfWeek FirstDayOfWeek { get; } | ||
DateTimeOffset MinDate { get; } | ||
DateTimeOffset MaxDate { get; } | ||
DateTimeOffset? SelectedDate { get; set; } | ||
void OnSelectedDateChanged(DateTimeOffset? selectedDate); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace MauiBells.Calendar; | ||
|
||
public class SelectedDateChangedEventArgs(DateTimeOffset? selectedDate) : EventArgs | ||
{ | ||
public DateTimeOffset? SelectedDate { get; } = selectedDate; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
namespace MauiBells.Calendar; | ||
|
||
using Microsoft.Maui.Handlers; | ||
using Calendar = Android.Widget.CalendarView; | ||
|
||
public partial class CalendarHandler : ViewHandler<ICalendarView, Calendar> | ||
{ | ||
protected override Calendar CreatePlatformView() | ||
{ | ||
return new Calendar(Context); | ||
} | ||
protected override void ConnectHandler(Calendar platformView) | ||
{ | ||
base.ConnectHandler(platformView); | ||
platformView.DateChange += PlatformView_SelectedDatesChanged; | ||
} | ||
|
||
private void PlatformView_SelectedDatesChanged(object? sender, Calendar.DateChangeEventArgs e) | ||
{ | ||
PlatformView.DateChange -= PlatformView_SelectedDatesChanged; | ||
VirtualView.SelectedDate = new DateTime(e.Year, e.Month + 1, e.DayOfMonth, 0,0,0); | ||
VirtualView.OnSelectedDateChanged(VirtualView.SelectedDate); | ||
PlatformView.DateChange += PlatformView_SelectedDatesChanged; | ||
} | ||
|
||
protected override void DisconnectHandler(Calendar platformView) | ||
{ | ||
platformView.DateChange -= PlatformView_SelectedDatesChanged; | ||
base.DisconnectHandler(platformView); | ||
} | ||
|
||
private static void MapFirstDayOfWeek(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
handler.PlatformView.FirstDayOfWeek = (int)virtualView.FirstDayOfWeek; | ||
} | ||
|
||
private static void MapMinDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
handler.PlatformView.MinDate = virtualView.MinDate.ToUnixTimeMilliseconds(); | ||
} | ||
|
||
private static void MapMaxDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
handler.PlatformView.MaxDate = virtualView.MaxDate.ToUnixTimeMilliseconds(); | ||
} | ||
|
||
private static void MapSelectedDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
if (virtualView.SelectedDate is null) | ||
{ | ||
return; | ||
} | ||
|
||
handler.PlatformView.SetDate(virtualView.SelectedDate.Value.ToUnixTimeMilliseconds(), true, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace MauiBells.Calendar; | ||
|
||
using Microsoft.Maui.Handlers; | ||
using UIKit; | ||
|
||
public partial class CalendarHandler : ViewHandler<ICalendarView, UICalendarView> | ||
{ | ||
protected override UICalendarView CreatePlatformView() | ||
{ | ||
return new UICalendarView(); | ||
} | ||
|
||
private static void MapFirstDayOfWeek(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
} | ||
private static void MapMinDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
} | ||
|
||
private static void MapMaxDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
} | ||
|
||
private static void MapSelectedDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
using UIKit; | ||
namespace MauiBells; | ||
|
||
namespace MauiBells; | ||
using UIKit; | ||
|
||
public class Program | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace MauiBells.Calendar; | ||
|
||
using Microsoft.Maui.Handlers; | ||
|
||
public partial class CalendarHandler : ViewHandler<ICalendarView, CalendarView> | ||
{ | ||
protected override CalendarView CreatePlatformView() | ||
{ | ||
return new CalendarView(); | ||
} | ||
|
||
private static void MapFirstDayOfWeek(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
} | ||
private static void MapMinDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
} | ||
|
||
private static void MapMaxDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
} | ||
|
||
private static void MapSelectedDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
} | ||
} |
Oops, something went wrong.