Esempio n. 1
0
        public NewsFeedViewModel(List<NewsFeedItem> newsItems, UserCache userCache)
        {
            NewsItems = newsItems;
            _cache = userCache;

            if (NewsItems.Any())
                _cache.LogViewedNewsItem(NewsItems[_index].Album.ID);
        }
Esempio n. 2
0
        public static UserCache Load(string userName)
        {
            UserCache newCache = new UserCache(userName);

            if (File.Exists(newCache._cacheLocation))
            {
                using (StreamReader reader = new StreamReader(newCache._cacheLocation))
                {
                    newCache._cacheData = JsonConvert.DeserializeObject<UserCacheData>(reader.ReadToEnd());
                }
            }

            if (newCache._cacheData == null)
            {
                newCache._cacheData = new UserCacheData();
            }

            return newCache;
        }
Esempio n. 3
0
        /// <summary>
        /// Spawn a background task to find any new albums or tracks
        /// based on what the user is following.  A news feed item will
        /// popup if an item is found.
        /// </summary>
        /// <param name="userCache"></param>
        private void GetNewsFeed(UserCache userCache)
        {
            /*System.Threading.Tasks.Task.Run(() =>
            {
                AlbumType filter = AlbumType.Album | AlbumType.Single;
                DateTime cutoff = DateTime.Now.AddMonths(-3); //TODO: Data-drive this setting.
                int maxSuggestions = 1;  //TODO: Data-drive this setting.

                FollowedArtistList followedArtists = SpotifyCacheService.GetFollowedArtists();
                List<NewsFeedItem> newsItems = new List<NewsFeedItem>();
    
                foreach (Artist followedArtist in followedArtists.ArtistItems.Items)
                {
                    //Find if there's any new content available from this artist.
                    AlbumInfoList albums = SpotifyClientService.Client.GetArtistAlbums(followedArtist, filter);

                    foreach (AlbumInfo album in albums.Items)
                    {
                        if (userCache.SeenNewsItem(album.ID)) continue;

                        Album albumInfo = SpotifyClientService.Client.GetAlbum(album);

                        if (albumInfo.ReleaseDate > cutoff)
                        {
                            newsItems.Add(new NewsFeedItem(followedArtist, albumInfo));
                            if (newsItems.Count >= maxSuggestions)
                                break;
                        }
                        else
                        {
                            //Assume that albums are returned by Spotify by release date, descending.
                            //If we miss the cutoff, skip out.
                            break;
                        }
                    }

                    if (newsItems.Count >= maxSuggestions)
                        break;
                }

                if (newsItems.Any())
                {
                    Dispatcher.Invoke(() =>
                    {
                        //Display a popup.
                        this.NewsFeedPopup.DataContext = new NewsFeedViewModel(newsItems, userCache);
                        this.NewsFeedPopup.Width = this.RenderSize.Width * 0.8;
                        this.NewsFeedPopup.Height = this.RenderSize.Height * 0.8;
                        this.NewsFeedPopup.IsOpen = true;
                    });
                }
            });*/
        }
Esempio n. 4
0
        /// <summary>
        /// Displays the login window and will initialize the application with
        /// login credentials.
        /// </summary>
        private void Login() {
            if (ShowLoginWindow() == false)
                return;
            
            this.PlaylistView.Initialize();
            this.NavigationControl.Initialize();
            PlaylistService.Initialize(this.PlaylistView.ViewModel);

            _userCache = UserCache.Load(SpotifyClientService.User.Id);

            GetNewsFeed(_userCache);

            //TODO:  Support other music services.  This should be broken out into a separate UI action.
            LoginViewModel loginViewModel = (LoginViewModel)this.LoginControl.DataContext;
            loginViewModel.AccountName = SpotifyClientService.User.DisplayName;
            loginViewModel.MusicService = MusicService.Spotify;

            MainWindowViewModel mainWindowViewModel = (MainWindowViewModel)this.DataContext;
            mainWindowViewModel.IsLoggedIn = true;
        }
Esempio n. 5
0
 public NewsFeedViewModel()
 {
     NewsItems = new List<NewsFeedItem>();
     _cache = null;
 }