Enhance footer
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
2e307e5974
commit
bd205913fc
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue