First pass at songs view
Using data grid for songs view. Added FileSystemUtil for async folder traversal
This commit is contained in:
@ -1,6 +1,38 @@
|
||||
<?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.Songs.SongsView">
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:dg="clr-namespace:Xamarin.Forms.DataGrid;assembly=Xamarin.Forms.DataGrid"
|
||||
x:Class="Aurora.Frontend.Views.Songs.SongsView">
|
||||
<ContentPage.Content>
|
||||
<Label Text="Songs" />
|
||||
<dg:DataGrid ItemsSource="{Binding SongsList}" SelectionEnabled="True" SelectedItem="{Binding SelectedSong}"
|
||||
RowHeight="30" HeaderHeight="50" BorderColor="#CCCCCC" HeaderBackground="#E0E6F8">
|
||||
|
||||
<!-- Header -->
|
||||
<dg:DataGrid.HeaderFontSize>
|
||||
<OnIdiom x:TypeArguments="x:Double">
|
||||
<OnIdiom.Tablet>15</OnIdiom.Tablet>
|
||||
<OnIdiom.Phone>13</OnIdiom.Phone>
|
||||
<OnIdiom.Desktop>20</OnIdiom.Desktop>
|
||||
</OnIdiom>
|
||||
</dg:DataGrid.HeaderFontSize>
|
||||
|
||||
<!-- Columns -->
|
||||
<dg:DataGrid.Columns>
|
||||
<dg:DataGridColumn Title="Title" PropertyName="Title" Width="2*"/>
|
||||
<dg:DataGridColumn Title="Album" PropertyName="Album" Width="0.95*"/>
|
||||
<dg:DataGridColumn Title="Artist" PropertyName="Artist" Width="1*"/>
|
||||
<dg:DataGridColumn Title="Duration" PropertyName="Duration"/>
|
||||
</dg:DataGrid.Columns>
|
||||
|
||||
<!-- Row Colors -->
|
||||
<dg:DataGrid.RowsBackgroundColorPalette>
|
||||
<dg:PaletteCollection>
|
||||
<Color>#F2F2F2</Color>
|
||||
<Color>#FFFFFF</Color>
|
||||
</dg:PaletteCollection>
|
||||
</dg:DataGrid.RowsBackgroundColorPalette>
|
||||
|
||||
|
||||
</dg:DataGrid>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
|
@ -10,6 +10,7 @@ namespace Aurora.Frontend.Views.Songs
|
||||
public SongsView()
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = new SongsViewModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using Aurora.Frontend.Utils;
|
||||
|
||||
namespace Aurora.Frontend.Views.Songs
|
||||
{
|
||||
public class SongsViewModel
|
||||
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;
|
||||
|
||||
#endregion Fields
|
||||
|
||||
#region Constructor
|
||||
public SongsViewModel()
|
||||
{
|
||||
_songsList = new ObservableCollection<Song>();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Properties
|
||||
public ObservableCollection<Song> SongsList
|
||||
{
|
||||
get { return _songsList; }
|
||||
set
|
||||
{
|
||||
if (value != _songsList)
|
||||
{
|
||||
_songsList = value;
|
||||
OnPropertyChanged("SongList");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Song SelectedSong
|
||||
{
|
||||
get { return _selectedSong; }
|
||||
set
|
||||
{
|
||||
if (value != _selectedSong)
|
||||
{
|
||||
_selectedSong = value;
|
||||
OnPropertyChanged("SelectedSong");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user