private void HandleMixCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == NotifyCollectionChangedAction.Remove ||
         e.Action == NotifyCollectionChangedAction.Replace)
     {
         foreach (MixModel model in e.OldItems)
         {
             MixCollection.Remove(MixLookupMap[model.MixId]);
             MixLookupMap.Remove(model.MixId);
         }
     }
     if (e.Action == NotifyCollectionChangedAction.Add ||
         e.Action == NotifyCollectionChangedAction.Replace)
     {
         foreach (MixModel model in e.NewItems)
         {
             LookupMix(model);
         }
     }
     if (e.Action == NotifyCollectionChangedAction.Reset)
     {
         MixCollection.Clear();
         MixLookupMap.Clear();
     }
 }
 private void PopulateCollection(MixCollection coll, Mix[] mixes)
 {
     foreach (var item in mixes)
     {
         coll.Add(item);
     }
 }
        public MixViewModel LookupMix(MixModel mix)
        {
            if (MixLookupMap.ContainsKey(mix.MixId))
            {
                return(MixLookupMap[mix.MixId]);
            }
            else
            {
                MixViewModel newViewModel = new MixViewModel(mix);

                MixLookupMap.Add(newViewModel.MixId, newViewModel);
                MixCollection.Add(newViewModel);
                return(newViewModel);
            }
        }
        private async void FetchHomePageMixSets(FrameworkElement sender, object args)
        {
            SearchResult trendingMixesSearch = await MixSearch.FetchTrendingMixes();
            trendingMixes = new MixCollection(trendingMixesSearch);
            trendingMixesLst.MixSource = trendingMixes;

            if (GlobalConfigs.CurrentUser != null)
            {
                Task<SearchResult> fetchRecommendedMixesTask = MixSearch.FetchMixesforUser(MixSearch.ListType.RECOMMENDED, GlobalConfigs.CurrentUser.UserId);
                Task<SearchResult> fetchListenLaterMixesTask = MixSearch.FetchMixesforUser(MixSearch.ListType.LISTEN_LATER, GlobalConfigs.CurrentUser.UserId);
                Task<SearchResult> fetchRecentlyPlayedMixesTask = MixSearch.FetchMixesforUser(MixSearch.ListType.HISTORY, GlobalConfigs.CurrentUser.UserId);
                
                fetchRecentlyPlayedMixesTask.ContinueWith((res) =>
                {
                    historyMixes = new MixCollection(res.Result);
                    Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                    () =>
                            {
                                historyMixesLst.MixSource = historyMixes;
                                historyMixesLst.Visibility = Visibility.Visible;
                            }
                    );

                });
                fetchListenLaterMixesTask.ContinueWith((res) =>
                {
                    listenlaterMixes = new MixCollection(res.Result);
                    Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                    () =>
                            {
                                listenLaterMixesLst.MixSource = listenlaterMixes;
                                listenLaterMixesLst.Visibility = Visibility.Visible;
                            }
                    );
                    
                });
                fetchRecommendedMixesTask.ContinueWith((res) =>
                {
                    recommendedMixes = new MixCollection(res.Result);
                    Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                    () =>
                            {
                                recommendedMixesLst.Visibility = Visibility.Visible;
                            }
                    );
                });
            }
        }