Skip to content

Commit 2c12710

Browse files
Added demo for the photo gallery
1 parent f7ee337 commit 2c12710

File tree

138 files changed

+9991
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+9991
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:listView="clr-namespace:Syncfusion.Maui.ListView;assembly=Syncfusion.Maui.ListView"
5+
x:Class="PhotoGallery.AlbumCollectionPage"
6+
Title="{Binding AlbumName}">
7+
<Grid>
8+
<listView:SfListView x:Name="listView" ItemsSource="{Binding Photos}" ItemSize="200" ItemSpacing="10"
9+
ItemTapped="OnPhotosItemTapped">
10+
<listView:SfListView.ItemsLayout>
11+
<listView:GridLayout SpanCount="3" />
12+
</listView:SfListView.ItemsLayout>
13+
<listView:SfListView.ItemTemplate>
14+
<DataTemplate>
15+
<Image Source="{Binding Image}" Aspect="AspectFill"/>
16+
</DataTemplate>
17+
</listView:SfListView.ItemTemplate>
18+
</listView:SfListView>
19+
</Grid>
20+
</ContentPage>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Syncfusion.Maui.DataSource;
2+
using System.Globalization;
3+
4+
namespace PhotoGallery;
5+
6+
public partial class AlbumCollectionPage : ContentPage
7+
{
8+
9+
private readonly GalleryViewModel _viewModel;
10+
11+
public AlbumCollectionPage(GalleryViewModel viewModel)
12+
{
13+
InitializeComponent();
14+
_viewModel = viewModel;
15+
listView.DataSource.GroupDescriptors.Add(new GroupDescriptor()
16+
{
17+
PropertyName = "DateTime",
18+
KeySelector = (object obj1) =>
19+
{
20+
var item = obj1 as ImageInfo;
21+
if (item != null)
22+
{
23+
if (item.DateTime.Date == DateTime.Now.Date)
24+
{
25+
return "Today";
26+
}
27+
else if (item.DateTime.Year == DateTime.Now.Year)
28+
{
29+
return item.DateTime.ToString("MMM dd", CultureInfo.InvariantCulture);
30+
}
31+
else
32+
{
33+
return item.DateTime.ToString("MMM dd yyyy", CultureInfo.InvariantCulture);
34+
}
35+
}
36+
else
37+
{
38+
return "";
39+
}
40+
}
41+
});
42+
}
43+
44+
private void OnPhotosItemTapped(object sender, Syncfusion.Maui.ListView.ItemTappedEventArgs e)
45+
{
46+
47+
ImagePage imagePage = new ImagePage(_viewModel, e.DataItem as ImageInfo);
48+
imagePage.BindingContext = e.DataItem as ImageInfo;
49+
Navigation.PushAsync(imagePage);
50+
}
51+
}

PhotoGallery/App.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:PhotoGallery"
5+
x:Class="PhotoGallery.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>

PhotoGallery/App.xaml.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace PhotoGallery
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
protected override Window CreateWindow(IActivationState? activationState)
11+
{
12+
return new Window(new AppShell());
13+
}
14+
}
15+
}

PhotoGallery/AppShell.xaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="PhotoGallery.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:PhotoGallery"
7+
Shell.FlyoutBehavior="Flyout"
8+
Title="PhotoGallery">
9+
10+
<ShellContent
11+
Title="Home"
12+
ContentTemplate="{DataTemplate local:MainPage}"
13+
Route="MainPage" />
14+
15+
</Shell>

PhotoGallery/AppShell.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace PhotoGallery
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Globalization;
2+
3+
namespace PhotoGallery
4+
{
5+
public class FavoriteToIconConverter : IValueConverter
6+
{
7+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
8+
{
9+
if (value is bool isFavorite)
10+
{
11+
// Assume '&#xE739;' is the outline and '&#xE73A;' is the filled icon.
12+
return isFavorite ? "\uE707" : "\uE706";
13+
}
14+
return "\uE706"; // Default to outline
15+
}
16+
17+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
18+
{
19+
throw new NotImplementedException();
20+
}
21+
}
22+
}

PhotoGallery/ImagePage.xaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="PhotoGallery.ImagePage"
5+
xmlns:effects="clr-namespace:Syncfusion.Maui.Core;assembly=Syncfusion.Maui.Core"
6+
xmlns:local="clr-namespace:PhotoGallery"
7+
Title="{Binding DateTime, StringFormat='{0:d MMM yyyy, h.mm tt}'}">
8+
9+
<ContentPage.Resources>
10+
<ResourceDictionary>
11+
<local:FavoriteToIconConverter x:Key="FavoriteToIconConverter"/>
12+
</ResourceDictionary>
13+
</ContentPage.Resources>
14+
15+
<Grid RowDefinitions="*,60">
16+
<Image Source="{Binding Image}" Aspect="AspectFit"/>
17+
<HorizontalStackLayout VerticalOptions="End" Spacing="10" HorizontalOptions="Center">
18+
19+
<Border StrokeThickness="0" HeightRequest="60" WidthRequest="60">
20+
<Border.StrokeShape>
21+
<RoundRectangle CornerRadius="25"/>
22+
</Border.StrokeShape>
23+
<effects:SfEffectsView TouchDownEffects="Highlight">
24+
<effects:SfEffectsView.GestureRecognizers>
25+
<TapGestureRecognizer Tapped="OnShareTapped"/>
26+
</effects:SfEffectsView.GestureRecognizers>
27+
<VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center">
28+
<Label Text="&#xE702;" FontFamily="PhotoGallery" FontSize="24" HorizontalOptions="Center"/>
29+
<Label Text="Share" />
30+
</VerticalStackLayout>
31+
</effects:SfEffectsView>
32+
</Border>
33+
34+
<Border StrokeThickness="0" HeightRequest="60" WidthRequest="60">
35+
<Border.StrokeShape>
36+
<RoundRectangle CornerRadius="25"/>
37+
</Border.StrokeShape>
38+
<effects:SfEffectsView TouchDownEffects="Highlight">
39+
<effects:SfEffectsView.GestureRecognizers>
40+
<TapGestureRecognizer Tapped="OnFavoriteTapped"/>
41+
</effects:SfEffectsView.GestureRecognizers>
42+
<VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center">
43+
<Label Text="{Binding IsFavorite, Converter={StaticResource FavoriteToIconConverter}}"
44+
FontFamily="PhotoGallery" FontSize="24" HorizontalOptions="Center"/>
45+
<Label Text="Favorite" />
46+
</VerticalStackLayout>
47+
</effects:SfEffectsView>
48+
</Border>
49+
50+
<Border StrokeThickness="0" HeightRequest="60" WidthRequest="60">
51+
<Border.StrokeShape>
52+
<RoundRectangle CornerRadius="25"/>
53+
</Border.StrokeShape>
54+
<effects:SfEffectsView TouchDownEffects="Highlight">
55+
<effects:SfEffectsView.GestureRecognizers>
56+
<TapGestureRecognizer Tapped="OnEditTapped"/>
57+
</effects:SfEffectsView.GestureRecognizers>
58+
<VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center">
59+
<Label Text="&#xE701;" FontFamily="PhotoGallery" FontSize="24" HorizontalOptions="Center"/>
60+
<Label Text="Edit" />
61+
</VerticalStackLayout>
62+
</effects:SfEffectsView>
63+
</Border>
64+
65+
<Border StrokeThickness="0" HeightRequest="60" WidthRequest="60">
66+
<Border.StrokeShape>
67+
<RoundRectangle CornerRadius="25"/>
68+
</Border.StrokeShape>
69+
<effects:SfEffectsView TouchDownEffects="Highlight">
70+
<effects:SfEffectsView.GestureRecognizers>
71+
<TapGestureRecognizer Tapped="OnDeleteTapped"/>
72+
</effects:SfEffectsView.GestureRecognizers>
73+
<VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center">
74+
<Label Text="&#xE700;" FontFamily="PhotoGallery" FontSize="24" HorizontalOptions="Center"/>
75+
<Label Text="Delete" />
76+
</VerticalStackLayout>
77+
</effects:SfEffectsView>
78+
</Border>
79+
80+
</HorizontalStackLayout>
81+
</Grid>
82+
</ContentPage>

PhotoGallery/ImagePage.xaml.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
namespace PhotoGallery;
2+
3+
public partial class ImagePage : ContentPage
4+
{
5+
private readonly GalleryViewModel _viewModel;
6+
7+
public ImagePage(GalleryViewModel viewModel, ImageInfo imageInfo)
8+
{
9+
InitializeComponent();
10+
_viewModel = viewModel;
11+
BindingContext = imageInfo;
12+
}
13+
14+
private void OnFavoriteTapped(object sender, TappedEventArgs e)
15+
{
16+
if (BindingContext is ImageInfo imageInfo)
17+
{
18+
imageInfo.IsFavorite = !imageInfo.IsFavorite;
19+
}
20+
}
21+
22+
private async void OnDeleteTapped(object sender, TappedEventArgs e)
23+
{
24+
if (BindingContext is ImageInfo imageInfo)
25+
{
26+
// Confirm the deletion action
27+
bool isConfirmed = await DisplayAlert("Delete Image", "Are you sure you want to delete this image?", "Yes", "No");
28+
if (isConfirmed)
29+
{
30+
if (_viewModel.Recents.Contains(imageInfo))
31+
_viewModel.Recents.Remove(imageInfo);
32+
33+
// Remove from Photos collection
34+
if (_viewModel.Photos.Contains(imageInfo))
35+
_viewModel.Photos.Remove(imageInfo);
36+
else if (_viewModel.Countries.Contains(imageInfo))
37+
_viewModel.Countries.Remove(imageInfo);
38+
else if (_viewModel.Foods.Contains(imageInfo))
39+
_viewModel.Foods.Remove(imageInfo);
40+
else if (_viewModel.Electronics.Contains(imageInfo))
41+
_viewModel.Electronics.Remove(imageInfo);
42+
else if (_viewModel.Birds.Contains(imageInfo))
43+
_viewModel.Birds.Remove(imageInfo);
44+
45+
46+
// Remove from Favorites if it's there
47+
if (imageInfo.IsFavorite)
48+
{
49+
_viewModel.Favorites.Remove(imageInfo);
50+
}
51+
52+
// Navigate back to the main page or previous navigation stack
53+
await Navigation.PopAsync();
54+
}
55+
}
56+
}
57+
58+
private void OnShareTapped(object sender, TappedEventArgs e)
59+
{
60+
// Add your changes to share the image
61+
}
62+
63+
private void OnEditTapped(object sender, TappedEventArgs e)
64+
{
65+
// Add your changes to edit the image
66+
}
67+
}
68+

0 commit comments

Comments
 (0)