Skip to content

Commit 2fc44d9

Browse files
tborozanAntonioSeric
and
AntonioSeric
authored
Implemented OneWeekView and TwoWeeksView (lilcodelab#106)
* implemented OneWeekView and TwoWeeksView * updated ReadMe.md * monthView number of weeks extracted to const * extracted number of days in a week to const * removed shown date switching after delay * fix event view Co-authored-by: AntonioSeric <[email protected]>
1 parent 4df8995 commit 2fc44d9

36 files changed

+1421
-722
lines changed

Diff for: README.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ xmlns:controls="clr-namespace:Xamarin.Plugin.Calendar.Controls;assembly=Xamarin.
5353
Basic control usage:
5454
```xml
5555
<controls:Calendar
56+
Day="14"
5657
Month="5"
5758
Year="2019"
5859
VerticalOptions="FillAndExpand"
@@ -61,11 +62,21 @@ Basic control usage:
6162

6263
Bindable properties:
6364
* `Culture` _CultureInfo_ calender culture/language
65+
* `Day` _int_ currently viewing day
6466
* `Month` _int_ currently viewing month
6567
* `Year` _int_ currently viewing year
6668
* `Events` _EventCollection_ (from package) your events for calender
6769
* Custom colors, fonts, sizes ...
6870

71+
72+
__Remark: You can use `ShownDate` as an alternative to `Year`, `Month` and `Day`__
73+
```xml
74+
<controls:Calendar
75+
ShownDate="2019-05-14"
76+
VerticalOptions="FillAndExpand"
77+
HorizontalOptions="FillAndExpand">
78+
```
79+
6980
#### Binding events:
7081
In your XAML, add the data template for events, and bind the events collection, example:
7182
```xml
@@ -189,6 +200,28 @@ TodayTextColor="Yellow"
189200

190201
#### Available customization properties
191202

203+
##### Calendar Layout customizations
204+
You can set the layout of the calendar with property `CalendarLayout`
205+
206+
- Available layouts are:
207+
208+
`OneWeek` - only one week is shown
209+
210+
`TwoWeeks` - two weeks are shown
211+
212+
`Month` - whole month is shown (default value)
213+
214+
```xml
215+
CalendarLayout="Month"
216+
```
217+
218+
You can also choose to display the shown week number instead of month name
219+
220+
```xml
221+
CalendarLayout="Week"
222+
WeekViewUnit="WeekNumber"
223+
```
224+
192225
##### Event indicator customizations
193226
You can customize how will look event indication with property `EventIndicatorType`
194227

@@ -201,7 +234,6 @@ You can customize how will look event indication with property `EventIndicatorTy
201234
```xml
202235
EventIndicatorType="Background"
203236
```
204-
205237
##### Calendar swipe customizations
206238
You can write your own customizations commands for swipe.
207239
```xml

Diff for: src/Calendar.Plugin.Sample/SampleApp/Controls/CalendarHeader.xaml

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Margin="0,2"
99
Padding="0"
1010
HorizontalOptions="FillAndExpand"
11-
IsVisible="{Binding ShowMonthPicker}"
11+
IsVisible="{Binding ShowLayoutUnitPicker}"
1212
VerticalOptions="Start">
1313
<Grid.RowDefinitions>
1414
<RowDefinition Height="Auto" />
@@ -43,7 +43,7 @@
4343
VerticalTextAlignment="Center" />
4444

4545
<Frame.GestureRecognizers>
46-
<TapGestureRecognizer Command="{Binding PrevMonthCommand}" />
46+
<TapGestureRecognizer Command="{Binding PrevLayoutUnitCommand}" />
4747
</Frame.GestureRecognizers>
4848
</Frame>
4949

@@ -52,16 +52,15 @@
5252
FontAttributes="Bold"
5353
FontSize="Medium"
5454
HorizontalOptions="Center"
55-
TextColor="{Binding MonthLabelColor}"
55+
TextColor="{Binding LayoutUnitLabelColor}"
5656
VerticalOptions="Center">
5757
<Label.FormattedText>
5858
<FormattedString>
59-
<Span Text="{Binding MonthText, Mode=TwoWay}" />
59+
<Span Text="{Binding LayoutUnitText, Mode=TwoWay}" />
6060
<Span Text=", " />
6161
<Span Text="{Binding Year, Mode=TwoWay}" />
6262
</FormattedString>
6363
</Label.FormattedText>
64-
6564
</Label>
6665

6766
<Frame
@@ -88,8 +87,8 @@
8887
VerticalTextAlignment="Center" />
8988

9089
<Frame.GestureRecognizers>
91-
<TapGestureRecognizer Command="{Binding NextMonthCommand}" />
90+
<TapGestureRecognizer Command="{Binding NextLayoutUnitCommand}" />
9291
</Frame.GestureRecognizers>
9392
</Frame>
9493
</Grid>
95-
</DataTemplate>
94+
</DataTemplate>
+56-51
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,64 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
5-
<ProduceAssemblyReference>true</ProduceAssemblyReference>
6-
<LangVersion>latest</LangVersion>
7-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<ProduceAssemblyReference>true</ProduceAssemblyReference>
6+
<LangVersion>latest</LangVersion>
7+
</PropertyGroup>
88

9-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
10-
<DebugType>portable</DebugType>
11-
<DebugSymbols>true</DebugSymbols>
12-
<DefineConstants>DEBUG;TRACE</DefineConstants>
13-
</PropertyGroup>
9+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
10+
<DebugType>portable</DebugType>
11+
<DebugSymbols>true</DebugSymbols>
12+
<DefineConstants>DEBUG;TRACE</DefineConstants>
13+
</PropertyGroup>
1414

15-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
16-
<DebugType>none</DebugType>
17-
<DebugSymbols>false</DebugSymbols>
18-
</PropertyGroup>
15+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
16+
<DebugType>none</DebugType>
17+
<DebugSymbols>false</DebugSymbols>
18+
</PropertyGroup>
1919

20-
<ItemGroup>
21-
<PackageReference Include="Rg.Plugins.Popup" Version="2.0.0.12" />
22-
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" />
23-
</ItemGroup>
20+
<ItemGroup>
21+
<PackageReference Include="Rg.Plugins.Popup" Version="2.0.0.12" />
22+
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" />
23+
</ItemGroup>
2424

25-
<ItemGroup>
26-
<ProjectReference Include="..\..\Calendar.Plugin\CalendarPlugin.csproj" />
27-
</ItemGroup>
25+
<ItemGroup>
26+
<ProjectReference Include="..\..\Calendar.Plugin\CalendarPlugin.csproj" />
27+
</ItemGroup>
2828

29-
<ItemGroup>
30-
<Compile Update="Views\RangeSelectionPage.xaml.cs">
31-
<DependentUpon>RangeSelectionPage.xaml</DependentUpon>
32-
</Compile>
33-
</ItemGroup>
29+
<ItemGroup>
30+
<Compile Update="Views\RangeSelectionPage.xaml.cs">
31+
<DependentUpon>RangeSelectionPage.xaml</DependentUpon>
32+
</Compile>
33+
</ItemGroup>
3434

35-
<ItemGroup>
36-
<EmbeddedResource Update="Controls\CalendarFooter.xaml">
37-
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
38-
</EmbeddedResource>
39-
<EmbeddedResource Update="Views\CalendarRangePickerPopupSelectedDates.xaml">
40-
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
41-
</EmbeddedResource>
42-
<EmbeddedResource Update="Views\MainPage.xaml">
43-
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
44-
</EmbeddedResource>
45-
<EmbeddedResource Update="Views\RangeSelectionPage.xaml">
46-
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
47-
</EmbeddedResource>
48-
<EmbeddedResource Update="Views\CalendarPickerPopup.xaml">
49-
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
50-
</EmbeddedResource>
51-
<EmbeddedResource Update="Views\SimplePage.xaml">
52-
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
53-
</EmbeddedResource>
54-
<EmbeddedResource Update="Views\AdvancedPage.xaml">
55-
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
56-
</EmbeddedResource>
57-
</ItemGroup>
58-
59-
</Project>
35+
<ItemGroup>
36+
<EmbeddedResource Update="Controls\CalendarFooter.xaml">
37+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
38+
</EmbeddedResource>
39+
<EmbeddedResource Update="Views\CalendarRangePickerPopupSelectedDates.xaml">
40+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
41+
</EmbeddedResource>
42+
<EmbeddedResource Update="Views\MainPage.xaml">
43+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
44+
</EmbeddedResource>
45+
<EmbeddedResource Update="Views\RangeSelectionPage.xaml">
46+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
47+
</EmbeddedResource>
48+
<EmbeddedResource Update="Views\CalendarPickerPopup.xaml">
49+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
50+
</EmbeddedResource>
51+
<EmbeddedResource Update="Views\SimplePage.xaml">
52+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
53+
</EmbeddedResource>
54+
<EmbeddedResource Update="Views\AdvancedPage.xaml">
55+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
56+
</EmbeddedResource>
57+
<EmbeddedResource Update="Views\TwoWeekViewPage.xaml">
58+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
59+
</EmbeddedResource>
60+
<EmbeddedResource Update="Views\WeekViewPage.xaml">
61+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
62+
</EmbeddedResource>
63+
</ItemGroup>
64+
</Project>

Diff for: src/Calendar.Plugin.Sample/SampleApp/ViewModels/AdvancedPageViewModel.cs

+72-35
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
using Xamarin.Plugin.Calendar.Models;
1+
using SampleApp.Model;
22
using System;
33
using System.Collections.Generic;
4+
using System.Collections.ObjectModel;
45
using System.Globalization;
5-
using System.Threading.Tasks;
66
using System.Linq;
7-
using System.Collections.ObjectModel;
7+
using System.Threading.Tasks;
88
using System.Windows.Input;
99
using Xamarin.Forms;
10-
using SampleApp.Model;
10+
using Xamarin.Plugin.Calendar.Enums;
11+
using Xamarin.Plugin.Calendar.Models;
1112

1213
namespace SampleApp.ViewModels
1314
{
1415
public class AdvancedPageViewModel : BasePageViewModel
1516
{
1617
public ICommand DayTappedCommand => new Command<DateTime>(async (date) => await DayTapped(date));
17-
public ICommand SwipeLeftCommand => new Command(() => { MonthYear = MonthYear.AddMonths(2); });
18-
public ICommand SwipeRightCommand => new Command(() => { MonthYear = MonthYear.AddMonths(-2); });
19-
public ICommand SwipeUpCommand => new Command(() => { MonthYear = DateTime.Today; });
18+
public ICommand SwipeLeftCommand => new Command(() => ChangeShownUnit(1));
19+
public ICommand SwipeRightCommand => new Command(() => ChangeShownUnit(-1));
20+
public ICommand SwipeUpCommand => new Command(() => { ShownDate = DateTime.Today; });
2021

2122
public ICommand EventSelectedCommand => new Command(async (item) => await ExecuteEventSelectedCommand(item));
2223

2324
public AdvancedPageViewModel() : base()
2425
{
26+
Device.BeginInvokeOnMainThread(async () => await App.Current.MainPage.DisplayAlert("Info", "Loading events with delay, and changeing current view.", "Ok"));
27+
2528
Culture = CultureInfo.CreateSpecificCulture("en-GB");
2629
// testing all kinds of adding events
2730
// when initializing collection
@@ -46,36 +49,34 @@ public AdvancedPageViewModel() : base()
4649
// with indexer
4750
Events[DateTime.Now] = new List<AdvancedEventModel>(GenerateEvents(2, "Boring"));
4851

49-
MonthYear = MonthYear.AddMonths(1);
50-
51-
Task.Delay(5000).ContinueWith( _ =>
52-
{
53-
// indexer - update later
54-
Events[DateTime.Now] = new ObservableCollection<AdvancedEventModel>(GenerateEvents(10, "Cool"));
55-
56-
// add later
57-
Events.Add(DateTime.Now.AddDays(3), new List<AdvancedEventModel>(GenerateEvents(5, "Cool")));
52+
ShownDate = ShownDate.AddMonths(1);
5853

59-
// indexer later
60-
Events[DateTime.Now.AddDays(10)] = new List<AdvancedEventModel>(GenerateEvents(10, "Boring"));
54+
Task.Delay(5000).ContinueWith(_ =>
55+
{
56+
// indexer - update later
57+
Events[DateTime.Now] = new ObservableCollection<AdvancedEventModel>(GenerateEvents(10, "Cool"));
6158

62-
// add later
63-
Events.Add(DateTime.Now.AddDays(15), new List<AdvancedEventModel>(GenerateEvents(10, "Cool")));
59+
// add later
60+
Events.Add(DateTime.Now.AddDays(3), new List<AdvancedEventModel>(GenerateEvents(5, "Cool")));
6461

62+
// indexer later
63+
Events[DateTime.Now.AddDays(10)] = new List<AdvancedEventModel>(GenerateEvents(10, "Boring"));
6564

66-
Task.Delay(3000).ContinueWith(t =>
67-
{
68-
MonthYear = MonthYear.AddMonths(-2);
65+
// add later
66+
Events.Add(DateTime.Now.AddDays(15), new List<AdvancedEventModel>(GenerateEvents(10, "Cool")));
6967

70-
// get observable collection later
71-
var todayEvents = Events[DateTime.Now] as ObservableCollection<AdvancedEventModel>;
68+
Task.Delay(3000).ContinueWith(t =>
69+
{
70+
ShownDate = ShownDate.AddMonths(-2);
7271

73-
// insert/add items to observable collection
74-
todayEvents.Insert(0, new AdvancedEventModel { Name = "Cool event insert", Description = "This is Cool event's description!", Starting = new DateTime() });
75-
todayEvents.Add(new AdvancedEventModel { Name = "Cool event add", Description = "This is Cool event's description!", Starting = new DateTime() });
72+
// get observable collection later
73+
var todayEvents = Events[DateTime.Now] as ObservableCollection<AdvancedEventModel>;
7674

77-
}, TaskScheduler.FromCurrentSynchronizationContext());
78-
}, TaskScheduler.FromCurrentSynchronizationContext());
75+
// insert/add items to observable collection
76+
todayEvents.Insert(0, new AdvancedEventModel { Name = "Cool event insert", Description = "This is Cool event's description!", Starting = new DateTime() });
77+
todayEvents.Add(new AdvancedEventModel { Name = "Cool event add", Description = "This is Cool event's description!", Starting = new DateTime() });
78+
}, TaskScheduler.FromCurrentSynchronizationContext());
79+
}, TaskScheduler.FromCurrentSynchronizationContext());
7980

8081
SelectedDate = DateTime.Today.AddDays(10);
8182
}
@@ -92,22 +93,32 @@ private IEnumerable<AdvancedEventModel> GenerateEvents(int count, string name)
9293

9394
public EventCollection Events { get; }
9495

95-
private DateTime _monthYear = DateTime.Today;
96-
public DateTime MonthYear
96+
private DateTime _shownDate = DateTime.Today;
97+
98+
public DateTime ShownDate
99+
{
100+
get => _shownDate;
101+
set => SetProperty(ref _shownDate, value);
102+
}
103+
104+
private WeekLayout _calendarLayout = WeekLayout.Month;
105+
106+
public WeekLayout CalendarLayout
97107
{
98-
get => _monthYear;
99-
set => SetProperty(ref _monthYear, value);
108+
get => _calendarLayout;
109+
set => SetProperty(ref _calendarLayout, value);
100110
}
101111

102112
private DateTime? _selectedDate = DateTime.Today;
113+
103114
public DateTime? SelectedDate
104115
{
105116
get => _selectedDate;
106117
set => SetProperty(ref _selectedDate, value);
107118
}
108119

109-
110120
private CultureInfo _culture = CultureInfo.InvariantCulture;
121+
111122
public CultureInfo Culture
112123
{
113124
get => _culture;
@@ -129,5 +140,31 @@ private async Task ExecuteEventSelectedCommand(object item)
129140
await App.Current.MainPage.DisplayAlert(title, message, "Ok");
130141
}
131142
}
143+
144+
private void ChangeShownUnit(int amountToAdd)
145+
{
146+
switch (CalendarLayout)
147+
{
148+
case WeekLayout.Week:
149+
case WeekLayout.TwoWeek:
150+
ChangeShownWeek(amountToAdd);
151+
break;
152+
153+
case WeekLayout.Month:
154+
default:
155+
ChangeShownMonth(amountToAdd);
156+
break;
157+
}
158+
}
159+
160+
private void ChangeShownMonth(int monthsToAdd)
161+
{
162+
ShownDate.AddMonths(monthsToAdd);
163+
}
164+
165+
private void ChangeShownWeek(int weeksToAdd)
166+
{
167+
ShownDate.AddDays(weeksToAdd * 7);
168+
}
132169
}
133170
}

0 commit comments

Comments
 (0)