Skip to content

Commit

Permalink
Merge pull request #70 from MykhailoDav/refactoring_view_models_and_a…
Browse files Browse the repository at this point in the history
…dding_samples

Refactored viewmodels;
Added new samples
  • Loading branch information
yurkinh authored Aug 6, 2024
2 parents 0021769 + 98a1cb3 commit 17a0d56
Show file tree
Hide file tree
Showing 71 changed files with 1,645 additions and 1,261 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ Simple cross platform plugin for Calendar control featuring:
| ------- | ------ |
| ![Windiws Calendar Screenshot](https://github.com/yurkinh/Plugin.Maui.Calendar/blob/main/res/win.png) | ![Mac Calendar Screenshot](https://github.com/yurkinh/Plugin.Maui.Calendar/blob/main/res/mac.png) |

Theme support
| Ligth | Dark | Setting |
| ------- | ------ | ------ |
| ![Light theme Screenshot](https://github.com/yurkinh/Plugin.Maui.Calendar/blob/main/res/LightTheme.png) | ![Dark theme Screenshot](https://github.com/yurkinh/Plugin.Maui.Calendar/blob/main/res/DarkTheme.png) | ![Setting Page Screenshot](https://github.com/yurkinh/Plugin.Maui.Calendar/blob/main/res/ThemeSettingPage.png) |

# New Samples

Windows 11 calendar
| Win | Mac |
| ------- | ------ |
| ![Windiws 11 android Calendar Screenshot](https://github.com/yurkinh/Plugin.Maui.Calendar/blob/main/res/W11_android.png) | ![Windiws 11 Calendar IOS Screenshot](https://github.com/yurkinh/Plugin.Maui.Calendar/blob/main/res/W11_ios.png) |

Weekend calendar
| Android | IOS |
| ------- | ------ |
| ![Weekend calendar Android Screenshot](https://github.com/yurkinh/Plugin.Maui.Calendar/blob/main/res/WeekendCalendar_android.png) | ![Weekend calendar IOS Screenshot](https://github.com/yurkinh/Plugin.Maui.Calendar/blob/main/res/WeekendCalendar_ios.png) |





Expand All @@ -33,6 +51,10 @@ Simple cross platform plugin for Calendar control featuring:
* Added OnShownDateChangedCommand so we can take action when date is changed.
* Added Dispose method to force handlers disconnect call.
* Added new property **OtherMonthSelectedDayColor**
* Fixed bug with **OtherMonthDayIsVisibleProperty**
* Added a weekend calendar sample
* Added a windows 11 calendar sample
* Added theme support


### Usage
Expand Down
Binary file added res/DarkTheme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/LightTheme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/ThemeSettingPage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/W11Calendar_mac.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/W11Calendar_windows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/W11_android.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/W11_android_d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/W11_ios.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/WeekendCalendar_android.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/WeekendCalendar_ios.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions samples/SampleApp/App.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:SampleApp"
x:Class="SampleApp.App">
<?xml version="1.0" encoding="UTF-8" ?>
<Application
x:Class="SampleApp.App"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:SampleApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down
15 changes: 10 additions & 5 deletions samples/SampleApp/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
using SampleApp.Views;
using SampleApp.Model;
using SampleApp.Services;
using SampleApp.Views;

namespace SampleApp;

public partial class App : Application
{
readonly IThemeService themeService;

public static new App Current => (App)Application.Current;
public App()
public App(IThemeService themeService)
{
InitializeComponent();
this.themeService = themeService;
InitializeComponent();

MainPage = new NavigationPage(new MainPage());
}


protected override void OnStart()
{
AppTheme currentTheme = Application.Current.RequestedTheme;
themeService.SetTheme((AppTheme)(Themes.System));
}

protected override void OnResume()
{
AppTheme currentTheme = Application.Current.RequestedTheme;

}

}
Expand Down
13 changes: 6 additions & 7 deletions samples/SampleApp/Controls/CalendarFooter.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace SampleApp.Controls
namespace SampleApp.Controls;

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CalendarFooter : ContentView
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CalendarFooter : ContentView
public CalendarFooter()
{
public CalendarFooter()
{
InitializeComponent();
}
InitializeComponent();
}
}
13 changes: 6 additions & 7 deletions samples/SampleApp/Controls/CalendarHeader.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace SampleApp.Controls
namespace SampleApp.Controls;

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CalendarHeader : DataTemplate
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CalendarHeader : DataTemplate
public CalendarHeader()
{
public CalendarHeader()
{
InitializeComponent();
}
InitializeComponent();
}
}
42 changes: 20 additions & 22 deletions samples/SampleApp/Controls/CalenderEvent.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
using SampleApp.Model;
using System.Windows.Input;
using System.Windows.Input;

namespace SampleApp.Controls
namespace SampleApp.Controls;

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CalenderEvent : ContentView
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CalenderEvent : ContentView
{
public static BindableProperty CalenderEventCommandProperty =
BindableProperty.Create(nameof(CalenderEventCommand), typeof(ICommand), typeof(CalenderEvent), null);
public static BindableProperty CalenderEventCommandProperty =
BindableProperty.Create(nameof(CalenderEventCommand), typeof(ICommand), typeof(CalenderEvent), null);

public CalenderEvent()
{
InitializeComponent();
}
public CalenderEvent()
{
InitializeComponent();
}

public ICommand CalenderEventCommand
{
get => (ICommand)GetValue(CalenderEventCommandProperty);
set => SetValue(CalenderEventCommandProperty, value);
}
public ICommand CalenderEventCommand
{
get => (ICommand)GetValue(CalenderEventCommandProperty);
set => SetValue(CalenderEventCommandProperty, value);
}

private void TapGestureRecognizer_Tapped(object sender, System.EventArgs e)
{
if (BindingContext is AdvancedEventModel eventModel)
CalenderEventCommand?.Execute(eventModel);
}
private void TapGestureRecognizer_Tapped(object sender, System.EventArgs e)
{
if (BindingContext is AdvancedEventModel eventModel)
CalenderEventCommand?.Execute(eventModel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView
x:Class="SampleApp.Controls.Windows11CalendarHeader"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:SampleApp.Controls"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Name="Header"
x:DataType="controls:CalendarHeader">
<ContentView.Resources>
<ResourceDictionary>
<Style x:Key="arrowButtonPrevStyle" TargetType="Button">
<Setter Property="FontFamily" Value="FontAwesomeSolid" />
<Setter Property="BorderColor" Value="Transparent" />
<Setter Property="BackgroundColor" Value="Transparent" />
<Setter Property="Text" Value="&#xf062;" />
<Setter Property="FontSize" Value="15" />
<Setter Property="TextColor" Value="DimGray" />
</Style>

<Style x:Key="arrowButtonNextStyle" TargetType="Button">
<Setter Property="FontFamily" Value="FontAwesomeSolid" />
<Setter Property="Text" Value="&#xf063;" />
<Setter Property="BorderColor" Value="Transparent" />
<Setter Property="BackgroundColor" Value="Transparent" />
<Setter Property="FontSize" Value="15" />
<Setter Property="TextColor" Value="DimGray" />
</Style>
<Style x:Key="ArrowFooterButtonUpStyle" TargetType="Button">
<Setter Property="BackgroundColor" Value="Transparent" />
<Setter Property="FontFamily" Value="FontAwesomeSolid" />
<Setter Property="FontAttributes" Value="Bold" />
<Setter Property="FontSize" Value="15" />
<Setter Property="HorizontalOptions" Value="End" />
<Setter Property="Text" Value="&#xf063;" />
<Setter Property="TextColor" Value="DimGray" />
<Setter Property="VerticalOptions" Value="Center" />
</Style>
</ResourceDictionary>
</ContentView.Resources>
<Grid
Padding="12,0,12,0"
ColumnDefinitions="*,Auto,Auto"
HorizontalOptions="Fill"
IsVisible="{Binding BindingContext.ShowMonthPicker, Source={x:Reference Header}}"
RowDefinitions="Auto"
VerticalOptions="Start">
<Label
Grid.Column="0"
FontAttributes="Bold"
FontSize="14"
HorizontalOptions="Start"
Style="{StaticResource HeaderLabelStyle}"
TextColor="{toolkit:AppThemeResource DaysTitleLabelTextColorMinimalistic}"
VerticalOptions="Center">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding BindingContext.LayoutUnitText, Source={x:Reference Header}, Mode=TwoWay}" />
<Span Text=" " />
<Span Text="{Binding BindingContext.Year, Source={x:Reference Header}, Mode=TwoWay}" />
</FormattedString>
</Label.FormattedText>
</Label>
<Button
Grid.Column="1"
Command="{Binding BindingContext.PrevLayoutUnitCommand, Source={x:Reference Header}, Mode=OneWay}"
Style="{StaticResource arrowButtonPrevStyle}" />
<Button
Grid.Column="2"
Command="{Binding BindingContext.NextLayoutUnitCommand, Source={x:Reference Header}, Mode=OneWay}"
Style="{StaticResource arrowButtonNextStyle}" />
</Grid>
</ContentView>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SampleApp.Controls;

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Windows11CalendarHeader : ContentView
{
public Windows11CalendarHeader()
{
InitializeComponent();
}
}
4 changes: 4 additions & 0 deletions samples/SampleApp/GlobalNamespaces.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
global using CommunityToolkit.Mvvm.ComponentModel;
global using CommunityToolkit.Mvvm.Input;
global using SampleApp.Model;
global using SampleApp.ViewModels;
10 changes: 10 additions & 0 deletions samples/SampleApp/Helpers/ServiceHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SampleApp.Helpers;
public static class ServiceHelper
{
public static IServiceProvider Services { get; private set; }

public static void Initialize(IServiceProvider serviceProvider) =>
Services = serviceProvider;

public static T GetService<T>() => Services.GetService<T>();
}
40 changes: 32 additions & 8 deletions samples/SampleApp/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Microsoft.Extensions.Logging;
using CommunityToolkit.Maui;
using Microsoft.Extensions.Logging;
using Mopups.Hosting;
using SampleApp.Helpers;
using SampleApp.Services;
using SampleApp.Views;

namespace SampleApp;

Expand All @@ -11,19 +15,39 @@ public static MauiApp CreateMauiApp()
builder
.UseMauiApp<App>()
.ConfigureMopups()
.ConfigureFonts(fonts =>
.UseMauiCommunityToolkit()
.InjectServices()
.InjectViewsAndViewModels()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("font-awesome-5-free-solid.otf", "FontAwesomeSolid");
fonts.AddFont("font-awesome-5-free-regular.otf", "FontAwesomeRegular");
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("font-awesome-6-free-solid.otf", "FontAwesomeSolid");
fonts.AddFont("font-awesome-6-free-regular.otf", "FontAwesomeRegular");
fonts.AddFont("DarkerGrotesque-VariableFont_wght.ttf", "DarkerGrotesque");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
var app = builder.Build();

//we must initialize our service helper before using it
ServiceHelper.Initialize(app.Services);

return app;
}
static MauiAppBuilder InjectViewsAndViewModels(this MauiAppBuilder builder)
{
builder.Services.AddTransient<UserSettingPage>();
builder.Services.AddTransient<UserSettingViewModel>();
return builder;
}
static MauiAppBuilder InjectServices(this MauiAppBuilder builder)
{
builder.Services.AddSingleton<IThemeService, ThemeService>();
return builder;
}
}

13 changes: 6 additions & 7 deletions samples/SampleApp/Model/AdvancedEventModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace SampleApp.Model
namespace SampleApp.Model;

public class AdvancedEventModel
{
public class AdvancedEventModel
{
public string Name { get; set; }
public string Description { get; set; }
public DateTime Starting { get; set; }
}
public string Name { get; set; }
public string Description { get; set; }
public DateTime Starting { get; set; }
}
11 changes: 4 additions & 7 deletions samples/SampleApp/Model/CalendarPickerResult.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
namespace SampleApp.Model;

namespace SampleApp.Model
public class CalendarPickerResult
{
public class CalendarPickerResult
{
public bool IsSuccess { get; set; }
public bool IsSuccess { get; set; }

public DateTime? SelectedDate { get; set; }
}
public DateTime? SelectedDate { get; set; }
}
16 changes: 6 additions & 10 deletions samples/SampleApp/Model/CalendarRangePickerResult.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using System;
using System.Collections.Generic;
namespace SampleApp.Model;

namespace SampleApp.Model
public class CalendarRangePickerResult
{
public class CalendarRangePickerResult
{
public bool IsSuccess { get; set; }
public List<DateTime> SelectedDates { get; set; } = new List<DateTime>();
public DateTime? SelectedStartDate { get; set; }
public DateTime? SelectedEndDate { get; set; }
}
public bool IsSuccess { get; set; }
public List<DateTime> SelectedDates { get; set; } = new List<DateTime>();
public DateTime? SelectedStartDate { get; set; }
public DateTime? SelectedEndDate { get; set; }
}
Loading

0 comments on commit 17a0d56

Please sign in to comment.