async void CreateLayout() { if (_noFavoritesView == null) { _noFavoritesView = new NoDataView (Strings.HeartIcon, Strings.NoFavoritesText) { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand }; } _noFavoritesView.Opacity = 0; if (_mainLayot == null) { _mainLayot = new StackLayout { Spacing = 20, Padding = new Thickness (10) }; } if (_mainContent == null) { _mainContent = new ScrollView { Opacity = 0, Content = _mainLayot }; } if (Content == null) { if (ViewModel.FavoritesLeagues.Count == 0) { Content = _noFavoritesView; await Content.FadeTo (1, (uint)Integers.AnimationSpeed, Easing.SinIn); return; } else { foreach (var league in SqlManager.Cache.Favorites) { var card = new LeagueCardView (league); card.OnCardClicked = OnCardClicked; _mainLayot.Children.Add (card); } } Content = _mainContent; await Content.FadeTo (1, (uint)Integers.AnimationSpeed, Easing.SinIn); } else { if (_mainContent.Content is StackLayout) { if (ViewModel.FavoritesLeagues.Count == 0) { foreach (var card in (_mainContent.Content as StackLayout).Children) { await card.FadeTo (0, (uint)Integers.AnimationSpeed, Easing.SinIn); } Content = _noFavoritesView; await _noFavoritesView.FadeTo (1, (uint)Integers.AnimationSpeed, Easing.SinIn); } else if(ViewModel.FavoritesLeagues.Count != (_mainContent.Content as StackLayout).Children.Count) { var removedIndex = -1; for(int i = 0; i < (_mainContent.Content as StackLayout).Children.Count; i++) { if (ViewModel.FavoritesLeagues.FirstOrDefault (item => item.Id == ((_mainContent.Content as StackLayout).Children[i] as LeagueCardView).LeagueItem.Id) == null && removedIndex == -1) { removedIndex = i; await (_mainContent.Content as StackLayout).Children [i].FadeTo (0, (uint)Integers.AnimationSpeed, Easing.SinIn); await Task.Delay (100); (_mainContent.Content as StackLayout).Children.RemoveAt (i); break; } } } } else { Content = _noFavoritesView; await _noFavoritesView.FadeTo (1, (uint)Integers.AnimationSpeed, Easing.SinIn); } } }
void CreateLayout() { _noDataView = new NoDataView("ic_cloud_off_48pt", "No Data Found") { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand }; _loadingDataView = new LoadingDataView { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand }; _arrowImage = new Image { Source = "ic_arrow_downward" }; _pullText = new Label () { Text = "Pull To Refresh", FontSize = 15, TextColor = Color.Black, HorizontalTextAlignment = TextAlignment.Center }; _pullToRefreshLayout = new StackLayout { VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.CenterAndExpand, Spacing = 5, Padding = new Thickness(0,5,0,0), Children = { _arrowImage, _pullText } }; _mainNoDataLayout = new ListView { SeparatorVisibility = SeparatorVisibility.None, IsPullToRefreshEnabled = true, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Header = new StackLayout{ Spacing = 200, Children = { _pullToRefreshLayout, _noDataView } } }; if (Device.OS == TargetPlatform.iOS) { var isfavorite = League.IsFavorite; _addItem = new ToolbarItem (); _addItem.Text = isfavorite ? "remove" : "add"; _addItem.Clicked += _addItem_Clicked; _addItem.Icon = isfavorite ? "ic_favorite_white" : "ic_favorite_border_white"; ToolbarItems.Add (_addItem); } _fixturesListView = new ListView (ListViewCachingStrategy.RecycleElement) { RowHeight = 120, IsPullToRefreshEnabled = true, BackgroundColor = Color.White, ItemTemplate = new DataTemplate(typeof(FixtureLayout)), SeparatorVisibility = SeparatorVisibility.None, Opacity = 0 }; }