Update (Back-end): Navigation établie, mais bancale
continuous-integration/drone/push Build is failing Details

Back-End
Louis DUFOUR 2 years ago
parent 25445b6f1b
commit d87d16c481

@ -2,6 +2,7 @@
<ContentPage <ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:vm="clr-namespace:BookApp.ViewModel"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Class="BookApp.MainPage"> x:Class="BookApp.MainPage">
<Shell.TitleView> <Shell.TitleView>
@ -37,13 +38,35 @@
<Shell.BackButtonBehavior> <Shell.BackButtonBehavior>
<BackButtonBehavior IsVisible="False" IsEnabled="False" /> <BackButtonBehavior IsVisible="False" IsEnabled="False" />
</Shell.BackButtonBehavior> </Shell.BackButtonBehavior>
<ContentPage.Resources>
<Style TargetType="StackLayout">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor"
Value="Purple" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
</ContentPage.Resources>
<StackLayout> <StackLayout>
<Label FontSize="35" FontFamily="SF-Pro-Display-Bold" Padding="10">Mes livres</Label> <Label FontSize="35" FontFamily="SF-Pro-Display-Bold" Padding="10">Mes livres</Label>
<Rectangle HeightRequest="1" BackgroundColor="black" VerticalOptions="End" /> <Rectangle HeightRequest="1" BackgroundColor="black" VerticalOptions="End" />
<CollectionView ItemsSource="{Binding MyCollections1}" SelectionMode="Single" SelectionChanged="OnSelectionChanged" Margin="25,0,0,0" BackgroundColor="#F9F9F9"> <CollectionView ItemsSource="{Binding ViewModelMenu.MenuItemsLivre}"
SelectionChangedCommand="{Binding ViewModelNavigation.ItemSelectedCommand}"
SelectedItem="{Binding ViewModelNavigation.SelectedItem, Mode=TwoWay}"
SelectionMode="Single" Margin="25,0,0,0" BackgroundColor="#F9F9F9">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate x:DataType="vm:ViewModelMenuItem">
<Grid RowDefinitions="Auto" > <Grid RowDefinitions="Auto" >
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="25"/> <ColumnDefinition Width="25"/>
@ -92,9 +115,12 @@
<Label FontFamily="SF-Pro-Display-Heavy" FontSize="20" Padding="10">Filtres</Label> <Label FontFamily="SF-Pro-Display-Heavy" FontSize="20" Padding="10">Filtres</Label>
<Rectangle HeightRequest="1" BackgroundColor="black" VerticalOptions="End"/> <Rectangle HeightRequest="1" BackgroundColor="black" VerticalOptions="End"/>
<CollectionView ItemsSource="{Binding MyCollections2}" Margin="25,0,0,0" BackgroundColor="#F9F9F9"> <CollectionView ItemsSource="{Binding ViewModelMenu.MenuItemsFiltre}"
SelectionChangedCommand="{Binding ViewModelNavigation.ItemSelectedCommand}"
SelectedItem="{Binding ViewModelNavigation.SelectedItem, Mode=TwoWay}"
Margin="25,0,0,0" BackgroundColor="#F9F9F9">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate x:DataType="vm:ViewModelMenuItem">
<Grid RowDefinitions="Auto" > <Grid RowDefinitions="Auto" >
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="25" /> <ColumnDefinition Width="25" />

@ -6,12 +6,10 @@ namespace BookApp
{ {
public partial class MainPage : ContentPage public partial class MainPage : ContentPage
{ {
public MainPage(NavigationViewModel data) public MainPage(ViewModelManager data)
{ {
InitializeComponent(); InitializeComponent();
BindingContext = data; BindingContext = data;
} }
private async void OnSelectionChanged(object sender, SelectionChangedEventArgs e) { }
} }
} }

@ -35,7 +35,9 @@ namespace BookApp
builder.Services.AddSingleton<CollectionFiltrage>(); builder.Services.AddSingleton<CollectionFiltrage>();
builder.Services.AddSingleton<Tous>(); builder.Services.AddSingleton<Tous>();
builder.Services.AddSingleton<MainPage>(); builder.Services.AddSingleton<MainPage>();
builder.Services.AddSingleton<NavigationViewModel>(); builder.Services.AddSingleton<ViewModelNavigation>();
builder.Services.AddTransient<ViewModelMenu>();
// transient pour recharger la data à l'execute // transient pour recharger la data à l'execute

@ -1,4 +1,5 @@
using BookApp.ViewModel; using BookApp.ViewModel;
using System.Diagnostics;
using VMWrapper; using VMWrapper;
namespace BookApp.Pages namespace BookApp.Pages
@ -8,6 +9,7 @@ namespace BookApp.Pages
public Tous(BookViewModel data) public Tous(BookViewModel data)
{ {
InitializeComponent(); InitializeComponent();
Debug.WriteLine("TousPage is initialized.");
BindingContext = data; BindingContext = data;
} }

@ -1,14 +1,17 @@
using Model; using Model;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using ToolKit;
using VMWrapper; using VMWrapper;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace BookApp.ViewModel; namespace BookApp.ViewModel;
public class ViewModelManager public class ViewModelManager : BaseViewModel
{ {
BookViewModel _viewModel; BookViewModel _viewModel;
public ObservableCollection<Author> Authors { get; set; } = new ObservableCollection<Author>(); public ObservableCollection<Author> Authors { get; set; } = new ObservableCollection<Author>();
public ViewModelMenu ViewModelMenu { get; } = new ViewModelMenu();
public ViewModelNavigation ViewModelNavigation { get; } = new ViewModelNavigation();
public ViewModelManager(BookViewModel viewModel) public ViewModelManager(BookViewModel viewModel)
{ {

@ -4,64 +4,63 @@ namespace BookApp.ViewModel
{ {
public class ViewModelMenu public class ViewModelMenu
{ {
public string Name { get; set; } public ObservableCollection<ViewModelMenuItem> MenuItemsLivre { get; set; }
public string Icone { get; set; } public ObservableCollection<ViewModelMenuItem> MenuItemsFiltre { get; set; }
public int Number { get; set; }
public string Route { get; set; }
public bool IsLastItem { get; set; }
public ViewModelMenu( public ViewModelMenu()
string name,
string icone,
int number,
string route,
bool isLastItem = false
)
{ {
Name = name; MenuItemsLivre = new ObservableCollection<ViewModelMenuItem>()
Icone = icone;
Number = number;
Route = route;
IsLastItem = isLastItem;
}
public ObservableCollection<ViewModelMenu> MyCollections1 { get; set; } =
new ObservableCollection<ViewModelMenu>()
{ {
new ViewModelMenu("Tous", "./Resources/Images/tray_2_fill.svg", 250, "Tous"), new ViewModelMenuItem(
new ViewModelMenu( "Tous",
"../Resources/Images/tray_2_fill.svg",
250,
"TousPage"
),
new ViewModelMenuItem(
"En prêt", "En prêt",
"./Resources/Images/person_badge_clock_fill.svg", "../Resources/Images/person_badge_clock_fill.svg",
250, 250,
"EmpruntsPrets" "EmpruntsPrets"
), ),
new ViewModelMenu( new ViewModelMenuItem(
"À lire plus tard", "À lire plus tard",
"./Resources/Images/arrow_forward.svg", "../Resources/Images/arrow_forward.svg",
250, 250,
"" ""
), ),
new ViewModelMenu( new ViewModelMenuItem(
"Statut de lecture", "Statut de lecture",
"./Resources/Images/eyeglasses.svg", "../Resources/Images/eyeglasses.svg",
250, 250,
"" ""
), ),
new ViewModelMenu("Favoris", "./Resources/Images/heart_fill.svg", 250, ""), new ViewModelMenuItem("Favoris", "../Resources/Images/heart_fill.svg", 250, ""),
new ViewModelMenu("Étiquettes", "./Resources/Images/tag_fill.svg", 250, "", true), new ViewModelMenuItem(
"Étiquettes",
"../Resources/Images/tag_fill.svg",
250,
"",
true
),
}; };
public ObservableCollection<ViewModelMenu> MyCollections2 { get; set; } = MenuItemsFiltre = new ObservableCollection<ViewModelMenuItem>()
new ObservableCollection<ViewModelMenu>()
{ {
new ViewModelMenu("Auteur", "./Resources/Images/person_fill.svg", 250, "Filtrage"), new ViewModelMenuItem(
new ViewModelMenu( "Auteur",
"../Resources/Images/person_fill.svg",
250,
"Filtrage"
),
new ViewModelMenuItem(
"Date de publication", "Date de publication",
"./Resources/Images/calendar.svg", "../Resources/Images/calendar.svg",
250, 250,
"" ""
), ),
new ViewModelMenu("Note", "./Resources/Images/sparkles.svg", 250, "", true), new ViewModelMenuItem("Note", "../Resources/Images/sparkles.svg", 250, "", true),
}; };
}
} }
} }

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BookApp.ViewModel
{
public class ViewModelMenuItem
{
public string Name { get; set; }
public string Icone { get; set; }
public int Number { get; set; }
public string Route { get; set; }
public bool IsLastItem { get; set; }
public ViewModelMenuItem(
string name,
string icone,
int number,
string route,
bool isLastItem = false
)
{
Name = name;
Icone = icone;
Number = number;
Route = route;
IsLastItem = isLastItem;
}
}
}

@ -1,32 +1,42 @@
using ToolKit; using ToolKit;
using System.Windows.Input; using System.Windows.Input;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
namespace BookApp.ViewModel namespace BookApp.ViewModel
{ {
public class NavigationViewModel : BaseViewModel public class ViewModelNavigation : BaseViewModel
{ {
public NavigationViewModel() { } private ViewModelMenuItem _selectedItem;
public ViewModelMenuItem SelectedItem
{
get { return _selectedItem; }
set { SetProperty(ref _selectedItem, value); }
}
public ICommand ItemSelectedCommand { get; private set; }
public ViewModelNavigation()
{
ItemSelectedCommand = new Command(async () => await OnItemSelected(SelectedItem));
}
private async void OnSelectionChanged(object sender, SelectionChangedEventArgs e) private async Task OnItemSelected(ViewModelMenuItem selectedItem)
{ {
if (e.CurrentSelection.FirstOrDefault() is ViewModelMenu selectedItem) SelectedItem = selectedItem;
if (string.IsNullOrEmpty(SelectedItem?.Route))
return;
try
{
await Shell.Current.GoToAsync(selectedItem.Route);
selectedItem = null;
}
catch (Exception ex)
{ {
if (!string.IsNullOrWhiteSpace(selectedItem.Route)) Debug.WriteLine($"Navigation failed: {ex.Message}");
{
Type pageType = Type.GetType("BookApp.Pages." + selectedItem.Route);
if (pageType == null)
{
return;
}
Page pageInstance = (Page)Activator.CreateInstance(pageType);
// await Navigation.PushAsync(pageInstance);
}
else
{
Console.WriteLine("Erreur trouvé");
}
} }
} }

@ -7,23 +7,22 @@ namespace ToolKit
{ {
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
protected bool SetProperty<T>( protected virtual void SetProperty<T>(
ref T backingField, ref T backingStore,
T value, T value,
[CallerMemberName] string propertyName = null [CallerMemberName] string propertyName = "",
Action onChanged = null
) )
{ {
if (EqualityComparer<T>.Default.Equals(backingField, value)) if (EqualityComparer<T>.Default.Equals(backingStore, value))
return false; return;
backingField = value; backingStore = value;
onChanged?.Invoke();
OnPropertyChanged(propertyName); OnPropertyChanged(propertyName);
return true;
} }
} }
} }

Loading…
Cancel
Save