Ejemplo n.º 1
0
        internal AlbumViewDialog(AlbumViewModel album)
        {
            InitializeComponent();
            RequestedTheme = Settings.Current.Theme;
            if (album == null)
            {
                Title = Consts.Localizer.GetString("OopsText");
                IsPrimaryButtonEnabled  = false;
                Album.Text              = Consts.Localizer.GetString("SearchFailedText");
                Artist.Visibility       = Visibility.Collapsed;
                Brief.Visibility        = Visibility.Collapsed;
                Descriptions.Visibility = Visibility.Collapsed;
            }
            this.album = album;
            if (!album.IsOnline)
            {
                SecondaryButtonText = string.Empty;
            }
            var  songs = AsyncHelper.RunSync(async() => { return(await album.GetSongsAsync()); });
            uint i     = 0;

            foreach (var item in songs)
            {
                SongList.Add(new SongViewModel(item)
                {
                    Index = i++,
                });
            }
            Task.Run(async() =>
            {
                var favors = await SQLOperator.Current().GetFavoriteAsync();
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                {
                    foreach (var song in SongList)
                    {
                        if (favors.Contains(song.ID))
                        {
                            if (favors.Count == 0)
                            {
                                return;
                            }
                            song.Favorite = true;
                            favors.Remove(song.ID);
                        }
                    }
                });
            });
            Album.Text     = album.Name;
            Artwork.Source = new BitmapImage(album.ArtworkUri ?? new Uri(Consts.NowPlaceholder));
            Artist.Text    = album.GetFormattedArtists();
            Brief.Text     = album.GetBrief();
            if (album.Description.IsNullorEmpty())
            {
                var t = ThreadPool.RunAsync(async x =>
                {
                    var info = await MainPageViewModel.Current.GetAlbumInfoAsync(album.Name, album.AlbumArtists.FirstOrDefault());
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                    {
                        if (info != null)
                        {
                            if (album.ArtworkUri == null && info.AltArtwork != null)
                            {
                                Artwork.Source = new BitmapImage(info.AltArtwork);
                                UpdateArtwork?.Invoke(this, info.AltArtwork);
                                var task = ThreadPool.RunAsync(async k =>
                                {
                                    if (!album.IsOnline)
                                    {
                                        await SQLOperator.Current().UpdateAlbumArtworkAsync(album.ID, info.AltArtwork.OriginalString);
                                    }
                                });
                            }
                            Descriptions.Text = info.Description;
                        }
                        else
                        {
                            Descriptions.Text = $"# {Consts.Localizer.GetString("LocaAlbumTitle")}";
                        }
                    });
                });
            }
            else
            {
                Descriptions.Text = album.Description;
            }
        }