From 91c2a51d9f46f099b14ffe3fba6051f2388c9817 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE Date: Mon, 5 Jun 2023 17:24:37 +0200 Subject: [PATCH] Finish the footer --- Sources/Linaris/App.xaml.cs | 2 +- Sources/Linaris/FooterPage.xaml | 36 +++-- Sources/Linaris/FooterPage.xaml.cs | 142 ++++++++++++++++++- Sources/Linaris/Linaris.csproj | 3 +- Sources/Linaris/LocalFilesPage.xaml.cs | 5 + Sources/Linaris/PlaylistPage.xaml.cs | 4 + Sources/Linaris/Resources/Styles/Styles.xaml | 94 ++++++++++++ Sources/Model/Model.csproj | 1 - Sources/Model/Stub/StubArtist.cs | 2 +- 9 files changed, 271 insertions(+), 18 deletions(-) diff --git a/Sources/Linaris/App.xaml.cs b/Sources/Linaris/App.xaml.cs index e506791..53f1b71 100644 --- a/Sources/Linaris/App.xaml.cs +++ b/Sources/Linaris/App.xaml.cs @@ -5,7 +5,7 @@ namespace Linaris; public partial class App : Application { - public Manager Manager = new(new LinqXmlSerialization(Path.Combine(FileSystem.Current.AppDataDirectory, "Data"))); + public Manager Manager = new(new LinqXmlSerialization(FileSystem.Current.AppDataDirectory)); public App() { diff --git a/Sources/Linaris/FooterPage.xaml b/Sources/Linaris/FooterPage.xaml index 38bd297..14ba795 100644 --- a/Sources/Linaris/FooterPage.xaml +++ b/Sources/Linaris/FooterPage.xaml @@ -1,20 +1,40 @@ - + - + - - - - - - + + + \ No newline at end of file diff --git a/Sources/Linaris/FooterPage.xaml.cs b/Sources/Linaris/FooterPage.xaml.cs index dd59eca..55d0534 100644 --- a/Sources/Linaris/FooterPage.xaml.cs +++ b/Sources/Linaris/FooterPage.xaml.cs @@ -1,21 +1,133 @@ +using CommunityToolkit.Maui.Core.Primitives; using Model; using Model.Stub; using System.ComponentModel; -using System.Runtime.CompilerServices; namespace Linaris; public partial class FooterPage : ContentView, INotifyPropertyChanged { + private CustomTitle currentPlaying; - private readonly Manager Manager = (Application.Current as App).Manager; + public CustomTitle CurrentPlaying + { + get => currentPlaying; + set + { + currentPlaying = value; + OnPropertyChanged(nameof(CurrentPlaying)); + } + } + + private string playImage = "play.png"; + + public string PlayImage + { + get => playImage; + set + { + playImage = value; + OnPropertyChanged(nameof(PlayImage)); + } + } + + private double volume = 1; + + public double Volume + { + get => volume; + set + { + volume = value; + OnPropertyChanged(nameof(Volume)); + } + } + + private string position = "00:00:00"; + + public string Position + { + get => position; + set + { + position = value; + OnPropertyChanged(nameof(Position)); + } + } + + private string duration = "00:00:00"; + + public string Duration + { + get => duration; + set + { + duration = value; + OnPropertyChanged(nameof(Duration)); + } + } + + private double sliderPosition = 0; + + public double SliderPosition + { + get => sliderPosition; + set + { + sliderPosition = value; + OnPropertyChanged(nameof(SliderPosition)); + } + } + + private readonly Manager manager = (Application.Current as App).Manager; + + public Manager Manager + { + get => manager; + } public FooterPage() { InitializeComponent(); - BindingContext = Manager.CurrentPlaying; + music.StateChanged += Music_StateChanged; + TimeSlider.ValueChanged += TimeSlider_ValueChanged; + VolumeSlider.ValueChanged += VolumeSlider_ValueChanged; + music.PositionChanged += Music_PositionChanged; + CurrentPlaying = Manager.CurrentPlaying; + BindingContext = this; } + private void Music_PositionChanged(object sender, EventArgs e) + { + SliderPosition = music.Position.TotalSeconds / music.Duration.TotalSeconds; + Position = music.Position.ToString(@"hh\:mm\:ss"); + } + + private void VolumeSlider_ValueChanged(object sender, ValueChangedEventArgs e) + { + Volume = VolumeSlider.Value; + music.Volume = Volume; + } + + private void TimeSlider_ValueChanged(object sender, ValueChangedEventArgs e) + { + TimeSpan PositionTimeSpan = TimeSpan.FromSeconds(TimeSlider.Value * music.Duration.TotalSeconds); + music.SeekTo(PositionTimeSpan); + Position = music.Position.ToString(@"hh\:mm\:ss"); + } + + private void Music_StateChanged(object sender, MediaStateChangedEventArgs e) + { + if (music.CurrentState == MediaElementState.Paused || music.CurrentState == MediaElementState.Stopped) + { + PlayImage = "play.png"; + } + else + { + PlayImage = "pause.png"; + Duration = music.Duration.ToString(@"hh\:mm\:ss"); + } + } public void RewindButton_Clicked(object sender, EventArgs e) { @@ -23,7 +135,9 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged Manager.PreviousTitle(); Dispatcher.DispatchAsync(() => { - music.Source = Manager.CurrentPlaying.Path; + CurrentPlaying = Manager.CurrentPlaying; + music.Source = CurrentPlaying.Path; + Duration = music.Duration.ToString(@"hh\:mm\:ss"); }); } @@ -33,7 +147,9 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged Manager.NextTitle(); Dispatcher.DispatchAsync(() => { - music.Source = Manager.CurrentPlaying.Path; + CurrentPlaying = Manager.CurrentPlaying; + music.Source = CurrentPlaying.Path; + Duration = music.Duration.ToString(@"hh\:mm\:ss"); }); } @@ -53,7 +169,21 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged Manager.NextTitle(); Dispatcher.DispatchAsync(() => { - music.Source = Manager.CurrentPlaying.Path; + CurrentPlaying = Manager.CurrentPlaying; + music.Source = CurrentPlaying.Path; + Duration = music.Duration.ToString(@"hh\:mm\:ss"); }); } + + public void PlayButton_Clicked(object sender, EventArgs e) + { + if (music.CurrentState == MediaElementState.Paused || music.CurrentState == MediaElementState.Stopped) + { + music.Play(); + } + else + { + music.Pause(); + } + } } \ No newline at end of file diff --git a/Sources/Linaris/Linaris.csproj b/Sources/Linaris/Linaris.csproj index f954d66..8adecf0 100644 --- a/Sources/Linaris/Linaris.csproj +++ b/Sources/Linaris/Linaris.csproj @@ -1,5 +1,4 @@  - net7.0-android $(TargetFrameworks);net7.0-windows10.0.19041.0 @@ -123,4 +122,6 @@ + + diff --git a/Sources/Linaris/LocalFilesPage.xaml.cs b/Sources/Linaris/LocalFilesPage.xaml.cs index 291494a..4d7b894 100644 --- a/Sources/Linaris/LocalFilesPage.xaml.cs +++ b/Sources/Linaris/LocalFilesPage.xaml.cs @@ -1,4 +1,5 @@ using CommunityToolkit.Maui.Views; +using Microsoft.Maui.Controls; using Model; using System.Collections.ObjectModel; using System.Diagnostics; @@ -276,6 +277,10 @@ public partial class LocalFilesPage : ContentPage { musicElement.Source = customTitle.Path; } + if (footer is FooterPage footerPage) + { + footerPage.CurrentPlaying = customTitle; + } } } } \ No newline at end of file diff --git a/Sources/Linaris/PlaylistPage.xaml.cs b/Sources/Linaris/PlaylistPage.xaml.cs index 26fc7cc..9f6dd22 100644 --- a/Sources/Linaris/PlaylistPage.xaml.cs +++ b/Sources/Linaris/PlaylistPage.xaml.cs @@ -46,6 +46,10 @@ public partial class PlaylistPage : ContentPage if (Manager.CurrentPlaying == null) return; musicElement.Source = Manager.CurrentPlaying.Path; } + if (footer is FooterPage footerPage) + { + footerPage.CurrentPlaying = Manager.CurrentPlaying; + } } } } diff --git a/Sources/Linaris/Resources/Styles/Styles.xaml b/Sources/Linaris/Resources/Styles/Styles.xaml index 57d8d92..4b93b3c 100644 --- a/Sources/Linaris/Resources/Styles/Styles.xaml +++ b/Sources/Linaris/Resources/Styles/Styles.xaml @@ -361,6 +361,100 @@ + + + + + +