Affichage de la liste de livres + vue modale pour la saisie de l'isbn

master
Lucas Evard 2 years ago
parent beab4f76c7
commit 7d7ea4c4a7

@ -4,7 +4,10 @@ namespace MyToolkitMVVM
public class BaseViewModel<TModel> : ObservableObject
{
public TModel Model { get; private set; }
public TModel Model {
get => model;
set => SetProperty(ref model,value);
}
private TModel model;
public BaseViewModel(TModel model)

@ -27,7 +27,25 @@ namespace MyToolkitMVVM
{
execute((T)parameter);
}
}
public class RelayCommand : RelayCommand<object>
{
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
: base(execute, canExecute)
{
}
/* public async Task<bool> CanExecuteAsync(object? parameter)
{
if (parameter == null)
return true;
return await CanExecuteInternalAsync((T)parameter);
}*/
public async Task Execute()
{
await Execute();
}
}
}

@ -4,16 +4,15 @@ public partial class AppShell : Shell
{
public AppShell()
{
Routing.RegisterRoute("MainPage/TousPage",typeof(TousPage));
Routing.RegisterRoute("MainPage/StatutPage", typeof(StatutPage));
Routing.RegisterRoute("MainPage/SharePage", typeof(SharePage));
Routing.RegisterRoute("MainPage/LaterPage", typeof(SharePage));
Routing.RegisterRoute("MainPage/LikePage", typeof(LikePage));
Routing.RegisterRoute("MainPage/Auteur", typeof(SharePage));
Routing.RegisterRoute("MainPage/DatePublic", typeof(DatePublic));
Routing.RegisterRoute("MainPage/MarkPage", typeof(MarkPage));
Routing.RegisterRoute("MainPage/TousPage/BookDetail", typeof(BookDetail));
Routing.RegisterRoute("TousPage",typeof(TousPage));
Routing.RegisterRoute("StatutPage", typeof(StatutPage));
Routing.RegisterRoute("SharePage", typeof(SharePage));
Routing.RegisterRoute("LaterPage", typeof(SharePage));
Routing.RegisterRoute("LikePage", typeof(LikePage));
Routing.RegisterRoute("Auteur", typeof(SharePage));
Routing.RegisterRoute("DatePublic", typeof(DatePublic));
Routing.RegisterRoute("MarkPage", typeof(MarkPage));
Routing.RegisterRoute("BookDetail", typeof(BookDetail));
InitializeComponent();
}
}

@ -8,11 +8,17 @@ namespace PocketBook.Applicative_VM
public class NavigatorVM
{
public ICommand Navigateto { get; private set; }
public ICommand SeeDetailPage { get; private set; }
public NavigatorVM()
{
Navigateto = new Command<string>(
async (string page) => await Shell.Current.GoToAsync(page)
);
SeeDetailPage = new Command(
async () => await Shell.Current.GoToAsync("BookDetail")
);
}
}
}

@ -16,11 +16,8 @@ namespace PocketBook.Applicative_VM
public bool ScanMenuIsVisible
{
get { return scanMenuIsVisible; }
set
{
SetProperty(ref scanMenuIsVisible,value);
}
get => scanMenuIsVisible;
set => SetProperty(ref scanMenuIsVisible,value);
}
public ScanMenuVM()

@ -1,6 +1,9 @@
using Microsoft.Extensions.Logging;
using CommunityToolkit.Maui;
using PocketBook.Applicative_VM;
using ViewModel;
using StubLib;
using Model;
namespace PocketBook;
@ -39,6 +42,8 @@ public static class MauiProgram
});
builder.Services
.AddSingleton<ILibraryManager,LibraryStub>()
.AddSingleton<IUserLibraryManager,UserLibraryStub>()
.AddSingleton<NavigatorVM>()
.AddSingleton<ScanMenuVM>()
.AddSingleton<MainPage>()
@ -49,6 +54,7 @@ public static class MauiProgram
.AddSingleton<LaterPage>()
.AddSingleton<MarkPage>()
.AddSingleton<SharePage>()
.AddSingleton<ManagerVM>()
.AddSingleton<StatutPage>()
.AddSingleton<Auteur>()
;

@ -15,7 +15,7 @@
<Label x:Name="autorName" Text="{Binding AutorName, Source={x:Reference root}}" FontFamily="Pro-Text-Semibold" FontSize="12"/>
<Label x:Name="bookStatus" Text="{Binding BookStatus, Source={x:Reference root}}" FontFamily="Pro-Text-Semibold" FontSize="12" TextColor="#AFAFAF"/>
<StackLayout Orientation="Horizontal" Margin="0,30,0,0">
<local:Stars NbStars="1" Margin="0,0,0,5"/>
<local:Stars NbStars="{Binding Nbstars, Source={x:Reference root}}" Margin="0,0,0,5"/>
</StackLayout>
</StackLayout>
</StackLayout>

@ -19,6 +19,9 @@ public partial class ContentViewBook : ContentView
public static readonly BindableProperty CommandProperty =
BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(ContentViewBook));
public static readonly BindableProperty StarsProperty =
BindableProperty.Create(nameof(Nbstars), typeof(int), typeof(ContentViewBook));
public static readonly BindableProperty CommandParameterProperty =
BindableProperty.Create(nameof(CommandParameter), typeof(string), typeof(ContentViewBook));
@ -28,6 +31,12 @@ public partial class ContentViewBook : ContentView
set { SetValue(CommandProperty, value); }
}
public int Nbstars
{
get { return (int)GetValue(StarsProperty); }
set { SetValue(StarsProperty, value); }
}
public string CommandParameter
{
get { return (string)GetValue(CommandParameterProperty); }

@ -6,6 +6,7 @@ public partial class Stars : ContentView
{
public static readonly BindableProperty NbStarsProperty =
BindableProperty.Create(nameof(NbStars), typeof(int), typeof(Stars), defaultValue: 0, propertyChanged: OnNbStarsChanged);
public int NbStars
{
get { return (int)GetValue(NbStarsProperty); }

@ -35,23 +35,23 @@
<Line BackgroundColor="{StaticResource LineColor1}"/>
<StackLayout Background="{StaticResource BackgroundMainPage}">
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="/MainPage/TousPage/" FilterImageName="tray_second_fill.png" FilterName="Tous" FilterNum="45"/>
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="TousPage" FilterImageName="tray_second_fill.png" FilterName="Tous" FilterNum="45"/>
<Line Style="{StaticResource LineStyle2}"/>
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="/MainPage/SharePage" FilterImageName="person_badge_clock_fill.png" FilterName="En prêt" FilterNum="1"/>
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="SharePage" FilterImageName="person_badge_clock_fill.png" FilterName="En prêt" FilterNum="1"/>
<Line Style="{StaticResource LineStyle2}"/>
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="/MainPage/LaterPage" FilterImageName="arrow_forward.png"
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="LaterPage" FilterImageName="arrow_forward.png"
FilterName="A lire plus tard"/>
<Line Style="{StaticResource LineStyle2}"/>
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="/MainPage/StatutPage" FilterImageName="eyeglasses.png"
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="StatutPage" FilterImageName="eyeglasses.png"
FilterName="Statut de lecture"/>
<Line Style="{StaticResource LineStyle2}"/>
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="/MainPage/LikePage" FilterImageName="heart_fill.png"
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="LikePage" FilterImageName="heart_fill.png"
FilterName="Favoris"/>
</StackLayout>
<Line BackgroundColor="{StaticResource LineColor1}"/>

@ -5,6 +5,7 @@
x:Class="PocketBook.TousPage"
Shell.NavBarIsVisible="True"
Title="Tous"
x:Name="root"
Shell.ForegroundColor="{StaticResource Primary}">
<ContentPage.Resources>
@ -26,21 +27,13 @@
<ScrollView VerticalOptions="StartAndExpand">
<VerticalStackLayout>
<local:TitledAuthor NameText="Alain Damasio"/>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="La horde du contrevent" AutorName="Alain Damasio" BookStatus="Non lu"/>
<Line Style="{StaticResource LineStyle3}"/>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="La zone du dehors" AutorName="Alain Damasio" BookStatus="Terminé"/>
<local:TitledAuthor NameText="Cixin Lui"/>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="L'équateur d'Einstein" AutorName="Cixin Liu" BookStatus="Terminé"/>
<Line Style="{StaticResource LineStyle3}"/>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="La forêt sombre" AutorName="Cixin Liu" BookStatus="Terminé"/>
<Line Style="{StaticResource LineStyle3}"/>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="Le problème à trois corps" AutorName="Cixin Liu" BookStatus="Terminé"/>
<Line Style="{StaticResource LineStyle3}"/>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="L'équateur d'Einstein" AutorName="Cixin Liu" BookStatus="Terminé"/>
<Line Style="{StaticResource LineStyle3}"/>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="La forêt sombre" AutorName="Cixin Liu" BookStatus="Terminé"/>
<Line Style="{StaticResource LineStyle3}"/>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="Le problème à trois corps" AutorName="Cixin Liu" BookStatus="Terminé"/>
<CollectionView ItemsSource="{Binding Manager.Books}">
<CollectionView.ItemTemplate>
<DataTemplate>
<local:ContentViewBook Margin="0,5,0,0" Nbstars="1" Command="{Binding NavigateCommandBooks.SeeDetailPage, Source={x:Reference root}}" BookImage="{Binding Image}" BookName="{Binding Title}" AutorName="{Binding BookFirstAuthor}" BookStatus="{Binding BookStatus}"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ScrollView>
</StackLayout>

@ -1,6 +1,7 @@
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Maui.Views;
using PocketBook.Applicative_VM;
using ViewModel;
namespace PocketBook;
@ -8,10 +9,12 @@ public partial class TousPage : ContentPage
{
public NavigatorVM NavigateCommandBooks { get; private set; }
public ScanMenuVM ScanMenuVM { get; private set; }
public ManagerVM Manager { get; private set; }
public TousPage(NavigatorVM navigation)
public TousPage(NavigatorVM navigation,ScanMenuVM scanMenuVM, ManagerVM manager)
{
ScanMenuVM = new ScanMenuVM();
ScanMenuVM = scanMenuVM;
Manager = manager;
NavigateCommandBooks = navigation;
InitializeComponent();
BindingContext = this;

@ -213,6 +213,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyToolkitMVVM\MyToolkitMVVM.csproj" />
<ProjectReference Include="..\ViewModel\ViewModel.csproj" />
<ProjectReference Include="..\Stub\Stub.csproj" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties XamarinHotReloadDebuggerTimeoutExceptionPocketBookHideInfoBar="True" /></VisualStudio></ProjectExtensions>

@ -6,8 +6,50 @@ namespace ViewModel
{
public class BookVM : BaseViewModel<Book>
{
public BookVM()
public string Title
{
get =>Model.Title;
set =>SetProperty(Model.Title,value,v=>Model.Title=v);
}
public string Image
{
get => Model.ImageLarge;
set { }
}
public Status BookStatus
{
get => Model.Status;
set
{
SetProperty(Model.Status, value, v => Model.Status = v);
}
}
public List<Author> BookAuthors
{
get => Model.Authors;
set
{
SetProperty(Model.Authors, value, v => Model.Authors = v);
}
}
public string BookFirstAuthor { get; private set; }
public BookVM(Book book)
{
Model = book;
Title = book.Title;
BookStatus = book.Status;
BookAuthors = book.Authors;
Image = book.ImageLarge;
if (BookAuthors.Count() > 0)
{
BookFirstAuthor = BookAuthors.First().Name;
}
else BookFirstAuthor = "Unknow";
}
}
}

@ -2,18 +2,64 @@
using System.Collections.ObjectModel;
using Model;
using MyToolkitMVVM;
public class ManagerVM
public class ManagerVM : BaseViewModel<Manager>
{
public Manager model { get; private set; }
public ReadOnlyObservableCollection<BookVM> Books { get; set; }
private readonly ObservableCollection<BookVM> books = new ObservableCollection<BookVM>();
public RelayCommand<string> LoadBooks { get; private set; }
public ManagerVM(ILibraryManager libraryManager,IUserLibraryManager userLibraryManager)
:this(new Manager(libraryManager,userLibraryManager))
{}
public ManagerVM(Manager model)
public async void LoadBooksFromManager()
{
var result = await Model.GetBooksFromCollection(index, 10, "");
NbBook = (int)result.count;
books.Clear();
foreach (Book book in result.books)
{
books.Add(new BookVM(book));
}
}
public ManagerVM(Manager model) : base(model)
{
Model = model;
LoadBooks = new RelayCommand<string>(o => LoadBooksFromManager());
LoadBooks.Execute();
Books = new ReadOnlyObservableCollection<BookVM>(books);
}
public int Index
{
this.model = model;
get => index;
set => SetProperty(ref index, value);
}
private int index;
public int Count
{
get => count;
set => SetProperty(ref count, value);
}
private int count;
public int NbBook
{
get => nbBook;
set => SetProperty(ref nbBook, value);
}
private int nbBook;
}

Loading…
Cancel
Save