Finish the Custom Files DataBinding development
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
210dd80a32
commit
3beaf2a7af
@ -1,29 +1,286 @@
|
||||
using Model;
|
||||
using Model.Serialization;
|
||||
using Model.Stub;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
|
||||
namespace Linaris;
|
||||
|
||||
public partial class LocalFilesPage : ContentPage
|
||||
namespace Linaris
|
||||
{
|
||||
public partial class LocalFilesPage : ContentPage
|
||||
{
|
||||
private ObservableCollection<CustomTitle> customTitles = App.Manager.GetCustomTitles();
|
||||
|
||||
private ObservableCollection<CustomTitle> customTitles = App.Manager.GetCustomTitles();
|
||||
public ObservableCollection<CustomTitle> CustomTitles
|
||||
{
|
||||
get => customTitles;
|
||||
}
|
||||
|
||||
public ObservableCollection<CustomTitle> CustomTitles
|
||||
{
|
||||
get => customTitles;
|
||||
}
|
||||
private ObservableCollection<Playlist> playlists = App.Manager.GetPlaylists();
|
||||
|
||||
public LocalFilesPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = this;
|
||||
}
|
||||
public ObservableCollection<Playlist> Playlists
|
||||
{
|
||||
get => playlists;
|
||||
}
|
||||
|
||||
void AddCustomTitle(object sender, EventArgs e)
|
||||
{
|
||||
App.Manager.AddCustomTitle(new CustomTitle());
|
||||
customTitles = App.Manager.GetCustomTitles();
|
||||
public LocalFilesPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = this;
|
||||
}
|
||||
|
||||
// Reset methods
|
||||
|
||||
void ResetAll(object sender, EventArgs e)
|
||||
{
|
||||
ResetSubMenus(sender, e);
|
||||
ResetRenaming(sender, e);
|
||||
}
|
||||
|
||||
void ResetSubMenus(object sender, EventArgs e)
|
||||
{
|
||||
foreach (var CustomTitle in customTitles)
|
||||
{
|
||||
CustomTitle.IsSubMenuVisible = false;
|
||||
}
|
||||
ResetPlaylistMenu(sender, e);
|
||||
}
|
||||
|
||||
void ResetRenaming(object sender, EventArgs e)
|
||||
{
|
||||
foreach (var CustomTitle in customTitles)
|
||||
{
|
||||
CustomTitle.IsRenaming = false;
|
||||
CustomTitle.Name = CustomTitle.NewName;
|
||||
}
|
||||
}
|
||||
|
||||
void ResetPlaylistMenu(object sender, EventArgs e)
|
||||
{
|
||||
foreach (CustomTitle customTitle in CustomTitles)
|
||||
{
|
||||
customTitle.IsPlaylistMenuVisible = false;
|
||||
customTitle.IsNewPlaylistMenuVisible = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add methods
|
||||
|
||||
void AddCustomTitle(CustomTitle customTitle)
|
||||
{
|
||||
App.Manager.AddCustomTitle(customTitle);
|
||||
customTitles.Add(customTitle);
|
||||
ResetAll(this, null);
|
||||
}
|
||||
|
||||
private async void AddTitles(object sender, EventArgs e)
|
||||
{
|
||||
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)
|
||||
{
|
||||
CustomTitle custom = new CustomTitle(result.FileName, "none.png", "", result.FullPath);
|
||||
if (!IsCustomTitleInCollection(custom))
|
||||
{
|
||||
AddCustomTitle(custom);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AddToPlaylist(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is Button button)
|
||||
{
|
||||
if (button.BindingContext is Playlist playlist)
|
||||
{
|
||||
if (button.Parent is StackLayout stack && stack.BindingContext is CustomTitle customTitle)
|
||||
{
|
||||
playlist.AddTitle(customTitle);
|
||||
ResetAll(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AddPlaylist(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is Entry entry)
|
||||
{
|
||||
Playlist playlist = new Playlist(entry.Text, "", "none.png");
|
||||
if (!IsInPlaylists(playlist))
|
||||
{
|
||||
App.Manager.AddPlaylist(playlist);
|
||||
playlists.Add(playlist);
|
||||
}
|
||||
if(entry.BindingContext is CustomTitle customTitle)
|
||||
{
|
||||
customTitle.IsNewPlaylistMenuVisible = false;
|
||||
entry.Text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Remove methods
|
||||
|
||||
void RemoveCustomTitle(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is Button button)
|
||||
{
|
||||
if (button.BindingContext is CustomTitle titleToRemove)
|
||||
{
|
||||
App.Manager.RemoveCustomTitle(titleToRemove);
|
||||
customTitles.Remove(titleToRemove);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Show methods
|
||||
|
||||
void ShowSubMenu(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is Image button)
|
||||
{
|
||||
if (button.BindingContext is CustomTitle customTitle)
|
||||
{
|
||||
if (!customTitle.IsSubMenuVisible)
|
||||
{
|
||||
ResetAll(sender, e);
|
||||
customTitle.IsSubMenuVisible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetSubMenus(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShowPlaylistMenu(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is Button button)
|
||||
{
|
||||
if (button.BindingContext is CustomTitle customTitle)
|
||||
{
|
||||
if (!customTitle.IsPlaylistMenuVisible)
|
||||
{
|
||||
customTitle.IsPlaylistMenuVisible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShowNewPlaylistMenu(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is Button button)
|
||||
{
|
||||
if (button.BindingContext is CustomTitle customTitle)
|
||||
{
|
||||
if (!customTitle.IsNewPlaylistMenuVisible)
|
||||
{
|
||||
customTitle.IsNewPlaylistMenuVisible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Change methods
|
||||
|
||||
void RenameCustomTitle(object sender, EventArgs e)
|
||||
{
|
||||
ResetSubMenus(sender, e);
|
||||
if (sender is Button button)
|
||||
{
|
||||
if (button.BindingContext is CustomTitle customTitle)
|
||||
{
|
||||
if (!customTitle.IsRenaming)
|
||||
{
|
||||
ResetRenaming(sender, e);
|
||||
customTitle.IsRenaming = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetRenaming(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (sender is Entry entry)
|
||||
{
|
||||
if (entry.BindingContext is CustomTitle customTitle)
|
||||
{
|
||||
ResetRenaming(sender, e);
|
||||
customTitle.Name = customTitle.NewName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 Button button)
|
||||
{
|
||||
if (button.BindingContext is CustomTitle customTitle)
|
||||
{
|
||||
customTitle.ImageURL = result.FullPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Search methods
|
||||
|
||||
bool IsCustomTitleInCollection(CustomTitle customTitle)
|
||||
{
|
||||
foreach(var custom in customTitles)
|
||||
{
|
||||
if (customTitle.Equals(custom))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsInPlaylists(Playlist playlist)
|
||||
{
|
||||
foreach (Playlist p in playlists)
|
||||
{
|
||||
if (p.Equals(playlist))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 128 KiB |
After Width: | Height: | Size: 28 KiB |
Loading…
Reference in new issue