Skip to content

Commit

Permalink
added auto library loading on first start.
Browse files Browse the repository at this point in the history
  • Loading branch information
theweavrs committed Dec 2, 2016
1 parent dfea8ac commit 0c75d40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions BreadPlayer.Core/ViewModels/LibraryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ You should have received a copy of the GNU General Public License
using BreadPlayer.Common;
using BreadPlayer.Messengers;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage.Search;

namespace BreadPlayer.ViewModels
{
Expand Down Expand Up @@ -424,7 +425,7 @@ async void Init(object para)
#endregion

#region Methods

async Task RefreshSourceAsync()
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
Expand All @@ -449,7 +450,7 @@ void ChangeView(string header, bool group, object src)
grouped = group;
source = src;
libgrouped = ViewSource.IsSourceGrouped;
if((src as ThreadSafeObservableCollection<Mediafile>)?.Any() == true && Player.CurrentlyPlayingFile != null)
if((src as ThreadSafeObservableCollection<Mediafile>)?.Any() == true && Player.CurrentlyPlayingFile != null && (src as ThreadSafeObservableCollection<Mediafile>).FirstOrDefault(t => t.Path == Player.CurrentlyPlayingFile?.Path) != null)
(src as ThreadSafeObservableCollection<Mediafile>).FirstOrDefault(t => t.Path == Player.CurrentlyPlayingFile?.Path).State = PlayerState.Playing;
}
async Task LoadCollectionAsync(Func<Mediafile, string> sortFunc, bool group)
Expand Down
13 changes: 12 additions & 1 deletion BreadPlayer.Core/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ public SettingsViewModel()
}
public static GroupedObservableCollection<string, Mediafile> TracksCollection
{ get; set; }
private void HandleMessage(Message message)
private async void HandleMessage(Message message)
{
if(message.Payload is List<object>)
{
TracksCollection = (message.Payload as List<object>)[0] as GroupedObservableCollection<string, Mediafile>;
if (TracksCollection.Count <= 0)
await AutoLoadMusicLibrary().ConfigureAwait(false);
if (TracksCollection != null)
{
message.HandledStatus = MessageHandledStatus.HandledContinue;
Expand Down Expand Up @@ -190,6 +192,15 @@ public ThreadSafeObservableCollection<StorageFolder> LibraryFoldersCollection
return _LibraryFoldersCollection; }
set { Set(ref _LibraryFoldersCollection, value); }
}
async Task AutoLoadMusicLibrary()
{
var options = Common.DirectoryWalker.GetQueryOptions();
//this is the query result which we recieve after querying in the folder
StorageFileQueryResult queryResult = KnownFolders.MusicLibrary.CreateFileQueryWithOptions(options);
//the event for files changed
queryResult.ContentsChanged += QueryResult_ContentsChanged;
await AddFolderToLibraryAsync(queryResult);
}
/// <summary>
/// Loads songs from a specified folder into the library. <seealso cref="LoadCommand"/>
/// </summary>
Expand Down

0 comments on commit 0c75d40

Please sign in to comment.