Skip to content

Commit 2cecf69

Browse files
author
theweavrs
committed
fix playlist import and notification queue system
1 parent d1eb465 commit 2cecf69

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

BreadPlayer.Views.UWP/Common/NotificationManager.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BreadPlayer.Core.Common;
22
using BreadPlayer.Core.Models;
3+
using BreadPlayer.Services;
34
using System;
45
using System.Collections;
56
using System.Collections.Generic;
@@ -15,7 +16,7 @@ namespace BreadPlayer.NotificationManager
1516
{
1617
public class BreadNotificationManager : ObservableObject, INotificationManager
1718
{
18-
private Queue<string> NotificationQueue => new Queue<string>();
19+
private Queue<string> NotificationQueue => GSingleton<Queue<string>>.Instance.Singleton;
1920
private ICommand _closeCommand;
2021
private DispatcherTimer _hideTimer;
2122
private string _status = string.Empty;
@@ -104,14 +105,14 @@ public void SendUpcomingSongNotification(Mediafile mediaFile)
104105
}
105106
}
106107

107-
private void HideTimer_Tick(object sender, object e)
108+
private async void HideTimer_Tick(object sender, object e)
108109
{
109110
Status = string.Empty;
110111
Show = false;
111112
_hideTimer?.Stop();
112113
if (NotificationQueue.Count > 0)
113114
{
114-
ShowMessageAsync(NotificationQueue.Dequeue()).Wait();
115+
await ShowMessageAsync(NotificationQueue.Dequeue()).ConfigureAwait(false);
115116
}
116117
}
117118
}

BreadPlayer.Views.UWP/Helpers/PlaylistHelper.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Windows.Storage.Search;
1414
using BreadPlayer.Common;
1515
using BreadPlayer.ViewModels;
16+
using BreadPlayer.Core;
1617

1718
namespace BreadPlayer.Helpers
1819
{
@@ -52,19 +53,30 @@ await BreadDispatcher.InvokeAsync(async () =>
5253
{
5354
var folderPaths = songPaths.GroupBy(t => Path.GetDirectoryName(t));
5455
Dictionary<string, (List<string> songs, StorageFolder folder)> folders = new Dictionary<string, (List<string> songs, StorageFolder folder)>();
56+
5557
foreach (var folderPath in folderPaths)
5658
{
57-
var folder = await StorageFolder.GetFolderFromPathAsync(folderPath.Key);
58-
var token = StorageApplicationPermissions.FutureAccessList.Add(folder);
59-
folders.Add(token, (folderPath.ToList(), folder));
59+
try
60+
{
61+
var folder = await StorageFolder.GetFolderFromPathAsync(folderPath.Key);
62+
var token = StorageApplicationPermissions.FutureAccessList.Add(folder);
63+
folders.Add(token, (folderPath.ToList(), folder));
64+
}
65+
catch (UnauthorizedAccessException)
66+
{
67+
await SharedLogic.Instance.NotificationManager.ShowMessageAsync(string.Format("We cannot import songs due to access problems. Please import {0} to Bread Player library.", folderPath.Key), 5);
68+
}
6069
}
70+
6171
return folders;
6272
}
6373
public static async Task<IEnumerable<Mediafile>> GetSongsInAllFoldersAsync(List<string> songPaths)
6474
{
6575
List<Mediafile> songsList = new List<Mediafile>();
6676
foreach (var folder in await GetFoldersFromSongsAsync(songPaths).ConfigureAwait(false))
6777
{
78+
if (folder.Key == null)
79+
break;
6880
songsList.AddRange(await GetSongsInFolderAsync(folder.Value.songs, folder.Value.folder).ConfigureAwait(false));
6981
StorageApplicationPermissions.FutureAccessList.Remove(folder.Key);
7082
}

BreadPlayer.Views.UWP/SettingsViews/ViewModels/AccountsViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private async void LastfmLogout(object para)
4646
}
4747
private async void LastfmLogin(object para)
4848
{
49-
if (!LastfmPassword.Any() || !LastfmUsername.Any())
49+
if (string.IsNullOrEmpty(LastfmPassword) || string.IsNullOrEmpty(LastfmUsername))
5050
{
5151
if ((bool)para)
5252
{
@@ -148,8 +148,8 @@ public AccountsViewModel()
148148
_lyricSource = SettingsHelper.GetRoamingSetting<string>("LyricSource", "Auto");
149149
_lyricType = SettingsHelper.GetRoamingSetting<string>("LyricType", "Synced");
150150
_noOfArtistsToFetchInfoFor = SettingsHelper.GetRoamingSetting<string>("NoOfArtistsToFetchInfoFor", "Lead artist");
151-
_lastfmPassword = SettingsHelper.GetRoamingSetting<string>("LastfmPassword", "");
152-
_lastfmUsername = SettingsHelper.GetRoamingSetting<string>("LastfmUsername", "");
151+
_lastfmPassword = SettingsHelper.GetRoamingSetting<string>("LastfmPassword", null);
152+
_lastfmUsername = SettingsHelper.GetRoamingSetting<string>("LastfmUsername", null);
153153
LastfmLogin(false);
154154
}
155155
}

0 commit comments

Comments
 (0)