Enhance footer
continuous-integration/drone/push Build is failing Details

pull/33/head
Corentin LEMAIRE 2 years ago
parent 2e307e5974
commit bd205913fc

@ -57,7 +57,7 @@
</ScrollView>
<local:FooterPage Grid.Row="1" Grid.ColumnSpan="2"/>
<local:FooterPage x:Name="Footer" Grid.Row="1" Grid.ColumnSpan="2"/>
</Grid>

@ -1,3 +1,4 @@
using CommunityToolkit.Maui.Views;
using Model;
namespace Linaris;
@ -20,7 +21,8 @@ public partial class AlbumPage : ContentPage
InitializeComponent();
album = (Application.Current as App).Manager.CurrentAlbum;
BindingContext = album;
}
}
private async void GoToInfoTitle(object sender, EventArgs e)
{
@ -30,4 +32,15 @@ public partial class AlbumPage : ContentPage
await Navigation.PushAsync(new InfoTitlePage());
}
}
protected override void OnDisappearing()
{
base.OnDisappearing();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
{
musicElement.Stop();
}
}
}

@ -2,15 +2,16 @@
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:model="clr-namespace:Model;assembly=Model"
x:Class="Linaris.FooterPage">
<Grid Grid.ColumnSpan="2" Grid.Row="1" BackgroundColor="Gray" ColumnDefinitions="16*,7*">
<toolkit:MediaElement Source="embed://peaches.mp3" ShouldShowPlaybackControls="True" Grid.Column="0" Speed="1" ShouldKeepScreenOn="false"/>
<toolkit:MediaElement x:Name="music" Source="{Binding Path}" BackgroundColor="Transparent" ShouldShowPlaybackControls="True" ShouldAutoPlay="True" Grid.Column="0" Speed="1" ShouldKeepScreenOn="false" MediaEnded="OnCompleted"/>
<Grid Grid.Column="1" HorizontalOptions="CenterAndExpand" RowDefinitions="*,*" ColumnDefinitions="*,*">
<ImageButton Style="{StaticResource FooterButton}" Source="rdm.png" Grid.Row="0" Grid.Column="0"/>
<ImageButton Style="{StaticResource FooterButton}" Source="loop.png" Grid.Row="0" Grid.Column="1"/>
<ImageButton Style="{StaticResource FooterButton}" Clicked="ShuffleButton_Clicked" Source="rdm.png" Grid.Row="0" Grid.Column="0"/>
<ImageButton Style="{StaticResource FooterButton}" Clicked="LoopButton_Clicked" Source="loop.png" Grid.Row="0" Grid.Column="1"/>
<ImageButton Style="{StaticResource FooterButton}" Clicked="RewindButton_Clicked" Source="back.png" Grid.Row="1" Grid.Column="0"/>
<ImageButton Style="{StaticResource FooterButton}" Clicked="NextButton_Clicked" Source="next.png" Grid.Row="1" Grid.Column="1"/>
</Grid>

@ -1,95 +1,58 @@
using NAudio.Wave;
using Plugin.Maui.Audio;
using Model;
using Model.Stub;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Linaris;
public partial class FooterPage : ContentView
public partial class FooterPage : ContentView, INotifyPropertyChanged
{
public FooterPage()
{
InitializeComponent();
BindingContext = (Application.Current as App).Manager;
}
public void RewindButton_Clicked(Object sender, EventArgs e)
{
/*audioFile.Position = 0;
outputDevice?.Play();
Play.Source = "pause.png";
Timer_Elapsed(sender, e);
timer = new System.Timers.Timer(1000);
timer.Elapsed += Timer_Elapsed;
timer.Enabled = true;*/
}
private readonly Manager Manager = (Application.Current as App).Manager;
public void NextButton_Clicked(Object sender, EventArgs e)
public FooterPage()
{
/*audioFile.Position = audioFile.Length;*/
InitializeComponent();
BindingContext = Manager.CurrentPlaying;
}
public void StopButton_Clicked(object sender, EventArgs e)
{
/*outputDevice.Stop();
audioFile.Position = 0;*/
}
public void Slider_ValueChanged(object sender, ValueChangedEventArgs e)
public void RewindButton_Clicked(object sender, EventArgs e)
{
/*outputDevice.Volume = (float)e.NewValue;*/
if (Manager.CurrentPlaylist == null || Manager.CurrentPlaying == null) return;
Manager.PreviousTitle();
Dispatcher.DispatchAsync(() =>
{
music.Source = Manager.CurrentPlaying.Path;
});
}
public void Bar_ValueChanged(object sender, ValueChangedEventArgs e)
public void NextButton_Clicked(object sender, EventArgs e)
{
/*if (changementManuel)
if (Manager.CurrentPlaylist == null || Manager.CurrentPlaying == null) return;
Manager.NextTitle();
Dispatcher.DispatchAsync(() =>
{
double totalSeconds = audioFile.TotalTime.TotalSeconds;
double newPosition = e.NewValue * totalSeconds;
audioFile.CurrentTime = TimeSpan.FromSeconds(newPosition);
}
else
{
changementManuel = true;
}*/
music.Source = Manager.CurrentPlaying.Path;
});
}
private void PlaybackStoppedHandler(object sender, StoppedEventArgs e)
public void ShuffleButton_Clicked(object sender, EventArgs e)
{
/*if (closing)
{
outputDevice.Dispose();
audioFile.Dispose();
}
else
{
Play.Dispatcher.Dispatch(() => Play.Source = "play.png");
}*/
Manager.Shuffle();
}
private void Timer_Elapsed(object sender, EventArgs e)
public void LoopButton_Clicked(object sender, EventArgs e)
{
/*TimeSpan totalTimeSpan = audioFile.TotalTime;
TimeSpan currentTimeSpan = audioFile.CurrentTime;
string totalTimeFormatted = totalTimeSpan.ToString(@"hh\:mm\:ss");
string currentTimeFormatted = currentTimeSpan.ToString(@"hh\:mm\:ss");
changementManuel = false;
bar.Dispatcher.Dispatch(() => bar.Value = audioFile.CurrentTime.TotalSeconds / audioFile.TotalTime.TotalSeconds);
currentTime.Dispatcher.Dispatch(() => currentTime.Text = currentTimeFormatted);
endTime.Dispatcher.Dispatch(() => endTime.Text = totalTimeFormatted);*/
Manager.Loop();
}
private void LoadNewAudioFile(string filePath)
public void OnCompleted(object sender, EventArgs e)
{
/*if (outputDevice.PlaybackState == PlaybackState.Playing)
if (Manager.CurrentPlaying == null) return;
Manager.NextTitle();
Dispatcher.DispatchAsync(() =>
{
outputDevice.Stop();
}
audioFile = new AudioFileReader(filePath);
outputDevice.Init(audioFile);*/
music.Source = Manager.CurrentPlaying.Path;
});
}
}

@ -29,6 +29,6 @@
</ScrollView>
</VerticalStackLayout>
</ScrollView>
<local:FooterPage Grid.Row="1" Grid.ColumnSpan="2"/>
<local:FooterPage x:Name="Footer" Grid.Row="1" Grid.ColumnSpan="2"/>
</Grid>
</ContentPage>

@ -1,3 +1,4 @@
using CommunityToolkit.Maui.Views;
using Model;
namespace Linaris;
@ -25,4 +26,15 @@ public partial class InfoTitlePage : ContentPage
artist = (Application.Current as App).Manager.GetAlbumById(infoTitle.AlbumID).Artist;
BindingContext = this;
}
protected override void OnDisappearing()
{
base.OnDisappearing();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
{
musicElement.Stop();
}
}
}

@ -4,9 +4,9 @@
x:Class="Linaris.Layout">
<VerticalStackLayout BackgroundColor="black" Spacing="20" Padding="0,20,0,0">
<Button Text="Home" Style="{StaticResource buttons}" Clicked="Go_Home"/>
<Button Text="Albums" Style="{StaticResource buttons}" Clicked="Go_Home"/>
<Button Text="Playlists" Style="{StaticResource buttons}" Clicked="Go_Playlists"/>
<Button Text="Files" Style="{StaticResource buttons}" Clicked="Go_Files"/>
<Button Text="Fichiers" Style="{StaticResource buttons}" Clicked="Go_Files"/>
</VerticalStackLayout>
</ContentView>

@ -1,3 +1,5 @@
using CommunityToolkit.Maui.Views;
namespace Linaris;
public partial class Layout : ContentView
@ -8,22 +10,51 @@ public partial class Layout : ContentView
}
private async void Go_Home(object sender, EventArgs e)
{
{
StopMusic();
await Navigation.PopToRootAsync();
}
private async void Go_Playlists(object sender, EventArgs e)
{
await Navigation.PushAsync(new PlaylistsPage());
}
{
StopMusic();
await Navigation.PushAsync(new PlaylistsPage());
}
private async void Go_Back(object sender, EventArgs e)
{
await Navigation.PopAsync();
{
StopMusic();
await Navigation.PopAsync();
}
private async void Go_Files(object sender, EventArgs e)
{
{
StopMusic();
await Navigation.PushAsync(new LocalFilesPage());
}
private void StopMusic()
{
var parentPage = GetParentPage(this);
if (parentPage == null) return;
ContentView footer = parentPage.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
{
musicElement.Stop();
}
}
private ContentPage GetParentPage(Element element)
{
Element parent = element?.Parent;
while (parent != null)
{
if (parent is ContentPage contentPage)
{
return contentPage;
}
parent = parent.Parent;
}
return null;
}
}

@ -30,9 +30,10 @@
<Label Text="{Binding Name}" Style="{StaticResource Titre}" HorizontalTextAlignment="Center" WidthRequest="250" LineBreakMode="TailTruncation"/>
</VerticalStackLayout>
<Grid IsVisible="{Binding IsSubMenuVisible}" BackgroundColor="Grey" HeightRequest="125" WidthRequest="155" Grid.Column="0" RowDefinitions="*,*,*">
<Button Grid.Row="0" Text="Ajouter à une playlist" Clicked="ShowPlaylistMenu"/>
<Button Grid.Row="1" Text="Supprimer" Clicked="RemoveCustomTitle"/>
<Grid IsVisible="{Binding IsSubMenuVisible}" BackgroundColor="Grey" HeightRequest="125" WidthRequest="155" Grid.Column="0" RowDefinitions="*,*,*,*">
<Button Grid.Row="0" Text="Jouer" Clicked="Play"/>
<Button Grid.Row="1" Text="Ajouter à une playlist" Clicked="ShowPlaylistMenu"/>
<Button Grid.Row="2" Text="Supprimer" Clicked="RemoveCustomTitle"/>
<Button Grid.Row="3" Text="Changer l'image" Clicked="ChangeImage"/>
</Grid>
<ScrollView Grid.Column="1" IsVisible="{Binding IsPlaylistMenuVisible}" BackgroundColor="Grey" WidthRequest="150" HeightRequest="200">
@ -59,7 +60,7 @@
<Button WidthRequest="300" HeightRequest="50" Margin="0,20,0,20" BackgroundColor="{StaticResource Primary}" Text="Ajouter d'autres titres" Clicked="AddTitles"/>
</VerticalStackLayout>
</ScrollView>
<local:FooterPage Grid.Row="1" Grid.ColumnSpan="2"/>
<local:FooterPage x:Name="Footer" Grid.Row="1" Grid.ColumnSpan="2"/>
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="ResetAll"/>
</Grid.GestureRecognizers>

@ -1,263 +1,274 @@
using CommunityToolkit.Maui.Views;
using Model;
using System.Collections.ObjectModel;
namespace Linaris
namespace Linaris;
public partial class LocalFilesPage : ContentPage
{
public partial class LocalFilesPage : ContentPage
{
private ObservableCollection<CustomTitle> customTitles = (Application.Current as App).Manager.GetCustomTitles();
private ObservableCollection<CustomTitle> customTitles = (Application.Current as App).Manager.GetCustomTitles();
public ObservableCollection<CustomTitle> CustomTitles
{
get => customTitles;
}
public ObservableCollection<CustomTitle> CustomTitles
{
get => customTitles;
}
private ObservableCollection<Playlist> playlists = (Application.Current as App).Manager.GetPlaylists();
private ObservableCollection<Playlist> playlists = (Application.Current as App).Manager.GetPlaylists();
public ObservableCollection<Playlist> Playlists
{
get => playlists;
}
public ObservableCollection<Playlist> Playlists
{
get => playlists;
}
public LocalFilesPage()
{
InitializeComponent();
BindingContext = this;
}
public LocalFilesPage()
{
InitializeComponent();
BindingContext = this;
}
// Reset methods
// Reset methods
void ResetAll(object sender, EventArgs e)
{
ResetSubMenus(sender, e);
}
void ResetAll(object sender, EventArgs e)
{
ResetSubMenus(sender, e);
}
void ResetSubMenus(object sender, EventArgs e)
void ResetSubMenus(object sender, EventArgs e)
{
foreach (var CustomTitle in customTitles)
{
foreach (var CustomTitle in customTitles)
{
CustomTitle.IsSubMenuVisible = false;
}
ResetPlaylistMenu(sender, e);
CustomTitle.IsSubMenuVisible = false;
}
void ResetPlaylistMenu(object sender, EventArgs e)
ResetPlaylistMenu(sender, e);
}
void ResetPlaylistMenu(object sender, EventArgs e)
{
foreach (CustomTitle customTitle in CustomTitles)
{
foreach (CustomTitle customTitle in CustomTitles)
{
customTitle.IsPlaylistMenuVisible = false;
customTitle.IsNewPlaylistMenuVisible = false;
}
customTitle.IsPlaylistMenuVisible = false;
customTitle.IsNewPlaylistMenuVisible = false;
}
}
// Add methods
// Add methods
void AddCustomTitle(CustomTitle customTitle)
{
(Application.Current as App).Manager.AddCustomTitle(customTitle);
customTitles = (Application.Current as App).Manager.GetCustomTitles();
ResetAll(this, null);
}
void AddCustomTitle(CustomTitle customTitle)
{
(Application.Current as App).Manager.AddCustomTitle(customTitle);
customTitles = (Application.Current as App).Manager.GetCustomTitles();
ResetAll(this, null);
}
private async void AddTitles(object sender, EventArgs e)
private async void AddTitles(object sender, EventArgs e)
{
var results = await FilePicker.PickMultipleAsync(new PickOptions
{
var results = await FilePicker.PickMultipleAsync(new PickOptions
{
PickerTitle = "Choisissez des nouveaux titres !",
FileTypes = new FilePickerFileType(
new Dictionary<DevicePlatform, IEnumerable<string>>
{
{ DevicePlatform.WinUI, new [] { "*.mp3", "*.m4a" } },
{ DevicePlatform.Android, new [] { "*.mp3", ".3gp", ".mp4", ".m4a", ".aac", ".ts", ".amr", ".flac", ".mid", ".xmf", ".mxmf", ".rtttl", ".rtx", ".ota", ".imy", ".mkv", ".ogg", ".wav" } },
{ DevicePlatform.iOS, new[] { "*.mp3", "*.aac", "*.aifc", "*.au", "*.aiff", "*.mp2", "*.3gp", "*.ac3" } }
})
});
if (results == null)
{
return;
}
if (sender is Button button)
{
foreach (var result in results)
PickerTitle = "Choisissez des nouveaux titres !",
FileTypes = new FilePickerFileType(
new Dictionary<DevicePlatform, IEnumerable<string>>
{
CustomTitle custom = new CustomTitle(result.FileName, "none.png", "", result.FullPath);
if (!IsCustomTitleInCollection(custom))
{
AddCustomTitle(custom);
}
}
}
}
{ DevicePlatform.WinUI, new [] { "*.mp3", "*.m4a" } },
{ DevicePlatform.Android, new [] { "*.mp3", ".3gp", ".mp4", ".m4a", ".aac", ".ts", ".amr", ".flac", ".mid", ".xmf", ".mxmf", ".rtttl", ".rtx", ".ota", ".imy", ".mkv", ".ogg", ".wav" } },
{ DevicePlatform.iOS, new[] { "*.mp3", "*.aac", "*.aifc", "*.au", "*.aiff", "*.mp2", "*.3gp", "*.ac3" } }
})
});
string SaveIconToDataFolder(MemoryStream stream, string iconName)
if (results == null)
{
string dataFolderPath = FileSystem.AppDataDirectory;
string iconPath = Path.Combine(dataFolderPath, $"{iconName}.png");
return;
}
using (FileStream fileStream = new FileStream(iconPath, FileMode.Create, FileAccess.Write))
if (sender is Button button)
{
foreach (var result in results)
{
stream.Position = 0;
stream.CopyTo(fileStream);
CustomTitle custom = new CustomTitle(result.FileName, "none.png", "", result.FullPath);
if (!IsCustomTitleInCollection(custom))
{
AddCustomTitle(custom);
}
}
return iconPath;
}
}
async void AddToPlaylist(object sender, EventArgs e)
async void AddToPlaylist(object sender, EventArgs e)
{
if (sender is Button button)
{
if (sender is Button button)
if (button.BindingContext is Playlist playlist)
{
if (button.BindingContext is Playlist playlist)
if (button.Parent is StackLayout stack && stack.BindingContext is CustomTitle customTitle)
{
if (button.Parent is StackLayout stack && stack.BindingContext is CustomTitle customTitle)
if (playlist.HasCustomTitle(customTitle))
{
if (playlist.HasCustomTitle(customTitle))
{
await DisplayAlert("Erreur !", "Ce morceau est déjà dans cette playlist !", "OK");
return;
}
playlist.AddTitle(customTitle);
ResetAll(sender, e);
await DisplayAlert("Erreur !", "Ce morceau est déjà dans cette playlist !", "OK");
return;
}
playlist.AddTitle(customTitle);
ResetAll(sender, e);
}
}
}
}
void AddPlaylist(object sender, EventArgs e)
void AddPlaylist(object sender, EventArgs e)
{
if (sender is Entry entry)
{
if (sender is Entry entry)
Playlist playlist = new Playlist(entry.Text, "", "none.png");
if (!IsInPlaylists(playlist))
{
Playlist playlist = new Playlist(entry.Text, "", "none.png");
if (!IsInPlaylists(playlist))
{
(Application.Current as App).Manager.AddPlaylist(playlist);
playlists.Add(playlist);
}
if(entry.BindingContext is CustomTitle customTitle)
{
customTitle.IsNewPlaylistMenuVisible = false;
entry.Text = "";
}
(Application.Current as App).Manager.AddPlaylist(playlist);
playlists = (Application.Current as App).Manager.GetPlaylists();
}
if(entry.BindingContext is CustomTitle customTitle)
{
customTitle.IsNewPlaylistMenuVisible = false;
entry.Text = "";
}
}
}
// Remove methods
// Remove methods
void RemoveCustomTitle(object sender, EventArgs e)
void RemoveCustomTitle(object sender, EventArgs e)
{
if (sender is Button button)
{
if (sender is Button button)
if (button.BindingContext is CustomTitle titleToRemove)
{
if (button.BindingContext is CustomTitle titleToRemove)
{
(Application.Current as App).Manager.RemoveCustomTitle(titleToRemove);
customTitles.Remove(titleToRemove);
}
(Application.Current as App).Manager.RemoveCustomTitle(titleToRemove);
customTitles.Remove(titleToRemove);
}
}
}
// Show methods
// Show methods
void ShowSubMenu(object sender, EventArgs e)
void ShowSubMenu(object sender, EventArgs e)
{
if (sender is Image image)
{
if (sender is Image image)
if (image.BindingContext is CustomTitle customTitle)
{
if (image.BindingContext is CustomTitle customTitle)
if (!customTitle.IsSubMenuVisible)
{
if (!customTitle.IsSubMenuVisible)
{
ResetAll(sender, e);
customTitle.IsSubMenuVisible = true;
}
else
{
ResetSubMenus(sender, e);
}
ResetAll(sender, e);
customTitle.IsSubMenuVisible = true;
}
else
{
ResetSubMenus(sender, e);
}
}
}
}
void ShowPlaylistMenu(object sender, EventArgs e)
void ShowPlaylistMenu(object sender, EventArgs e)
{
if (sender is Button button)
{
if (sender is Button button)
if (button.BindingContext is CustomTitle customTitle)
{
if (button.BindingContext is CustomTitle customTitle)
if (!customTitle.IsPlaylistMenuVisible)
{
if (!customTitle.IsPlaylistMenuVisible)
{
customTitle.IsPlaylistMenuVisible = true;
}
customTitle.IsPlaylistMenuVisible = true;
}
}
}
}
void ShowNewPlaylistMenu(object sender, EventArgs e)
void ShowNewPlaylistMenu(object sender, EventArgs e)
{
if (sender is Button button)
{
if (sender is Button button)
if (button.BindingContext is CustomTitle customTitle)
{
if (button.BindingContext is CustomTitle customTitle)
if (!customTitle.IsNewPlaylistMenuVisible)
{
if (!customTitle.IsNewPlaylistMenuVisible)
{
customTitle.IsNewPlaylistMenuVisible = true;
}
customTitle.IsNewPlaylistMenuVisible = true;
}
}
}
}
// Change methods
// Change methods
private async void ChangeImage(object sender, EventArgs e)
{
var result = await FilePicker.PickAsync(new PickOptions
{
PickerTitle = "Choisissez une nouvelle image !",
FileTypes = FilePickerFileType.Images
});
private async void ChangeImage(object sender, EventArgs e)
if (result == null)
{
var result = await FilePicker.PickAsync(new PickOptions
{
PickerTitle = "Choisissez une nouvelle image !",
FileTypes = FilePickerFileType.Images
});
return;
}
if (result == null)
if (sender is Button button)
{
if (button.BindingContext is CustomTitle customTitle)
{
return;
customTitle.ImageURL = result.FullPath;
}
}
}
if (sender is Button button)
// Search methods
bool IsCustomTitleInCollection(CustomTitle customTitle)
{
foreach(var custom in customTitles)
{
if (customTitle.Equals(custom))
{
if (button.BindingContext is CustomTitle customTitle)
{
customTitle.ImageURL = result.FullPath;
}
return true;
}
}
return false;
}
// Search methods
bool IsCustomTitleInCollection(CustomTitle customTitle)
bool IsInPlaylists(Playlist playlist)
{
foreach (Playlist p in playlists)
{
foreach(var custom in customTitles)
if (p.Equals(playlist))
{
if (customTitle.Equals(custom))
{
return true;
}
return true;
}
return false;
}
return false;
}
bool IsInPlaylists(Playlist playlist)
protected override void OnDisappearing()
{
base.OnDisappearing();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
{
foreach (Playlist p in playlists)
musicElement.Stop();
}
}
private void Play(object sender, EventArgs e)
{
if (sender is Button button && button.BindingContext is CustomTitle customTitle)
{
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
{
if (p.Equals(playlist))
{
return true;
}
musicElement.Source = customTitle.Path;
}
return false;
}
}
}

@ -39,7 +39,7 @@
</ScrollView>
<local:FooterPage Grid.Row="1" Grid.ColumnSpan="2"/>
<local:FooterPage x:Name="Footer" Grid.Row="1" Grid.ColumnSpan="2"/>
</Grid>

@ -31,5 +31,16 @@ public partial class MainPage : ContentPage
}
}
}
protected override void OnDisappearing()
{
base.OnDisappearing();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
{
musicElement.Stop();
}
}
}

@ -42,6 +42,6 @@
</ListView>
</VerticalStackLayout>
</ScrollView>
<local:FooterPage Grid.Row="1" Grid.ColumnSpan="2"/>
<local:FooterPage x:Name="Footer" Grid.Row="1" Grid.ColumnSpan="2"/>
</Grid>
</ContentPage>

@ -1,13 +1,17 @@
using CommunityToolkit.Maui.Views;
using Model;
using Model.Stub;
namespace Linaris;
public partial class PlaylistPage : ContentPage
{
private readonly Manager Manager = (Application.Current as App).Manager;
public PlaylistPage()
{
InitializeComponent();
BindingContext = (Application.Current as App).Manager.CurrentPlaylist;
BindingContext = Manager.CurrentPlaylist;
}
private async void EditPlaylist(object sender, EventArgs e)
@ -21,7 +25,7 @@ public partial class PlaylistPage : ContentPage
{
if (menuItem.BindingContext is CustomTitle customTitle)
{
(Application.Current as App).Manager.GetPlaylistByName((Application.Current as App).Manager.CurrentPlaylist.Name).RemoveTitle(customTitle);
Manager.GetPlaylistByName(Manager.CurrentPlaylist.Name).RemoveTitle(customTitle);
}
}
}
@ -33,20 +37,47 @@ public partial class PlaylistPage : ContentPage
{
if (button.BindingContext is Playlist playlist)
{
(Application.Current as App).Manager.CurrentPlaying = playlist.Titles.FirstOrDefault();
if ((Application.Current as App).Manager.CurrentPlaying == null) return;
Manager.CurrentPlaylist = playlist;
Manager.NextTitle();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
{
if (Manager.CurrentPlaying == null) return;
musicElement.Source = Manager.CurrentPlaying.Path;
}
}
}
}
private void RdmPlay(object sender, EventArgs e)
{
/*if (sender is Button button)
{
if (button.BindingContext is Playlist playlist)
{
(Application.Current as App).Manager.CurrentPlaying = playlist.GetCurrentTitle();
{
if (sender is Button button)
{
if (button.BindingContext is Playlist playlist)
{
Manager.CurrentPlaylist = playlist;
Manager.Shuffle();
Manager.NextTitle();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
{
if (Manager.CurrentPlaying == null) return;
musicElement.Source = Manager.CurrentPlaying.Path;
}
}
}*/
}
}
protected override void OnDisappearing()
{
base.OnDisappearing();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
{
musicElement.Stop();
}
}
}

@ -46,7 +46,7 @@
<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"/>
<local:FooterPage x:Name="Footer" Grid.Row="1" Grid.ColumnSpan="2"/>
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="ResetAll"/>
</Grid.GestureRecognizers>

@ -1,3 +1,4 @@
using CommunityToolkit.Maui.Views;
using Model;
using System.Collections.ObjectModel;
@ -112,4 +113,15 @@ public partial class PlaylistsPage : ContentPage
}
await Navigation.PushAsync(new PlaylistPage());
}
protected override void OnDisappearing()
{
base.OnDisappearing();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
{
musicElement.Stop();
}
}
}

@ -4,8 +4,13 @@ using System.Runtime.CompilerServices;
namespace Model.Stub;
public class Manager
{
public class Manager : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
public readonly static int MAX_NAME_LENGTH = 75;
public readonly static int MAX_DESCRIPTION_LENGTH = 500;
@ -72,13 +77,11 @@ public class Manager
public Album CurrentAlbum
{
get
{
return currentAlbum;
}
get => currentAlbum;
set
{
currentAlbum = value;
OnPropertyChanged();
}
}
@ -90,6 +93,7 @@ public class Manager
set
{
currentPlaylist = value;
OnPropertyChanged();
}
}
@ -101,6 +105,7 @@ public class Manager
set
{
currentInfoTitle = value;
OnPropertyChanged();
}
}
@ -112,6 +117,7 @@ public class Manager
set
{
currentPlaying = value;
OnPropertyChanged();
}
}
@ -127,10 +133,40 @@ public class Manager
currentAlbum = albums.First();
currentPlaylist = playlists.FirstOrDefault();
currentInfoTitle = infoTitles.FirstOrDefault();
currentInfoTitle = null;
currentPlaying = null;
}
public void NextTitle()
{
if (currentPlaylist == null) return;
currentPlaying = currentPlaylist.NextTitle();
}
public void PreviousTitle()
{
if (CurrentPlaying == null) return;
currentPlaying = currentPlaylist.PreviousTitle();
}
public CustomTitle CurrentTitle()
{
if (CurrentPlaylist == null) return null;
return currentPlaylist.GetCurrentTitle();
}
public void Loop()
{
if (CurrentPlaylist == null) return;
currentPlaylist.LoopTitle = !currentPlaylist.LoopTitle;
}
public void Shuffle()
{
if (CurrentPlaylist == null) return;
currentPlaylist.Shuffle = !currentPlaylist.Shuffle;
}
public void AddAlbum(Album album)
{
if (GetAlbumByName(album.Name) != null) return;

@ -92,19 +92,17 @@ public class Playlist : INotifyPropertyChanged
{
index = value;
}
else if(Loop)
else
{
index = 0;
}
}
}
private int index = 0;
private int index = -1;
public bool Shuffle { get; set; } = false;
public bool Loop { get; set; } = false;
public bool LoopTitle { get; set; } = false;
private readonly List<int> played = new List<int>();
@ -139,10 +137,7 @@ public class Playlist : INotifyPropertyChanged
ImageURL = imageURL;
}
public Playlist()
{
}
public Playlist() { }
public void AddTitle(CustomTitle morceau)
{
@ -154,30 +149,33 @@ public class Playlist : INotifyPropertyChanged
titles.Remove(morceau);
}
public void NextTitle()
public CustomTitle NextTitle()
{
if (titles.Count < 1) return null;
if (LoopTitle)
{
return;
return GetCurrentTitle();
}
if (!Shuffle)
{
Index++;
played.Add(Index);
return GetCurrentTitle();
}
else
{
Index = RandomGenerator(titles.Count);
played.Add(Index);
return GetCurrentTitle();
}
}
public void PreviousTitle()
public CustomTitle PreviousTitle()
{
if (LoopTitle)
{
return;
return GetCurrentTitle();
}
if(!Shuffle)
@ -186,21 +184,28 @@ public class Playlist : INotifyPropertyChanged
{
Index--;
played.RemoveAt(played.Count - 1);
return GetCurrentTitle();
}
else
{
return GetCurrentTitle();
}
}
else
{
if (!played.Any())
{
return;
return GetCurrentTitle();
}
Index = played[played.Count - 1];
played.RemoveAt(played.Count - 1);
return GetCurrentTitle();
}
}
public CustomTitle GetCurrentTitle()
{
if (Index < 0) Index = 0;
if (Index < titles.Count)
{
return titles[Index];
@ -235,8 +240,8 @@ public class Playlist : INotifyPropertyChanged
RandomNumberGenerator rng = RandomNumberGenerator.Create();
byte[] randomBytes = new byte[4];
rng.GetBytes(randomBytes);
int randomNumber = BitConverter.ToInt32(randomBytes, 0);
return randomNumber % n + 1;
uint randomNumber = BitConverter.ToUInt32(randomBytes, 0);
return (int)(randomNumber % n) + 1;
}
public bool HasCustomTitle(CustomTitle customTitle)

Loading…
Cancel
Save