Ejemplo n.º 1
0
        public static async void SetThemeColor(string albumartPath)
        {
            try
            {
                await SharedLogic.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                {
                    if (App.Current.RequestedTheme == ApplicationTheme.Light && SharedLogic.SettingsVM.ChangeAccentByAlbumArt)
                    {
                        Color color;
                        if (!string.IsNullOrEmpty(albumartPath))
                        {
                            color = await SharedLogic.GetDominantColor(await StorageFile.GetFileFromPathAsync(albumartPath));
                        }
                        else
                        {
                            color = GetAccentColor();
                        }

                        var oldColor = GetThemeResource <SolidColorBrush>("SystemControlBackgroundAccentBrush").Color;
                        ChangeTitleBarColor(color);
                        GetThemeResource <SolidColorBrush>("SystemControlBackgroundAccentBrush").AnimateBrush(oldColor, color, "(SolidColorBrush.Color)");
                        foreach (var brushKey in brushKeys)
                        {
                            if (Application.Current.Resources.ContainsKey(brushKey))
                            {
                                ((SolidColorBrush)App.Current.Resources[brushKey]).Color = color;
                            }
                        }
                        //ThemeChanged.Invoke(null, new Events.ThemeChangedEventArgs(oldColor, color));
                    }
                });
            }
            catch { }
        }
Ejemplo n.º 2
0
        public static async Task <(string artistArtPath, Color dominantColor)> CacheArtistArt(string url, Artist artist)
        {
            var artistArtPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, @"ArtistArts\" + (artist.Name).ToLower().ToSha1() + ".jpg");

            if (!File.Exists(artistArtPath))
            {
                var artistArt = await ApplicationData.Current.LocalFolder.CreateFileAsync(@"ArtistArts\" + (artist.Name).ToLower().ToSha1() + ".jpg", CreationCollisionOption.FailIfExists);

                HttpClient client = new HttpClient();                                          // Create HttpClient
                byte[]     buffer = await client.GetByteArrayAsync(url).ConfigureAwait(false); // Download file

                using (FileStream stream = new FileStream(artistArt.Path, FileMode.Open, FileAccess.Write, FileShare.None, 51200, FileOptions.WriteThrough))
                {
                    await stream.WriteAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
                }
                var color = await SharedLogic.GetDominantColor(artistArt).ConfigureAwait(false);

                return(artistArt.Path, color);
            }
            else
            {
                var color = await SharedLogic.GetDominantColor(await StorageFile.GetFileFromPathAsync(artistArtPath)).ConfigureAwait(false);

                return(artistArtPath, color);
            }
        }
Ejemplo n.º 3
0
        public static async void SetThemeColor(string albumartPath)
        {
            await BreadDispatcher.InvokeAsync(async() =>
            {
                if (SharedLogic.SettingsVm.ChangeAccentByAlbumArt == false)
                {
                    ChangeColor(GetAccentColor());
                    return;
                }
                if (RoamingSettingsHelper.GetSetting <string>("SelectedTheme", "Light") == "Light" && SharedLogic.SettingsVm.ChangeAccentByAlbumArt)
                {
                    try
                    {
                        Color color;
                        if (!string.IsNullOrEmpty(albumartPath) && albumartPath != "default")
                        {
                            color = await SharedLogic.GetDominantColor(await StorageFile.GetFileFromPathAsync(albumartPath));
                        }
                        else if (albumartPath == "default" && SharedLogic.Player.CurrentlyPlayingFile != null)
                        {
                            color = await SharedLogic.GetDominantColor(await StorageFile.GetFileFromPathAsync(SharedLogic.Player.CurrentlyPlayingFile.AttachedPicture));
                        }
                        else
                        {
                            color = GetAccentColor();
                        }

                        ChangeColor(color);
                    }
                    catch (Exception ex)
                    {
                        BLogger.Logger.Error("Failed to update accent.", ex);
                        await SharedLogic.NotificationManager.ShowMessageAsync(ex.Message);
                    }
                    //ThemeChanged?.Invoke(null, new Events.ThemeChangedEventArgs(oldColor, color));
                }
                else
                {
                    ChangeColor(GetAccentColor());
                }
            });
        }
Ejemplo n.º 4
0
 public static async void SetThemeColor(string albumartPath)
 {
     await SharedLogic.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
     {
         if (SharedLogic.SettingsVM.ChangeAccentByAlbumArt == false)
         {
             ChangeColor(GetAccentColor());
             return;
         }
         if (App.Current.RequestedTheme == ApplicationTheme.Light && SharedLogic.SettingsVM.ChangeAccentByAlbumArt)
         {
             try
             {
                 Color color;
                 if (!string.IsNullOrEmpty(albumartPath) && albumartPath != "default")
                 {
                     color = await SharedLogic.GetDominantColor(await StorageFile.GetFileFromPathAsync(albumartPath));
                 }
                 else if (albumartPath == "default" && SharedLogic.Player.CurrentlyPlayingFile != null)
                 {
                     color = await SharedLogic.GetDominantColor(await StorageFile.GetFileFromPathAsync(SharedLogic.Player.CurrentlyPlayingFile.AttachedPicture));
                 }
                 else
                 {
                     color = GetAccentColor();
                 }
                 ChangeColor(color);
             }
             catch (Exception ex)
             {
                 BLogger.Logger.Error("Failed to update accent.", ex);
                 await Core.SharedLogic.NotificationManager.ShowMessageAsync(ex.Message);
             }
             //ThemeChanged.Invoke(null, new Events.ThemeChangedEventArgs(oldColor, color));
         }
     });
 }