Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented OneWeekView and TwoWeeksView #106

Merged
merged 6 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ xmlns:controls="clr-namespace:Xamarin.Plugin.Calendar.Controls;assembly=Xamarin.
Basic control usage:
```xml
<controls:Calendar
Day="14"
Month="5"
Year="2019"
VerticalOptions="FillAndExpand"
Expand All @@ -61,11 +62,21 @@ Basic control usage:

Bindable properties:
* `Culture` _CultureInfo_ calender culture/language
* `Day` _int_ currently viewing day
* `Month` _int_ currently viewing month
* `Year` _int_ currently viewing year
* `Events` _EventCollection_ (from package) your events for calender
* Custom colors, fonts, sizes ...


__Remark: You can use `ShownDate` as an alternative to `Year`, `Month` and `Day`__
```xml
<controls:Calendar
ShownDate="2019-05-14"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand">
```

#### Binding events:
In your XAML, add the data template for events, and bind the events collection, example:
```xml
Expand Down Expand Up @@ -189,6 +200,28 @@ TodayTextColor="Yellow"

#### Available customization properties

##### Calendar Layout customizations
You can set the layout of the calendar with property `CalendarLayout`

- Available layouts are:

`OneWeek` - only one week is shown

`TwoWeeks` - two weeks are shown

`Month` - whole month is shown (default value)

```xml
CalendarLayout="Month"
```

You can also choose to display the shown week number instead of month name

```xml
CalendarLayout="Week"
WeekViewUnit="WeekNumber"
```

##### Event indicator customizations
You can customize how will look event indication with property `EventIndicatorType`

Expand All @@ -201,7 +234,6 @@ You can customize how will look event indication with property `EventIndicatorTy
```xml
EventIndicatorType="Background"
```

##### Calendar swipe customizations
You can write your own customizations commands for swipe.
```xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Margin="0,2"
Padding="0"
HorizontalOptions="FillAndExpand"
IsVisible="{Binding ShowMonthPicker}"
IsVisible="{Binding ShowLayoutUnitPicker}"
VerticalOptions="Start">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand Down Expand Up @@ -43,7 +43,7 @@
VerticalTextAlignment="Center" />

<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding PrevMonthCommand}" />
<TapGestureRecognizer Command="{Binding PrevLayoutUnitCommand}" />
</Frame.GestureRecognizers>
</Frame>

Expand All @@ -52,16 +52,15 @@
FontAttributes="Bold"
FontSize="Medium"
HorizontalOptions="Center"
TextColor="{Binding MonthLabelColor}"
TextColor="{Binding LayoutUnitLabelColor}"
VerticalOptions="Center">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding MonthText, Mode=TwoWay}" />
<Span Text="{Binding LayoutUnitText, Mode=TwoWay}" />
<Span Text=", " />
<Span Text="{Binding Year, Mode=TwoWay}" />
</FormattedString>
</Label.FormattedText>

</Label>

<Frame
Expand All @@ -88,8 +87,8 @@
VerticalTextAlignment="Center" />

<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding NextMonthCommand}" />
<TapGestureRecognizer Command="{Binding NextLayoutUnitCommand}" />
</Frame.GestureRecognizers>
</Frame>
</Grid>
</DataTemplate>
</DataTemplate>
107 changes: 56 additions & 51 deletions src/Calendar.Plugin.Sample/SampleApp/SampleApp.csproj
Original file line number Diff line number Diff line change
@@ -1,59 +1,64 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<ProduceAssemblyReference>true</ProduceAssemblyReference>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<ProduceAssemblyReference>true</ProduceAssemblyReference>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Rg.Plugins.Popup" Version="2.0.0.12" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Rg.Plugins.Popup" Version="2.0.0.12" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Calendar.Plugin\CalendarPlugin.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Calendar.Plugin\CalendarPlugin.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Views\RangeSelectionPage.xaml.cs">
<DependentUpon>RangeSelectionPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Update="Views\RangeSelectionPage.xaml.cs">
<DependentUpon>RangeSelectionPage.xaml</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Controls\CalendarFooter.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\CalendarRangePickerPopupSelectedDates.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\MainPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\RangeSelectionPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\CalendarPickerPopup.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\SimplePage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\AdvancedPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>

</Project>
<ItemGroup>
<EmbeddedResource Update="Controls\CalendarFooter.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\CalendarRangePickerPopupSelectedDates.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\MainPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\RangeSelectionPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\CalendarPickerPopup.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\SimplePage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\AdvancedPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\TwoWeekViewPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\WeekViewPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using Xamarin.Plugin.Calendar.Models;
using SampleApp.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Threading.Tasks;
using System.Linq;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
using SampleApp.Model;
using Xamarin.Plugin.Calendar.Enums;
using Xamarin.Plugin.Calendar.Models;

namespace SampleApp.ViewModels
{
public class AdvancedPageViewModel : BasePageViewModel
{
public ICommand DayTappedCommand => new Command<DateTime>(async (date) => await DayTapped(date));
public ICommand SwipeLeftCommand => new Command(() => { MonthYear = MonthYear.AddMonths(2); });
public ICommand SwipeRightCommand => new Command(() => { MonthYear = MonthYear.AddMonths(-2); });
public ICommand SwipeUpCommand => new Command(() => { MonthYear = DateTime.Today; });
public ICommand SwipeLeftCommand => new Command(() => ChangeShownUnit(1));
public ICommand SwipeRightCommand => new Command(() => ChangeShownUnit(-1));
public ICommand SwipeUpCommand => new Command(() => { ShownDate = DateTime.Today; });

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

Expand Down Expand Up @@ -46,36 +47,34 @@ public AdvancedPageViewModel() : base()
// with indexer
Events[DateTime.Now] = new List<AdvancedEventModel>(GenerateEvents(2, "Boring"));

MonthYear = MonthYear.AddMonths(1);

Task.Delay(5000).ContinueWith( _ =>
{
// indexer - update later
Events[DateTime.Now] = new ObservableCollection<AdvancedEventModel>(GenerateEvents(10, "Cool"));

// add later
Events.Add(DateTime.Now.AddDays(3), new List<AdvancedEventModel>(GenerateEvents(5, "Cool")));
ShownDate = ShownDate.AddMonths(1);

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

// add later
Events.Add(DateTime.Now.AddDays(15), new List<AdvancedEventModel>(GenerateEvents(10, "Cool")));
// add later
Events.Add(DateTime.Now.AddDays(3), new List<AdvancedEventModel>(GenerateEvents(5, "Cool")));

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

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

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

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

}, TaskScheduler.FromCurrentSynchronizationContext());
}, TaskScheduler.FromCurrentSynchronizationContext());
// insert/add items to observable collection
todayEvents.Insert(0, new AdvancedEventModel { Name = "Cool event insert", Description = "This is Cool event's description!", Starting = new DateTime() });
tborozan marked this conversation as resolved.
Show resolved Hide resolved
todayEvents.Add(new AdvancedEventModel { Name = "Cool event add", Description = "This is Cool event's description!", Starting = new DateTime() });
}, TaskScheduler.FromCurrentSynchronizationContext());
}, TaskScheduler.FromCurrentSynchronizationContext());

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

public EventCollection Events { get; }

private DateTime _monthYear = DateTime.Today;
public DateTime MonthYear
private DateTime _shownDate = DateTime.Today;

public DateTime ShownDate
{
get => _monthYear;
set => SetProperty(ref _monthYear, value);
get => _shownDate;
set => SetProperty(ref _shownDate, value);
}

private WeekLayout _calendarLayout = WeekLayout.Month;

public WeekLayout CalendarLayout
{
get => _calendarLayout;
set => SetProperty(ref _calendarLayout, value);
}

private DateTime? _selectedDate = DateTime.Today;

public DateTime? SelectedDate
{
get => _selectedDate;
set => SetProperty(ref _selectedDate, value);
}


private CultureInfo _culture = CultureInfo.InvariantCulture;

public CultureInfo Culture
{
get => _culture;
Expand All @@ -129,5 +138,31 @@ private async Task ExecuteEventSelectedCommand(object item)
await App.Current.MainPage.DisplayAlert(title, message, "Ok");
}
}

private void ChangeShownUnit(int amountToAdd)
{
switch (CalendarLayout)
{
case WeekLayout.Week:
case WeekLayout.TwoWeek:
ChangeShownWeek(amountToAdd);
break;

case WeekLayout.Month:
default:
ChangeShownMonth(amountToAdd);
break;
}
}

private void ChangeShownMonth(int monthsToAdd)
{
ShownDate.AddMonths(monthsToAdd);
}

private void ChangeShownWeek(int weeksToAdd)
{
ShownDate.AddDays(weeksToAdd * 7);
}
}
}
Loading