Exemplo n.º 1
0
 private void LoadMoreListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
 {
     if (ItemsSource is IList items && e.Item == items[items.Count - 1])
     {
         if (CanLoadMore && LoadStatus == LoadMoreStatus.StatusHasData)
         {
             if (CanLoadMore && (LoadMoreCommand?.CanExecute(null) == true))
             {
                 LoadMoreCommand.Execute(null);
             }
         }
     }
 }
Exemplo n.º 2
0
        private void OnItemAppearing(object sender, ItemVisibilityEventArgs e)
        {
            if (ItemsSource != null && e.Item != null)
            {
                var items = ItemsSource as IList;

                if (e.Item == items[items.Count - 1])
                {
                    var execute = LoadMoreCommand?.CanExecute(e);
                    if (execute.HasValue && execute.Value)
                        LoadMoreCommand?.Execute(e.Item);
                }
            }
        }
Exemplo n.º 3
0
        private void InfiniteListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
        {
            if (IsLoadingMore)
            {
                return;
            }

            if (ItemsSource is IList items && e.Item == items[items.Count - 1])
            {
                if (LoadMoreCommand != null && LoadMoreCommand.CanExecute(null))
                {
                    LoadMoreCommand.Execute(null);
                }
            }
        }
Exemplo n.º 4
0
        void LoadMoreListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
        {
            var items = ItemsSource as IList;

            if (items != null && e.Item == items[items.Count - 1])
            {
                if (CanLoadMore && LoadStatus == LoadMoreStatus.StausDefault)
                {
                    if (CanLoadMore && (LoadMoreCommand != null && LoadMoreCommand.CanExecute(null)))
                    {
                        LoadMoreCommand.Execute(null);
                    }
                }
            }
        }
Exemplo n.º 5
0
        void InfiniteListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
        {
            if (!CanLoadMorePages)
            {
                return;
            }

            var items = ItemsSource as IList;

            if (items != null && e.Item == items[items.Count - 1])
            {
                if (LoadMoreCommand != null && LoadMoreCommand.CanExecute(null))
                {
                    LoadMoreCommand.Execute(null);
                }
            }
        }
Exemplo n.º 6
0
        void InfiniteListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
        {
            byte visibleLoad = 1;
            var  items       = AssociatedObject.ItemsSource as IList;

            if ((items == null) || (items?.Count ?? 0) < visibleLoad || (e?.Item ?? null) == null)
            {
                return;
            }

            if (items.IndexOf(e?.Item ?? null) >= items.Count - (visibleLoad + 1))
            {
                if (LoadMoreCommand != null && LoadMoreCommand.CanExecute(null))
                {
                    LoadMoreCommand.Execute(null);
                }
            }
        }
Exemplo n.º 7
0
        private void ExtendedListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
        {
            try
            {
                if (ItemsSource is IList items && e.Item.Equals(items[items.Count - LoadPositionOffset]))
                {
                    var param = LoadMoreCommandParameter ?? e.Item;

                    if (LoadMoreCommand != null && LoadMoreCommand.CanExecute(param))
                    {
                        LoadMoreCommand.Execute(param);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Exemplo n.º 8
0
 void InfiniteListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
 {
     try
     {
         var items = ItemsSource as IList;
         if (items.Count > 0)
         {
             if (items != null && e.Item == items[items.Count - 1])
             {
                 if (LoadMoreCommand != null && LoadMoreCommand.CanExecute(null))
                 {
                     LoadMoreCommand.Execute(null);
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
     }
 }
Exemplo n.º 9
0
        private void InfiniteListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
        {
            var items = ItemsSource as IList;

            if (items == null)
            {
                Log.Warn("ItemsSource needs to be of type IList, otherwise performance suffers to great");
                return;
            }

            if (LoadMoreCommand == default(ICommand))
            {
                return;
            }

            if (e.Item == items[items.Count - LoadMoreOffset] && LoadMoreCommand.CanExecute(e.Item))
            {
                LoadMoreCommand.Execute(e.Item);
            }
        }
        public LoadMoreListView()
        {
            ItemAppearing += (sender, args) =>
            {
                IList items = ItemsSource as IList;

                if (items?.Count == 0 && LoadMoreCommand == null && !LoadMoreCommand.CanExecute(null))
                {
                    return;
                }

                if (args.Item == items[items.Count - 1])
                {
                    LoadMoreCommand.Execute(null);
                }
            };

            Footer = new StackLayout
            {
                Spacing           = 0,
                Padding           = 12,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Transparent,
                Children          =
                {
                    new ActivityIndicator
                    {
                        IsRunning         = true,
                        HeightRequest     = 15,
                        VerticalOptions   = LayoutOptions.CenterAndExpand,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Color             = AppColor.MainAction
                    }
                }
            };
        }
Exemplo n.º 11
0
        public LoadMoreListView() : base(ListViewCachingStrategy.RecycleElement)
        {
            Xamarin.Forms.PlatformConfiguration.iOSSpecific.ListView.SetSeparatorStyle(this, Xamarin.Forms.PlatformConfiguration.iOSSpecific.SeparatorStyle.FullWidth);

            loadingPage = new StackLayout
            {
                Orientation   = StackOrientation.Horizontal,
                HeightRequest = 50,
                Children      =
                {
                    new StackLayout
                    {
                        VerticalOptions   = LayoutOptions.CenterAndExpand,
                        HorizontalOptions = LayoutOptions.CenterAndExpand,
                        Orientation       = StackOrientation.Horizontal,
                        Children          =
                        {
                            new ActivityIndicator {
                                IsRunning       = true,
                                WidthRequest    = 20,
                                HeightRequest   = 20,
                                Color           = (Color)Application.Current.Resources["Primary"],
                                VerticalOptions = LayoutOptions.CenterAndExpand
                            },
                            new Label
                            {
                                Text            = "Loading...",
                                Style           = Application.Current.Resources["SecondaryTextStyle"] as Style,
                                VerticalOptions = LayoutOptions.CenterAndExpand
                            }
                        }
                    }
                }
            };
            endPage = new StackLayout
            {
                HeightRequest     = 50,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children          =
                {
                    new Label
                    {
                        Text            = "No more",
                        Style           = Application.Current.Resources["SecondaryTextStyle"] as Style,
                        VerticalOptions = LayoutOptions.CenterAndExpand
                    }
                }
            };
            failPage = new StackLayout
            {
                HeightRequest = FailHeight,
                Children      =
                {
                    new StackLayout
                    {
                        VerticalOptions   = LayoutOptions.EndAndExpand,
                        HorizontalOptions = LayoutOptions.CenterAndExpand,
                        Children          =
                        {
                            new Label
                            {
                                Text              = "It seems that something went wrong.",
                                Style             = Application.Current.Resources["SecondaryTextStyle"] as Style,
                                HorizontalOptions = LayoutOptions.CenterAndExpand,
                            },
                            new Label
                            {
                                Text              = "Reload",
                                Style             = Application.Current.Resources["SecondaryTextStyle"] as Style,
                                TextColor         = (Color)Application.Current.Resources["Primary"],
                                HorizontalOptions = LayoutOptions.CenterAndExpand,
                            }
                        }
                    }
                }
            };
            var failGestureRecognizer = new TapGestureRecognizer();

            failGestureRecognizer.Tapped += (s, e) =>
            {
                if (LoadStatus == LoadMoreStatus.StausFail)
                {
                    RefreshCommand.Execute(null);
                }
            };
            failPage.GestureRecognizers.Add(failGestureRecognizer);

            nodataPage = new StackLayout
            {
                HeightRequest     = 50,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children          =
                {
                    new Label
                    {
                        Text            = "No content yet",
                        Style           = Application.Current.Resources["SecondaryTextStyle"] as Style,
                        VerticalOptions = LayoutOptions.CenterAndExpand
                    }
                }
            };

            errorPage = new StackLayout
            {
                HeightRequest     = 50,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children          =
                {
                    new Label
                    {
                        Text            = "Failed to load, click to try again",
                        Style           = Application.Current.Resources["SecondaryTextStyle"] as Style,
                        VerticalOptions = LayoutOptions.CenterAndExpand
                    }
                }
            };
            var errorGestureRecognizer = new TapGestureRecognizer();

            errorGestureRecognizer.Tapped += (s, e) =>
            {
                if (LoadStatus == LoadMoreStatus.StausError && LoadMoreCommand != null && LoadMoreCommand.CanExecute(null))
                {
                    LoadMoreCommand.Execute(null);
                }
            };
            errorPage.GestureRecognizers.Add(errorGestureRecognizer);

            nologinPage = new StackLayout
            {
                HeightRequest = FailHeight,
                Children      =
                {
                    new StackLayout
                    {
                        VerticalOptions   = LayoutOptions.EndAndExpand,
                        HorizontalOptions = LayoutOptions.CenterAndExpand,
                        Children          =
                        {
                            new Label
                            {
                                Text              = "Not logged in yet",
                                Style             = Application.Current.Resources["SecondaryTextStyle"] as Style,
                                HorizontalOptions = LayoutOptions.CenterAndExpand,
                            },
                            new Label
                            {
                                Text              = "Log in now",
                                Style             = Application.Current.Resources["SecondaryTextStyle"] as Style,
                                TextColor         = (Color)Application.Current.Resources["Primary"],
                                HorizontalOptions = LayoutOptions.CenterAndExpand,
                            }
                        }
                    }
                }
            };
            var nologinGestureRecognizer = new TapGestureRecognizer();

            nologinGestureRecognizer.Tapped += (s, e) =>
            {
                if (LoadStatus == LoadMoreStatus.StausNologin)
                {
                    MessagingService.Current.SendMessage(MessageKeys.NavigateLogin);
                }
            };
            nologinPage.GestureRecognizers.Add(nologinGestureRecognizer);

            ItemAppearing += LoadMoreListView_ItemAppearing;
        }
Exemplo n.º 12
0
        public LoadMoreListView() : base(ListViewCachingStrategy.RecycleElement)
        {
            loadingPage = new StackLayout
            {
                Orientation   = StackOrientation.Horizontal,
                HeightRequest = 50,
                Children      =
                {
                    new StackLayout
                    {
                        VerticalOptions   = LayoutOptions.CenterAndExpand,
                        HorizontalOptions = LayoutOptions.CenterAndExpand,
                        Orientation       = StackOrientation.Horizontal,
                        Children          =
                        {
                            new ActivityIndicator {
                                IsRunning       = true,
                                WidthRequest    = 20,
                                HeightRequest   = 20,
                                Color           = (Color)Application.Current.Resources["Primary"],
                                VerticalOptions = LayoutOptions.CenterAndExpand
                            },
                            new Label
                            {
                                Text            = "正在加载中",
                                Style           = Application.Current.Resources["SecondaryTextStyle"] as Style,
                                VerticalOptions = LayoutOptions.CenterAndExpand
                            }
                        }
                    }
                }
            };
            endPage = new StackLayout
            {
                HeightRequest     = 50,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children          =
                {
                    new Label
                    {
                        Text            = "没有更多了",
                        Style           = Application.Current.Resources["SecondaryTextStyle"] as Style,
                        VerticalOptions = LayoutOptions.CenterAndExpand
                    }
                }
            };
            failPage = new StackLayout
            {
                HeightRequest = FailHeight,
                Children      =
                {
                    new StackLayout
                    {
                        VerticalOptions   = LayoutOptions.EndAndExpand,
                        HorizontalOptions = LayoutOptions.CenterAndExpand,
                        Children          =
                        {
                            new Label
                            {
                                Text              = "似乎出了点问题",
                                Style             = Application.Current.Resources["SecondaryTextStyle"] as Style,
                                HorizontalOptions = LayoutOptions.CenterAndExpand,
                            },
                            new Label
                            {
                                Text              = "重新加载",
                                Style             = Application.Current.Resources["SecondaryTextStyle"] as Style,
                                TextColor         = (Color)Application.Current.Resources["Primary"],
                                HorizontalOptions = LayoutOptions.CenterAndExpand,
                            }
                        }
                    }
                }
            };
            var failGestureRecognizer = new TapGestureRecognizer();

            failGestureRecognizer.Tapped += (s, e) =>
            {
                if (LoadStatus == LoadMoreStatus.StausFail)
                {
                    RefreshCommand.Execute(null);
                }
            };
            failPage.GestureRecognizers.Add(failGestureRecognizer);

            nodataPage = new StackLayout
            {
                HeightRequest     = 50,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children          =
                {
                    new Label
                    {
                        Text            = "还没有内容",
                        Style           = Application.Current.Resources["SecondaryTextStyle"] as Style,
                        VerticalOptions = LayoutOptions.CenterAndExpand
                    }
                }
            };

            errorPage = new StackLayout
            {
                HeightRequest     = 50,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children          =
                {
                    new Label
                    {
                        Text            = "加载失败,点击重试",
                        Style           = Application.Current.Resources["SecondaryTextStyle"] as Style,
                        VerticalOptions = LayoutOptions.CenterAndExpand
                    }
                }
            };
            var errorGestureRecognizer = new TapGestureRecognizer();

            errorGestureRecognizer.Tapped += (s, e) =>
            {
                if (LoadStatus == LoadMoreStatus.StausError && LoadMoreCommand != null && LoadMoreCommand.CanExecute(null))
                {
                    LoadMoreCommand.Execute(null);
                }
            };
            errorPage.GestureRecognizers.Add(errorGestureRecognizer);

            nologinPage = new StackLayout
            {
                HeightRequest = FailHeight,
                Children      =
                {
                    new StackLayout
                    {
                        VerticalOptions   = LayoutOptions.EndAndExpand,
                        HorizontalOptions = LayoutOptions.CenterAndExpand,
                        Children          =
                        {
                            new Label
                            {
                                Text              = "还未登录",
                                Style             = Application.Current.Resources["SecondaryTextStyle"] as Style,
                                HorizontalOptions = LayoutOptions.CenterAndExpand,
                            },
                            new Label
                            {
                                Text              = "马上登录",
                                Style             = Application.Current.Resources["SecondaryTextStyle"] as Style,
                                TextColor         = (Color)Application.Current.Resources["Primary"],
                                HorizontalOptions = LayoutOptions.CenterAndExpand,
                            }
                        }
                    }
                }
            };
            var nologinGestureRecognizer = new TapGestureRecognizer();

            nologinGestureRecognizer.Tapped += (s, e) =>
            {
                if (LoadStatus == LoadMoreStatus.StausNologin)
                {
                    MessagingService.Current.SendMessage(MessageKeys.NavigateLogin);
                }
            };
            nologinPage.GestureRecognizers.Add(nologinGestureRecognizer);


            ItemAppearing += LoadMoreListView_ItemAppearing;
        }
Exemplo n.º 13
0
        private void OnItemAppearing(object sender, ItemVisibilityEventArgs e)
        {
            var items = ItemsSource as IList;

            if (_isLoadingMore || items == null || items.Count == 0 || LoadMoreCommand == null || !LoadMoreCommand.CanExecute(e.Item))
            {
                return;
            }

            // Hit the bottom
            if (e.Item == items[items.Count - 1])
            {
                _isLoadingMore = true;

                LoadMoreCommand.Execute(null);

                _isLoadingMore = false;
            }
        }