diff --git a/Sources/Linaris/AddPlaylistPage.xaml b/Sources/Linaris/AddPlaylistPage.xaml
new file mode 100644
index 0000000..ac303db
--- /dev/null
+++ b/Sources/Linaris/AddPlaylistPage.xaml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Sources/Linaris/AddPlaylistPage.xaml.cs b/Sources/Linaris/AddPlaylistPage.xaml.cs
new file mode 100644
index 0000000..0057b2d
--- /dev/null
+++ b/Sources/Linaris/AddPlaylistPage.xaml.cs
@@ -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();
+ }
+}
\ No newline at end of file
diff --git a/Sources/Linaris/EditPlaylistPage.xaml b/Sources/Linaris/EditPlaylistPage.xaml
new file mode 100644
index 0000000..877384e
--- /dev/null
+++ b/Sources/Linaris/EditPlaylistPage.xaml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Sources/Linaris/EditPlaylistPage.xaml.cs b/Sources/Linaris/EditPlaylistPage.xaml.cs
new file mode 100644
index 0000000..2b52ba4
--- /dev/null
+++ b/Sources/Linaris/EditPlaylistPage.xaml.cs
@@ -0,0 +1,62 @@
+using Model;
+using Model.Stub;
+
+namespace Linaris;
+
+public partial class EditPlaylistPage : ContentPage
+{
+
+ private Playlist playlist;
+
+ public Playlist Playlist { get => playlist; }
+
+ public EditPlaylistPage()
+ {
+ InitializeComponent();
+ CopyCurrent();
+ BindingContext = Playlist;
+ }
+
+ private void CopyCurrent()
+ {
+ playlist = new Playlist();
+ playlist.Name = (Application.Current as App).Manager.CurrentPlaylist.Name;
+ playlist.Description = (Application.Current as App).Manager.CurrentPlaylist.Description;
+ playlist.ImageURL = (Application.Current as App).Manager.CurrentPlaylist.ImageURL;
+ }
+
+ 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 void EditPlaylist(object sender, EventArgs e)
+ {
+ (Application.Current as App).Manager.CurrentPlaylist.Name = playlist.Name;
+ (Application.Current as App).Manager.CurrentPlaylist.Description = playlist.Description;
+ (Application.Current as App).Manager.CurrentPlaylist.ImageURL = playlist.ImageURL;
+ Navigation.PopModalAsync();
+ }
+}
\ No newline at end of file
diff --git a/Sources/Linaris/Linaris.csproj b/Sources/Linaris/Linaris.csproj
index 2bf4465..11201ac 100644
--- a/Sources/Linaris/Linaris.csproj
+++ b/Sources/Linaris/Linaris.csproj
@@ -34,7 +34,7 @@
-
+
@@ -73,9 +73,15 @@
+
+ MSBuild:Compile
+
MSBuild:Compile
+
+ MSBuild:Compile
+
MSBuild:Compile
diff --git a/Sources/Linaris/PlaylistPage.xaml b/Sources/Linaris/PlaylistPage.xaml
index de2b10d..426d75d 100644
--- a/Sources/Linaris/PlaylistPage.xaml
+++ b/Sources/Linaris/PlaylistPage.xaml
@@ -1,16 +1,12 @@
+
-
-
-
-
@@ -21,75 +17,31 @@
-
-
-
-
-
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Sources/Linaris/PlaylistPage.xaml.cs b/Sources/Linaris/PlaylistPage.xaml.cs
index cb8f24b..e95a23b 100644
--- a/Sources/Linaris/PlaylistPage.xaml.cs
+++ b/Sources/Linaris/PlaylistPage.xaml.cs
@@ -5,5 +5,11 @@ public partial class PlaylistPage : ContentPage
public PlaylistPage()
{
InitializeComponent();
+ BindingContext = (Application.Current as App).Manager.CurrentPlaylist;
}
+
+ private async void EditPlaylist(object sender, EventArgs e)
+ {
+ await Navigation.PushModalAsync(new EditPlaylistPage());
+ }
}
\ No newline at end of file
diff --git a/Sources/Linaris/PlaylistsPage.xaml b/Sources/Linaris/PlaylistsPage.xaml
index b35cd71..d393c5c 100644
--- a/Sources/Linaris/PlaylistsPage.xaml
+++ b/Sources/Linaris/PlaylistsPage.xaml
@@ -43,8 +43,7 @@
-
-
+
diff --git a/Sources/Linaris/PlaylistsPage.xaml.cs b/Sources/Linaris/PlaylistsPage.xaml.cs
index 965798a..00a74eb 100644
--- a/Sources/Linaris/PlaylistsPage.xaml.cs
+++ b/Sources/Linaris/PlaylistsPage.xaml.cs
@@ -1,30 +1,13 @@
using Model;
-using Model.Stub;
using System.Collections.ObjectModel;
namespace Linaris;
public partial class PlaylistsPage : ContentPage
{
-
private ObservableCollection playlists = (Application.Current as App).Manager.GetPlaylists();
- public ObservableCollection Playlists
- {
- get => playlists;
- }
-
- private bool isNewPlaylist = false;
-
- public bool IsNewPlaylist
- {
- get => isNewPlaylist;
- set
- {
- isNewPlaylist = value;
- OnPropertyChanged(nameof(IsNewPlaylist));
- }
- }
+ public ObservableCollection 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,9 @@ 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");
- (Application.Current as App).Manager.AddPlaylist(playlist);
- playlists.Add(playlist);
- IsNewPlaylist = false;
- entry.Text = "";
- }
- }
+ await Navigation.PushModalAsync(new AddPlaylistPage());
}
@@ -75,7 +47,6 @@ public partial class PlaylistsPage : ContentPage
{
if (button.BindingContext is Playlist playlist)
{
- (Application.Current as App).Manager.RemovePlaylist(playlist);
playlists.Remove(playlist);
}
}
@@ -103,11 +74,6 @@ public partial class PlaylistsPage : ContentPage
}
}
- void ShowEntryPlaylist(object sender, EventArgs e)
- {
- IsNewPlaylist = true;
- }
-
// Change methods
@@ -133,24 +99,17 @@ public partial class PlaylistsPage : ContentPage
}
}
- // Search methods
+ // Navigation
- bool HasSameName(string name)
+ async void GoToPlaylist(object sender, EventArgs e)
{
- foreach(Playlist playlist in playlists)
+ if (sender is Button button)
{
- if (playlist.Name == name)
+ if (button.BindingContext is Playlist playlist)
{
- return true;
+ (Application.Current as App).Manager.CurrentPlaylist = playlist;
}
}
- return false;
- }
-
- // Navigation
-
- async void GoToPlaylist(object sender, EventArgs e)
- {
await Navigation.PushAsync(new PlaylistPage());
}
}
\ No newline at end of file
diff --git a/Sources/Model/IDataManager.cs b/Sources/Model/IDataManager.cs
index 8cfc498..18dc8d1 100644
--- a/Sources/Model/IDataManager.cs
+++ b/Sources/Model/IDataManager.cs
@@ -28,7 +28,7 @@ public interface IDataManager
// Read
ObservableCollection GetCustomTitles();
- CustomTitle? GetCustomTitleByName(string custom);
+ CustomTitle? GetCustomTitleByUrl(string custom);
ObservableCollection GetInfoTitles();
@@ -50,7 +50,7 @@ public interface IDataManager
// Update
void UpdateCustomTitle(CustomTitle title, string name, string url, string info, string path);
- void UpdateCustomTitleByName(string name, string newUrl, string info, string path);
+ void UpdateCustomTitleByUrl(string url, string name, string newUrl, string info, string path);
void UpdateInfoTitle(InfoTitle title, string name, string url, string info, Artist artist, string description, Genre genre);
diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs
index cc4837e..7d2d8a9 100644
--- a/Sources/Model/Manager.cs
+++ b/Sources/Model/Manager.cs
@@ -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;
@@ -66,9 +68,9 @@ public class Manager
}
}
- private Album currentAlbum;
+ private Album? currentAlbum;
- public Album CurrentAlbum
+ public Album? CurrentAlbum
{
get
{
@@ -80,6 +82,17 @@ public class Manager
}
}
+ private Playlist? currentPlaylist;
+
+ public Playlist? CurrentPlaylist
+ {
+ get => currentPlaylist;
+ set
+ {
+ currentPlaylist = value;
+ }
+ }
+
public Manager(IDataManager dataManager)
{
DataManager = dataManager;
@@ -89,35 +102,42 @@ public class Manager
infoTitles = DataManager.GetInfoTitles();
playlists = DataManager.GetPlaylists();
artists = DataManager.GetArtists();
- currentAlbum = albums.First();
+
+ currentAlbum = albums.FirstOrDefault();
+ currentPlaylist = playlists.FirstOrDefault();
}
public void AddAlbum(Album album)
{
+ if (GetAlbumByName(album.Name) != null) return;
DataManager.AddAlbum(album);
albums = DataManager.GetAlbums();
}
public void AddCustomTitle(CustomTitle title)
{
+ if (GetInfoTitleByName(title.Name) != null) return;
DataManager.AddCustomTitle(title);
customTitles = DataManager.GetCustomTitles();
}
public void AddInfoTitle(InfoTitle title)
{
+ if (GetInfoTitleByName(title.Name) != null) return;
DataManager.AddInfoTitle(title);
infoTitles = DataManager.GetInfoTitles();
}
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();
}
@@ -186,4 +206,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);
+ }
+
}
diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs
index da4862e..c88482e 100644
--- a/Sources/Model/Playlist.cs
+++ b/Sources/Model/Playlist.cs
@@ -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 (string.IsNullOrEmpty(value) || value.Length > Manager.MAX_NAME_LENGTH)
{
- value = "IncorrectName";
+ return;
}
name = value;
OnPropertyChanged();
diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs
index 1ebb941..5e3db86 100644
--- a/Sources/Model/Serialization/LINQ_XML_Serialization.cs
+++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs
@@ -108,8 +108,6 @@ public class LinqXmlSerialization : IDataManager
Directory.CreateDirectory(XMLPATH);
}
Directory.SetCurrentDirectory(XMLPATH);
- SaveAlbums();
- SaveInfoTitles();
LoadSerialization();
}
@@ -260,7 +258,7 @@ public class LinqXmlSerialization : IDataManager
foreach(var custom in customsList)
{
- CustomTitle? customTitle = GetCustomTitleByName(custom);
+ CustomTitle? customTitle = GetCustomTitleByUrl(custom);
if (customTitle == null)
{
@@ -743,11 +741,11 @@ public class LinqXmlSerialization : IDataManager
return null;
}
- public CustomTitle? GetCustomTitleByName(string custom)
+ public CustomTitle? GetCustomTitleByUrl(string custom)
{
foreach(CustomTitle customTitle in customTitles)
{
- if(customTitle.Name == custom)
+ if(customTitle.ImageURL == custom)
{
return customTitle;
}
@@ -815,9 +813,9 @@ public class LinqXmlSerialization : IDataManager
title.Path = path;
}
- public void UpdateCustomTitleByName(string name, string newUrl, string info, string path)
+ public void UpdateCustomTitleByUrl(string url, string name, string newUrl, string info, string path)
{
- CustomTitle? title = GetCustomTitleByName(name);
+ CustomTitle? title = GetCustomTitleByUrl(url);
if (title != null)
{
title.Name = name;
diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs
index 56ba7e9..5456910 100644
--- a/Sources/Model/Stub/StubManager.cs
+++ b/Sources/Model/Stub/StubManager.cs
@@ -236,11 +236,11 @@ public class StubManager : IDataManager
// Doesn't do anything because it's Stubs
}
- public CustomTitle? GetCustomTitleByName(string custom)
+ public CustomTitle? GetCustomTitleByUrl(string custom)
{
foreach (CustomTitle customTitle in StubCustomTitle.GetCustomTitles())
{
- if (customTitle.Name == custom)
+ if (customTitle.ImageURL == custom)
{
return customTitle;
}
@@ -344,9 +344,9 @@ public class StubManager : IDataManager
title.Path = path;
}
- public void UpdateCustomTitleByName(string name, string newUrl, string info, string path)
+ public void UpdateCustomTitleByUrl(string url, string name, string newUrl, string info, string path)
{
- CustomTitle? title = GetCustomTitleByName(name);
+ CustomTitle? title = GetCustomTitleByUrl(url);
if (title != null)
{
title.Name = name;