Restructuring. Added services.

This commit is contained in:
watsonb8
2019-05-19 20:21:54 -04:00
parent 1fcaffb9b1
commit 4b7c146041
15 changed files with 175 additions and 28 deletions

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Aurora.Frontend.Components.MusicPlayer.Player">
<ContentView.Content>
</ContentView.Content>
</ContentView>

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace Aurora.Frontend.Components.MusicPlayer
{
public partial class Player : ContentView
{
public Player()
{
InitializeComponent();
}
}
}

0
Aurora/Frontend/Converters/InverseBoolConverter.cs Executable file → Normal file
View File

0
Aurora/Frontend/Converters/ToUpperConverter.cs Executable file → Normal file
View File

View File

@ -1,41 +0,0 @@
using System;
namespace Aurora.Frontend.Views.Songs
{
public class Song
{
public Song()
{
}
/// <summary>
/// The title of the song.
/// </summary>
/// <value></value>
public string Title { get; set; }
/// <summary>
/// The artist of the song.
/// </summary>
/// <value></value>
public string Artist { get; set; }
/// <summary>
/// The album from which the song belongs.
/// </summary>
/// <value></value>
public string Album { get; set; }
/// <summary>
/// The duration of the song.
/// </summary>
/// <value></value>
public string Duration { get; set; }
/// <summary>
/// Extra data associated with a song.
/// </summary>
/// <value></value>
public object Metadata { get; set; }
}
}

View File

@ -1,82 +0,0 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Aurora.Frontend.Utils
{
public class FileSystemUtils
{
public FileSystemUtils()
{
}
/// <summary>
/// Asynchronousely recursively traverse a directory path.
/// </summary>
/// <param name="path">The path to the directory to traverse</param>
/// <param name="extensions">Comma separated list of file extensions to accept</param>
public static List<FileInfo> TraverseFoldersAsync(string path, string extensions)
{
string[] extensionList = extensions.Split(',');
ConcurrentBag<Task> tasks = new ConcurrentBag<Task>();
List<FileInfo> outFiles = new List<FileInfo>();
DirectoryInfo directoryInfo = new DirectoryInfo(path);
tasks.Add(Task.Run(() => Traverse(directoryInfo, tasks, outFiles, extensionList)));
Task waitingTask;
while (tasks.TryTake(out waitingTask))
{
waitingTask.Wait();
}
return outFiles;
}
/// <summary>
/// Recursive method to capture children of a directory.
/// </summary>
/// <param name="dir">The directory to traverse</param>
/// <param name="tasks">The list of currently running tasks</param>
private static void Traverse(DirectoryInfo dir, ConcurrentBag<Task> tasks, List<FileInfo> outFiles, string[] extensions)
{
try
{
DirectoryInfo[] directoryInfos = dir.GetDirectories();
//Enque children
foreach (DirectoryInfo childInfo in directoryInfos)
{
tasks.Add(Task.Run(() => Traverse(childInfo, tasks, outFiles, extensions)));
}
//Collect files
foreach (FileInfo fileInfo in dir.GetFiles())
{
if (extensions.Any(e => e == fileInfo.Extension))
{
//Don't know if this lock is necessary
lock (outFiles)
{
outFiles.Add(fileInfo);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine($"{ex.GetType()} {ex.Message}\n{ex.StackTrace}");
ex = ex.InnerException;
}
}
}
}

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Aurora.Frontend.Views.Artists.ArtistsView">
<ContentPage.Content>
</ContentPage.Content>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<MasterDetailPage
xmlns="http://xamarin.com/schemas/2014/forms"
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:Aurora.Frontend.Views.Songs"
xmlns:navigation="clr-namespace:Aurora.Frontend.Components.NavigationMenu"

View File

@ -1,16 +1,12 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using Aurora.Frontend.Utils;
using System.Collections.ObjectModel;
using Aurora.Backend.Models;
using Aurora.Backend.Services;
namespace Aurora.Frontend.Views.Songs
{
public class SongsViewModel : BaseViewModel
{
#region Fields
private string _pathName = "/Users/brandonwatson/Music/iTunes/iTunes Media/Music";
private string _extensions = ".wav,.mp3,.aiff,.flac,.m4a,.m4b,.wma";
private ObservableCollection<Song> _songsList;
private Song _selectedSong;
@ -57,18 +53,8 @@ namespace Aurora.Frontend.Views.Songs
#region Methods
public void Initialize()
{
List<FileInfo> musicFiles = FileSystemUtils.TraverseFoldersAsync(_pathName, _extensions);
foreach (FileInfo file in musicFiles)
{
TagLib.File tagFile = TagLib.File.Create(file.FullName);
_songsList.Add(new Song()
{
Title = tagFile.Tag.Title,
Album = tagFile.Tag.Album,
Artist = tagFile.Tag.FirstAlbumArtist
});
}
SongsList = LibraryService.Instance.GetLibrary();
}
#endregion Methods