/// <summary> /// Update data properties in the view model by syncing with the server data. /// </summary> public async Task Update(bool justForLiveTile = false) { IsUpdateRequested = true; _gotResponseEver = false; _isDataLoadedPartially = false; Debug.WriteLine("!!! Updating feed data: MainVM.Update"); // Set up the Feed Service. if (_feedService != null) { DataLayer.SetFeedService(_feedService); } else { DataLayer.SetDefaultFeedService(); } var categoryModels = await DataLayer.GetCategoriesAsync(); var appDealsCategory = await GetAppDealsCategory(); var categoryVMs = new ObservableCollection<CategoryViewModel>(); if (categoryModels.Count > 0) { _gotResponseEver = true; Debug.WriteLine("Got response ever"); } try { for (int i = 0; i < categoryModels.Count; i++) { var category = categoryModels[i]; var categoryViewModel = new CategoryViewModel(category); // // TODO:Carousal feature is disabled in V1. Enable if we want the carousal functionality. // //if (i == 0) //{ // // Only the first module, we want the carousal // categoryViewModel.SetCarousalInterval(CategoryViewModel.CarousalInterval.Daily); //} await categoryViewModel.Update(justForLiveTile); if (categoryViewModel.HasAlbum()) { categoryViewModel.PropertyChanged += CategoryPropertyChanged; categoryVMs.Add(categoryViewModel); } } } catch (DataLayerFeedException ex) { // Notify UI that this is partial data. _isDataLoadedPartially = true; } _mainImage = categoryModels[0].ImageUrl; // Clean up old Category VMs and event handlers. if (_categoryViewModels != null && _categoryViewModels.Count > 0) { foreach (var categoryViewModel in _categoryViewModels) { categoryViewModel.PropertyChanged -= CategoryPropertyChanged; } _categoryViewModels.Clear(); } //Append Music Apps category to collection if (null != appDealsCategory) categoryVMs.Add(appDealsCategory); _categoryViewModels = categoryVMs; _isDataLoaded = true; _isDataLoadedPartially = false; Debug.WriteLine("Main VM - Categories are updated"); OnPropertyChanged("CategoryViewModels"); OnPropertyChanged("IsDataLoaded"); }
private async Task<CategoryViewModel> GetAppDealsCategory() { var appDealsData = await _appStoreService.GetAppStoreDealsFeedDataAsync(); //Populate view model properties if (appDealsData != null) { var appViewModels = new ObservableCollection<AppElementViewModel>(); foreach (var item in appDealsData.Items) { var appVM = new AppElementViewModel(item, _usePhoneFeed); appViewModels.Add(appVM); } var categoryVM = new CategoryViewModel(appViewModels); return categoryVM; } return null; }