Add add playlist feature with modal page
continuous-integration/drone/push Build is failing Details

pull/27/head
Corentin LEMAIRE 2 years ago
parent 2ed464f7ee
commit b0011f3aae

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Linaris.AddPlaylistPage"
Title="AddPlaylistPage">
<VerticalStackLayout BackgroundColor="#404040">
<Frame Margin="10" CornerRadius="75" HeightRequest="150" WidthRequest="150" IsClippedToBounds="True" HorizontalOptions="Center" VerticalOptions="Center">
<Image Source="{Binding ImageURL}" Aspect="AspectFill" WidthRequest="150" HeightRequest="150" Margin="-20" IsAnimationPlaying="True">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="ChangeImage"/>
</Image.GestureRecognizers>
</Image>
</Frame>
<Entry Text="{Binding Name}" WidthRequest="300" Placeholder="Nom de la playlist" TextColor="White" Margin="0,20,0,20" VerticalOptions="Center" HorizontalOptions="Center"/>
<Entry Text="{Binding Description}" WidthRequest="300" HeightRequest="150" Placeholder="Description de la playlist" VerticalTextAlignment="Start" TextColor="White" Margin="0,20,0,20" VerticalOptions="Center" HorizontalOptions="Center"/>
<HorizontalStackLayout HorizontalOptions="Center" Margin="10" Spacing="15">
<Button Text="Créer la playlist" BackgroundColor="green" FontSize="20" Clicked="AddPlaylist"/>
<Button Text="Annuler" BackgroundColor="red" FontSize="20" Clicked="Cancel"/>
</HorizontalStackLayout>
</VerticalStackLayout>
</ContentPage>

@ -0,0 +1,58 @@
using Model;
using System.Collections.ObjectModel;
namespace Linaris;
public partial class AddPlaylistPage : ContentPage
{
public Playlist NewPlaylist { get; } = new Playlist();
public AddPlaylistPage()
{
InitializeComponent();
BindingContext = NewPlaylist;
}
private async void ChangeImage(object sender, EventArgs e)
{
var result = await FilePicker.PickAsync(new PickOptions
{
PickerTitle = "Choisissez une nouvelle image !",
FileTypes = FilePickerFileType.Images
});
if (result == null)
{
return;
}
if (sender is Image image)
{
if (image.BindingContext is Playlist playlist)
{
playlist.ImageURL = result.FullPath;
}
}
}
private void Cancel(object sender, EventArgs e)
{
Navigation.PopModalAsync();
}
private async void AddPlaylist(object sender, EventArgs e)
{
if ((Application.Current as App).Manager.GetPlaylistByName(NewPlaylist.Name) != null)
{
await DisplayAlert("Erreur !", "La playlist existe déjà", "OK");
return;
}
if (string.IsNullOrWhiteSpace(NewPlaylist.Name))
{
await DisplayAlert("Erreur !", "Le nom de la playlist ne doit pas être vide !", "OK");
return;
}
(Application.Current as App).Manager.AddPlaylist(NewPlaylist);
await Navigation.PopModalAsync();
}
}

@ -6,9 +6,8 @@ namespace Linaris;
public partial class App : Application
{
static IDataManager DataManager = new LinqXmlSerialization();
public static Manager Manager = new Manager(DataManager);
public Manager Manager = new(new LinqXmlSerialization());
public App()
{

@ -34,7 +34,7 @@
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg"/>
<MauiIcon Include="Resources\AppIcon\appicon.svg" />
<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
@ -73,9 +73,21 @@
</ItemGroup>
<ItemGroup>
<MauiXaml Update="AddCustomTitlePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="AddPlaylistPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="AlbumPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="EditCustomTitlePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="EditPlaylistPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="FooterPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>

@ -9,14 +9,14 @@ namespace Linaris
{
public partial class LocalFilesPage : ContentPage
{
private ObservableCollection<CustomTitle> customTitles = App.Manager.GetCustomTitles();
private ObservableCollection<CustomTitle> customTitles = (Application.Current as App).Manager.GetCustomTitles();
public ObservableCollection<CustomTitle> CustomTitles
{
get => customTitles;
}
private ObservableCollection<Playlist> playlists = App.Manager.GetPlaylists();
private ObservableCollection<Playlist> playlists = (Application.Current as App).Manager.GetPlaylists();
public ObservableCollection<Playlist> Playlists
{
@ -69,7 +69,7 @@ namespace Linaris
void AddCustomTitle(CustomTitle customTitle)
{
App.Manager.AddCustomTitle(customTitle);
(Application.Current as App).Manager.AddCustomTitle(customTitle);
customTitles.Add(customTitle);
ResetAll(this, null);
}
@ -128,7 +128,7 @@ namespace Linaris
Playlist playlist = new Playlist(entry.Text, "", "none.png");
if (!IsInPlaylists(playlist))
{
App.Manager.AddPlaylist(playlist);
(Application.Current as App).Manager.AddPlaylist(playlist);
playlists.Add(playlist);
}
if(entry.BindingContext is CustomTitle customTitle)
@ -148,7 +148,7 @@ namespace Linaris
{
if (button.BindingContext is CustomTitle titleToRemove)
{
App.Manager.RemoveCustomTitle(titleToRemove);
(Application.Current as App).Manager.RemoveCustomTitle(titleToRemove);
customTitles.Remove(titleToRemove);
}
}

@ -5,7 +5,7 @@ namespace Linaris;
public partial class MainPage : ContentPage
{
private ObservableCollection<Album> albums = App.Manager.GetAlbums();
private ObservableCollection<Album> albums = (Application.Current as App).Manager.GetAlbums();
public ObservableCollection<Album> Albums
{

@ -43,8 +43,7 @@
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
<Button WidthRequest="300" HeightRequest="50" Margin="0,20,0,20" BackgroundColor="{StaticResource Primary}" Text="Ajouter d'autres playlists" Clicked="ShowEntryPlaylist" TextColor="White"/>
<Entry WidthRequest="300" HeightRequest="50" Margin="0,20,0,20" BackgroundColor="DimGrey" Text="" Placeholder="Nom de la nouvelle playlist" Completed="CreatePlaylist" IsVisible="{Binding IsNewPlaylist}"/>
<Button WidthRequest="300" HeightRequest="50" Margin="0,20,0,20" BackgroundColor="{StaticResource Primary}" Text="Ajouter d'autres playlists" Clicked="AddPlaylist" TextColor="White"/>
</VerticalStackLayout>
</ScrollView>
<local:FooterPage Grid.Row="1" Grid.ColumnSpan="2"/>

@ -1,30 +1,13 @@
using Model;
using Model.Stub;
using System.Collections.ObjectModel;
namespace Linaris;
public partial class PlaylistsPage : ContentPage
{
private ObservableCollection<Playlist> playlists = (Application.Current as App).Manager.GetPlaylists();
private ObservableCollection<Playlist> playlists = App.Manager.GetPlaylists();
public ObservableCollection<Playlist> Playlists
{
get => playlists;
}
private bool isNewPlaylist = false;
public bool IsNewPlaylist
{
get => isNewPlaylist;
set
{
isNewPlaylist = value;
OnPropertyChanged(nameof(IsNewPlaylist));
}
}
public ObservableCollection<Playlist> Playlists { get => playlists; }
public PlaylistsPage()
{
@ -37,7 +20,6 @@ public partial class PlaylistsPage : ContentPage
void ResetAll(object sender, EventArgs e)
{
ResetSubMenus(sender, e);
IsNewPlaylist = false;
}
void ResetSubMenus(object sender, EventArgs e)
@ -51,19 +33,10 @@ public partial class PlaylistsPage : ContentPage
// Add methods
void CreatePlaylist(object sender, EventArgs e)
async void AddPlaylist(object sender, EventArgs e)
{
if (sender is Entry entry)
{
if (!HasSameName(entry.Text))
{
Playlist playlist = new Playlist(entry.Text, "", "none.png");
App.Manager.AddPlaylist(playlist);
playlists.Add(playlist);
IsNewPlaylist = false;
entry.Text = "";
}
}
await Navigation.PushModalAsync(new AddPlaylistPage());
}
@ -75,7 +48,6 @@ public partial class PlaylistsPage : ContentPage
{
if (button.BindingContext is Playlist playlist)
{
App.Manager.RemovePlaylist(playlist);
playlists.Remove(playlist);
}
}
@ -103,11 +75,6 @@ public partial class PlaylistsPage : ContentPage
}
}
void ShowEntryPlaylist(object sender, EventArgs e)
{
IsNewPlaylist = true;
}
// Change methods
@ -133,19 +100,6 @@ public partial class PlaylistsPage : ContentPage
}
}
// Search methods
bool HasSameName(string name)
{
foreach(Playlist playlist in playlists)
{
if (playlist.Name == name)
{
return true;
}
}
return false;
}
// Navigation
async void GoToPlaylist(object sender, EventArgs e)

@ -1,9 +1,11 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Model.Stub;
public class Manager
{
{
public readonly static int MAX_NAME_LENGTH = 75;
public readonly static int MAX_DESCRIPTION_LENGTH = 500;
@ -79,32 +81,37 @@ public class Manager
public void AddAlbum(Album album)
{
if (GetAlbumByName(album.Name) != null) return;
DataManager.AddAlbum(album);
albums = DataManager.GetAlbums();
albums.Add(album);
}
public void AddCustomTitle(CustomTitle title)
{
if (GetInfoTitleByName(title.Name) != null) return;
DataManager.AddCustomTitle(title);
customTitles = DataManager.GetCustomTitles();
customTitles.Add(title);
}
public void AddInfoTitle(InfoTitle title)
{
if (GetInfoTitleByName(title.Name) != null) return;
DataManager.AddInfoTitle(title);
infoTitles = DataManager.GetInfoTitles();
infoTitles.Add(title);
}
public void AddPlaylist(Playlist playlist)
{
if (GetPlaylistByName(playlist.Name) != null) return;
DataManager.AddPlaylist(playlist);
playlists = DataManager.GetPlaylists();
}
public void AddArtist(Artist artist)
{
if (GetArtistByName(artist.Name) != null) return;
DataManager.AddArtist(artist);
artists = DataManager.GetArtists();
artists.Add(artist);
}
public void RemoveAlbum(Album album)
@ -171,4 +178,24 @@ public class Manager
return DataManager.GetPlaylistByName(name);
}
public Artist? GetArtistByName(string name)
{
return DataManager.GetArtistByName(name);
}
public CustomTitle? GetCustomTitleByUrl(string url)
{
return DataManager.GetCustomTitleByUrl(url);
}
public InfoTitle? GetInfoTitleByName(string name)
{
return DataManager.GetInfoTitleByName(name);
}
public Album? GetAlbumByName(string name)
{
return DataManager.GetAlbumByName(name);
}
}

@ -3,7 +3,6 @@ using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Xml.Serialization;
namespace Model;
@ -20,9 +19,9 @@ public class Playlist : INotifyPropertyChanged
set
{
if (string.IsNullOrWhiteSpace(value) || value.Length > Manager.MAX_NAME_LENGTH)
if (value.Length > Manager.MAX_NAME_LENGTH)
{
value = "IncorrectName";
return;
}
name = value;
OnPropertyChanged();
@ -31,21 +30,6 @@ public class Playlist : INotifyPropertyChanged
private string name = Manager.DEFAULT_NAME;
public string NewName
{
get => newName;
set
{
if (value != null && value.Length < Manager.MAX_NAME_LENGTH)
{
newName = value;
}
}
}
private string newName = Manager.DEFAULT_NAME;
public string Description
{
get => description;
@ -151,7 +135,6 @@ public class Playlist : INotifyPropertyChanged
public Playlist(string nom, string description, string imageURL)
{
Name = nom;
NewName = nom;
Description = description;
ImageURL = imageURL;
}

@ -97,7 +97,6 @@ public class LinqXmlSerialization : IDataManager
Directory.CreateDirectory(XMLPATH);
}
Directory.SetCurrentDirectory(XMLPATH);
SaveAlbums();
LoadSerialization();
}
@ -128,7 +127,7 @@ public class LinqXmlSerialization : IDataManager
public ObservableCollection<Album> GetAlbums()
{
return Albums;
return albums;
}
public List<Artist> GetArtists()
@ -138,17 +137,17 @@ public class LinqXmlSerialization : IDataManager
public ObservableCollection<CustomTitle> GetCustomTitles()
{
return CustomTitles;
return customTitles;
}
public ObservableCollection<InfoTitle> GetInfoTitles()
{
return InfoTitles;
return infoTitles;
}
public ObservableCollection<Playlist> GetPlaylists()
{
return Playlists;
return playlists;
}
public void RemoveAlbum(Album album)

Loading…
Cancel
Save