From 1200aa95b3cf2e73e60d618f14f15246f5fca079 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE Date: Sat, 10 Jun 2023 20:27:44 +0200 Subject: [PATCH 1/5] Footer get and set data between different pages + fix local files scrollview bug --- Sources/Linaris/AlbumPage.xaml.cs | 54 +++++++++++ Sources/Linaris/App.xaml.cs | 49 +++++++++- Sources/Linaris/FooterPage.xaml | 6 +- Sources/Linaris/FooterPage.xaml.cs | 44 +++++---- Sources/Linaris/InfoTitlePage.xaml.cs | 54 +++++++++++ Sources/Linaris/Layout.xaml.cs | 29 ------ Sources/Linaris/Linaris.csproj | 1 - Sources/Linaris/LocalFilesPage.xaml | 2 +- Sources/Linaris/LocalFilesPage.xaml.cs | 95 ++++++++++++++++--- Sources/Linaris/MainPage.xaml.cs | 58 ++++++++++- .../Platforms/Android/AndroidManifest.xml | 9 +- Sources/Linaris/PlaylistPage.xaml | 2 +- Sources/Linaris/PlaylistPage.xaml.cs | 62 +++++++++++- Sources/Linaris/PlaylistsPage.xaml.cs | 54 +++++++++++ .../Serialization/LINQ_XML_Serialization.cs | 12 +-- Sources/Model/Title.cs | 3 +- 16 files changed, 447 insertions(+), 87 deletions(-) diff --git a/Sources/Linaris/AlbumPage.xaml.cs b/Sources/Linaris/AlbumPage.xaml.cs index 66b931f..92fe516 100644 --- a/Sources/Linaris/AlbumPage.xaml.cs +++ b/Sources/Linaris/AlbumPage.xaml.cs @@ -1,3 +1,4 @@ +using CommunityToolkit.Maui.Core.Primitives; using CommunityToolkit.Maui.Views; using Model; @@ -33,9 +34,16 @@ public partial class AlbumPage : ContentPage } } + protected override void OnAppearing() + { + base.OnAppearing(); + GetFooterData(); + } + protected override void OnDisappearing() { base.OnDisappearing(); + SetFooterData(); ContentView footer = this.FindByName("Footer"); var musicElement = footer?.FindByName("music"); if (musicElement != null) @@ -43,4 +51,50 @@ public partial class AlbumPage : ContentPage musicElement.Stop(); } } + + private void GetFooterData() + { + FooterPage FooterPage = (Application.Current as App).FooterPage; + Footer.CurrentPlaying = FooterPage.CurrentPlaying; + Footer.PlayImage = FooterPage.PlayImage; + Footer.LoopImage = FooterPage.LoopImage; + Footer.ShuffleImage = FooterPage.ShuffleImage; + Footer.Volume = FooterPage.Volume; + Footer.Position = FooterPage.Position; + Footer.Duration = FooterPage.Duration; + Footer.SliderPosition = FooterPage.SliderPosition; + + // Place l'index de lecture de la musique à la position du slider + var musicElement = Footer?.FindByName("music"); + musicElement.Dispatcher.StartTimer(TimeSpan.FromMilliseconds(100), () => + { + musicElement.SeekTo((Application.Current as App).MusicPosition); + return false; + }); + if ((Application.Current as App).MediaState == MediaElementState.Playing) + { + musicElement.Play(); + } + else + { + musicElement.Pause(); + } + } + + public void SetFooterData() + { + FooterPage FooterPage = (Application.Current as App).FooterPage; + FooterPage.CurrentPlaying = (Application.Current as App).Manager.CurrentPlaying; + FooterPage.PlayImage = Footer.PlayImage; + FooterPage.LoopImage = Footer.LoopImage; + FooterPage.ShuffleImage = Footer.ShuffleImage; + FooterPage.Volume = Footer.Volume; + FooterPage.Position = Footer.Position; + FooterPage.Duration = Footer.Duration; + FooterPage.SliderPosition = Footer.SliderPosition; + + var musicElement = Footer?.FindByName("music"); + (Application.Current as App).MusicPosition = musicElement.Position; + (Application.Current as App).MediaState = musicElement.CurrentState; + } } \ No newline at end of file diff --git a/Sources/Linaris/App.xaml.cs b/Sources/Linaris/App.xaml.cs index 53f1b71..26240a2 100644 --- a/Sources/Linaris/App.xaml.cs +++ b/Sources/Linaris/App.xaml.cs @@ -1,15 +1,60 @@ -using Model.Serialization; +using CommunityToolkit.Maui.Core.Primitives; +using Model.Serialization; using Model.Stub; namespace Linaris; public partial class App : Application { - public Manager Manager = new(new LinqXmlSerialization(FileSystem.Current.AppDataDirectory)); + private Manager manager = new(new LinqXmlSerialization(FileSystem.Current.AppDataDirectory)); + + public Manager Manager + { + get => manager; + set + { + manager = value; + } + } + + private FooterPage footerPage; + + public FooterPage FooterPage + { + get => footerPage; + set + { + footerPage = value; + } + } + + private TimeSpan musicPosition = TimeSpan.FromSeconds(0); + + public TimeSpan MusicPosition + { + get => musicPosition; + set + { + musicPosition = value; + } + } + + private MediaElementState mediaState = MediaElementState.Paused; + + public MediaElementState MediaState + { + get => mediaState; + set + { + mediaState = value; + } + } + public App() { InitializeComponent(); + footerPage = new FooterPage(); MainPage = new AppShell(); } diff --git a/Sources/Linaris/FooterPage.xaml b/Sources/Linaris/FooterPage.xaml index ec8f9a3..997f179 100644 --- a/Sources/Linaris/FooterPage.xaml +++ b/Sources/Linaris/FooterPage.xaml @@ -6,12 +6,12 @@ xmlns:model="clr-namespace:Model;assembly=Model" x:Class="Linaris.FooterPage"> - + - + -