public async Task ChangeLocal() { List<Category> Categories = await App.DataAccess.GetCategoriesAsync(true, false); Hubs.RemoveAt(Hubs.Count - 2); int NbMaxOthers = (((NbItemsHeight - 4) * 2) / 2) + 1; List<Article> Articles = await App.DataAccess.GetArticlesForCategoryAsync(ARTICLE_URL + Categories[Categories.Count - 2].Guid, true, false); Hubs.Insert(Hubs.Count - 1, new HubHomeViewModel() { ID = ARTICLE_URL + Categories[Categories.Count - 2].Guid, Color = new SolidColorBrush(MetroFrance.Libs.ConvertHelpers.HexToColor(Categories[Categories.Count - 2].Color)), HubName = Categories[Categories.Count - 2].Name }); int j = 0; foreach (Article art in Articles) { Stretch stretch = (art.ImgOrientation == LANDSCAPE) ? Stretch.UniformToFill : Stretch.Uniform; int sw = (j == 0) ? WIDTH_FIRST : WIDTH_OTHER; int sh = (j == 0) ? HEIGHT_FIRST : HEIGHT_OTHER; if (j < NbMaxOthers) { ArticleItemViewModel article = new ArticleItemViewModel() { Guid = art.Guid, ContentLight = art.DescrTXT, Title = art.Title, Author = art.Author, PublicationDate = ConvertHelpers.DateTimeToString(art.UpdateDate), NormalVisibility = Windows.UI.Xaml.Visibility.Visible, FilActu = false, HeightBorder = sh, WidthBorder = sw, Tag = art.ImgBig, ShareLink = art.Link, URL = art.Link, Category = Hubs[Hubs.Count - 2].ID, Stretch = stretch, Parent = Hubs[Hubs.Count - 2], HubName = Hubs[Hubs.Count - 2].HubName }; MetroFrance.Data.DataAccess.ResizeParams rp = new Data.DataAccess.ResizeParams(); if (j == 0) { rp = ImageResizeBuilder.GenericResizeBuilder(ImageResizeBuilder.PictureType.BIG_ARTICLE_PICTURE, art.ImgBig); } else { rp = ImageResizeBuilder.GenericResizeBuilder(ImageResizeBuilder.PictureType.MEDIUM_ARTICLE_PICTURE, art.ImgBig); } this.LoadImage(article, rp, true); Hubs[Hubs.Count - 2].Add(article); } else { break; } j++; } Hubs = await this.PhotosHubs(Hubs); }
private async Task<ObservableCollection<HubHomeViewModel>> DataToViewModel(bool refresh, bool cache) { /*while (_isLoadingData) { // Do nothing. This is to avoid loading Data 2 times... } _isLoadingData = true;*/ //Hubs = new ObservableCollection<HubHomeViewModel>(); ArticleItemViewModel errorItem = new ArticleItemViewModel() { ErrorVisibility = Windows.UI.Xaml.Visibility.Visible, HeightBorder = HEIGHT_FIRST, WidthBorder = WIDTH_FIRST }; // Initialize local variables. ObservableCollection<HubHomeViewModel> hubs = new ObservableCollection<HubHomeViewModel>(); ObservableCollection<HubHomeViewModel> hubsToDisplay = new ObservableCollection<HubHomeViewModel>(); int NbMaxItemsALaUne = 0; if (IsLandscape) NbMaxItemsALaUne = ((((NbItemsHeight - 4) * 2) + NbItemsHeight) / 2) + 1; else NbMaxItemsALaUne = ((((NbItemsHeight - 4) * 2)) / 2) + 1; int NbMaxOthers = (((NbItemsHeight - 4) * 2) / 2) + 1; await _buildView.WaitAsync(); List<Category> Categories = new List<Category>(); try { Categories = await App.DataAccess.GetCategoriesAsync(refresh, cache); refresh = false; } catch { if (Hubs.Count == 0) { _buildView.Release(); return new ObservableCollection<HubHomeViewModel>(); } else return Hubs; } foreach (Category catego in Categories) { hubs.Add(new HubHomeViewModel() { ID = ARTICLE_URL + catego.Guid, Color = new SolidColorBrush(MetroFrance.Libs.ConvertHelpers.HexToColor(catego.Color)), HubName = catego.Name }); } int i = 0; if (hubs[2].HubName == App.ResourceLoader.GetString("NewsImages")) hubs.RemoveAt(2); Windows.UI.Xaml.Visibility filInfoVisibility = Windows.UI.Xaml.Visibility.Collapsed; Windows.UI.Xaml.Visibility normalVisibility = Windows.UI.Xaml.Visibility.Collapsed; foreach (HubHomeViewModel hub in hubs) { if (hub.HubName == App.ResourceLoader.GetString("TopNews")) { NbMaxArticle = NbMaxItemsALaUne; filInfoVisibility = Windows.UI.Xaml.Visibility.Collapsed; normalVisibility = Windows.UI.Xaml.Visibility.Visible; } else { if (hub.HubName == App.ResourceLoader.GetString("FilInfoTitle")) { NbMaxArticle = NbItemsHeight; filInfoVisibility = Windows.UI.Xaml.Visibility.Visible; normalVisibility = Windows.UI.Xaml.Visibility.Collapsed; } else { NbMaxArticle = NbMaxOthers; filInfoVisibility = Windows.UI.Xaml.Visibility.Collapsed; normalVisibility = Windows.UI.Xaml.Visibility.Visible; } } try { List<Article> Articles = await App.DataAccess.GetArticlesForCategoryAsync(hub.ID, refresh, cache); if (Articles.Count == 0) throw new System.ArgumentException("WSExeption", "No data"); int j = 0; SolidColorBrush Color; foreach (Article art in Articles) { if (j < NbMaxArticle) { Stretch stretch = (art.ImgOrientation == LANDSCAPE) ? Stretch.UniformToFill : Stretch.Uniform; int sw = (j == 0) ? WIDTH_FIRST : WIDTH_OTHER; int sh = (j == 0) ? HEIGHT_FIRST : HEIGHT_OTHER; if (j % 2 == 0) Color = new SolidColorBrush(MetroFrance.Libs.ConvertHelpers.HexToColor("#EAEBDD")); else Color = new SolidColorBrush(MetroFrance.Libs.ConvertHelpers.HexToColor("#E4F8D7")); ArticleItemViewModel myArticle = new ArticleItemViewModel() { Guid = art.Guid, ContentLight = art.DescrTXT, Title = art.Title, Author = art.Author, FirstHub = (hub.HubName == App.ResourceLoader.GetString("TopNews")) ? true : false, FilActu = (hub.HubName == App.ResourceLoader.GetString("FilInfoTitle")) ? true : false, PublicationDate = ConvertHelpers.DateTimeToString(art.UpdateDate), FilActuVisibility = filInfoVisibility, NormalVisibility = normalVisibility, ShareLink = art.Link, Tag = (hub.HubName == App.ResourceLoader.GetString("FilInfoTitle")) ? art.ImgThumbnail : art.ImgBig, HeightBorder = sh, WidthBorder = sw, URL = art.Link, Category = hub.ID, Color = Color, Stretch = stretch, Parent = hub, HubName = hub.HubName }; string img = (hub.HubName == App.ResourceLoader.GetString("FilInfoTitle")) ? art.ImgThumbnail : art.ImgBig; MetroFrance.Data.DataAccess.ResizeParams rp = new Data.DataAccess.ResizeParams(); if (j == 0) { rp = ImageResizeBuilder.GenericResizeBuilder(ImageResizeBuilder.PictureType.BIG_ARTICLE_PICTURE, img); this.LoadImage(myArticle, rp, true); } else { rp = ImageResizeBuilder.GenericResizeBuilder(ImageResizeBuilder.PictureType.MEDIUM_ARTICLE_PICTURE, img); this.LoadImage(myArticle, rp, true); } hub.Add(myArticle); j++; } else { break; } } } catch (Exception e) { Debug.WriteLine(e.Message); Debug.WriteLine("Article de " + hub.HubName + " error : " + e.Message); hub.Add(errorItem); } i++; hubsToDisplay.Add(hub); Hubs = hubsToDisplay; } Debug.WriteLine(resultTrace); _buildView.Release(); //_isLoadingData = false; return hubs; }