Esempio n. 1
0
 private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
 {
     if (scrollViewer.VerticalOffset >= scrollViewer.ScrollableHeight - LoadMoreBottomOffset && CanLoadMore)
     {
         LoadMoreCommand?.Execute(null);
     }
 }
        public HomePageViewModel(INavigationService navigationService, IItemListService itemListService, IEventAggregator eventAggregator) : base(navigationService)
        {
            _itemListService = itemListService;
            _eventAggregator = eventAggregator;

            Title = "ホーム";

            Items = _itemListService.Items.ToReadOnlyReactiveCollection(i => new ItemViewModel(i)).AddTo(_disposables);

            LoadMoreCommand.Subscribe(async item =>
            {
                if (item == Items?.LastOrDefault())
                {
                    await _itemListService.LoadAsync();
                }
            });

            GoToContributionPageCommand.Subscribe(async() => await NavigateAsync <ContributionPageViewModel>());
            GoToItemDetailPageCommand.Subscribe(async viewModel => await NavigateAsync <ItemDetailPageViewModel, string>(viewModel.Id.Value));

            _eventAggregator.GetEvent <DestoryEvent>().Subscribe(_itemListService.Close)
            .AddTo(_disposables);

            _itemListService.LoadAsync();
        }
        public MyPageViewModel(INavigationService navigationService, IUserItemListService userItemListService, IAccountService accountService, IEventAggregator eventAggregator) : base(navigationService)
        {
            _userItemListService = userItemListService;
            _accountService      = accountService;
            _eventAggregator     = eventAggregator;

            Title = "マイページ";

            _userItemListService.SetUserId(_accountService.UserId.Value);
            Items = _userItemListService.Items.ToReadOnlyReactiveCollection(i => new ItemViewModel(i)).AddTo(_disposables);

            UserName          = _accountService.UserName;
            UserImage         = _accountService.UserImage;
            ContributionCount = _accountService.ContributionCount;

            LoadMoreCommand.Subscribe(async item =>
            {
                if (item == Items?.LastOrDefault())
                {
                    await _userItemListService.LoadAsync();
                }
            });

            GoToItemDetailPageCommand.Subscribe(async viewModel => await NavigateAsync <ItemDetailPageViewModel, string>(viewModel.Id.Value));

            _eventAggregator.GetEvent <DestoryEvent>().Subscribe(_userItemListService.Close)
            .AddTo(_disposables);

            _userItemListService.LoadAsync();
        }
 private void MyAdaptiveGridView_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     Debug.WriteLine("内容变更");
     if (scrollViewer.ScrollableHeight == 0)
     {
         LoadMoreCommand?.Execute(null);
     }
 }
Esempio n. 5
0
 public override void WillDisplay(UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
 {
     if ((indexPath.Row >= (ItemsSource.Count() - FromBottomCellStartLoadingIndex)) &&
         LoadMoreCommand != null && LoadMoreCommand.CanExecute(null))
     {
         LoadMoreCommand.Execute(null);
     }
 }
Esempio n. 6
0
        private void OnItemAppearing(object sender, ItemVisibilityEventArgs e)
        {
            if (ItemAppearingCommand != null)
            {
                ItemAppearingCommand?.Execute(e.Item);
            }

            if (LoadMoreCommand != null)
            {
                if (IsGroupingEnabled)
                {
                    if (PageSize == null)
                    {
                        var firstItem = ((IList)ItemsSource.Cast <object>().First()).Cast <object>().First();

                        if (e.Item == firstItem && !IsRefreshing)
                        {
                            LoadMoreCommand?.Execute(null);
                        }
                    }
                    else
                    {
                        var firstItem = ((IList)ItemsSource.Cast <object>().First()).Cast <object>().First();

                        var totalItems = 0;
                        foreach (var item in ItemsSource.Cast <object>())
                        {
                            totalItems = totalItems + ((IList)item).Cast <object>().Count();
                        }

                        if (e.Item == firstItem && !IsRefreshing
                            & totalItems >= PageSize.Value)
                        {
                            LoadMoreCommand?.Execute(null);
                        }
                    }
                }
                else
                {
                    if (PageSize == null)
                    {
                        if (e.Item == ItemsSource.Cast <object>().First() && !IsRefreshing)
                        {
                            LoadMoreCommand?.Execute(null);
                        }
                    }
                    else
                    {
                        if (e.Item == ItemsSource.Cast <object>().First() && !IsRefreshing
                            & ItemsSource.Cast <object>().Count() >= PageSize.Value)
                        {
                            LoadMoreCommand?.Execute(null);
                        }
                    }
                }
            }
        }
        // If the new item that is appearing on the screen is the last one in the
        // collection, we execute the LoadMoreCommand so our ViewModel knows we
        // want to load more data for our user from the data service.
        private void OnItemAppearing(object sender, ItemVisibilityEventArgs e)
        {
            ItemAppearingCommand?.Execute(e.Item);

            //If its the last item execute command and load more data.
            if (e.Item == ItemsSource.Cast <object>().Last())
            {
                LoadMoreCommand?.Execute(null);
            }
        }
Esempio n. 8
0
        protected override async Task LoadMoreContent()
        {
            await Task.Run(async() =>
            {
                var dataSource = await VmService.LoadReviews(LOADING_REVIEWS_COUNT, Reviews.Count);

                CanLoadMore = !dataSource.IsNullOrEmpty() && dataSource.Count == LOADING_REVIEWS_COUNT;
                LoadMoreCommand.RaiseCanExecuteChanged();

                InvokeOnMainThread(() => Reviews.AddRange(dataSource));
            });
        }
Esempio n. 9
0
        public override void ExecuteRefreshCommand()
        {
            if (IsBusy)
            {
                return;
            }

            groups.Clear();
            OnPropertyChanged("Groups");
            CanLoadMore = true;
            LoadMoreCommand.Execute(null);
        }
        void InfiniteListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
        {
            var items = AssociatedObject.ItemsSource as IList;

            if (items != null && e.Item == items[items.Count - 1])
            {
                if (LoadMoreCommand != null && LoadMoreCommand.CanExecute(null))
                {
                    LoadMoreCommand.Execute(null);
                }
            }
        }
Esempio n. 11
0
        protected override async Task LoadContent()
        {
            Loading = true;

            Items = await VmService.LoadPoints(SearchText, 0, LOADING_COUNT);

            CanLoadMore = !Items.IsNullOrEmpty() && Items.Count >= LOADING_COUNT;

            LoadMoreCommand.RaiseCanExecuteChanged();

            Loading = false;
        }
Esempio n. 12
0
        private void InfiniteListViewItemAppearing(object sender, ItemVisibilityEventArgs e)
        {
            var items = ItemsSource as IList;

            if ((items != null) && (items.Count >= ItemsPerPage) && (items.Count - 3 >= 0) &&
                (e.Item == items[items.Count - 3]))
            {
                if ((LoadMoreCommand != null) && LoadMoreCommand.CanExecute(null))
                {
                    LoadMoreCommand.Execute(null);
                }
            }
        }
Esempio n. 13
0
        protected virtual async Task LoadContent()
        {
            Loading = true;

            var dataSource = await VmService.LoadReviews(LOADING_REVIEWS_COUNT);

            InvokeOnMainThread(() => Reviews = dataSource);

            CanLoadMore = !dataSource.IsNullOrEmpty() && dataSource.Count == LOADING_REVIEWS_COUNT;
            LoadMoreCommand.RaiseCanExecuteChanged();

            Loading = false;
        }
Esempio n. 14
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);
             }
         }
     }
 }
Esempio n. 15
0
        protected override Task LoadMoreContent()
        {
            return(Task.Run(async() =>
            {
                var moreItems = await VmService.LoadPoints(SearchText, Items?.Count ?? 0, LOADING_COUNT);

                InvokeOnMainThread(() => Items.AddRange(moreItems));

                CanLoadMore = !moreItems.IsNullOrEmpty() && moreItems.Count == LOADING_COUNT;

                LoadMoreCommand.RaiseCanExecuteChanged();
            }));
        }
        private void LoadArticlesPage(FetchArticlesResult articles)
        {
            var nextPage = Articles.VirtualPage + 1;

            if (nextPage != articles.PageNumber)
            {
                // Already loaded, discarding the result
                return;
            }

            Articles.AddPage(articles.Articles, articles.TotalCount, articles.PageNumber, articles.PageSize);
            LoadMoreCommand.ChangeCanExecute();
            Raise(nameof(IsEmpty));
        }
Esempio n. 17
0
 private void OnItemAppearing(object sender, ItemVisibilityEventArgs e)
 {
     if (ItemAppearingCommand != null)
     {
         ItemAppearingCommand?.Execute(e.Item);
     }
     if (LoadMoreCommand != null)
     {
         if (e.Item == ItemsSource.Cast <object>().Last())
         {
             LoadMoreCommand?.Execute(null);
         }
     }
 }
Esempio n. 18
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);
                }
            }
        }
Esempio n. 19
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);
                    }
                }
            }
        }
Esempio n. 20
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);
                }
            }
        }
        protected override void OnApplyTemplate()
        {
            scrollViewer              = GetTemplateChild("ScrollViewer") as ScrollViewer;
            scrollViewer.ViewChanged += ScrollViewer_ViewChanged;
            this.RegisterPropertyChangedCallback(LoadingProperty, new DependencyPropertyChangedCallback((obj, e) => {
                if (!Loading)
                {
                    if (scrollViewer.ScrollableHeight == 0)
                    {
                        LoadMoreCommand?.Execute(null);
                    }
                }
            }));

            base.OnApplyTemplate();
        }
Esempio n. 22
0
        protected override async Task LoadItems()
        {
            Loading = true;

            var dataSource = await VmService.LoadMarkedProducts(LOADING_PRODUCTS_COUNT);

            InvokeOnMainThread(() =>
            {
                Items = dataSource;
                Empty = Items.IsNullOrEmpty();
            });

            CanLoadMore = !dataSource.IsNullOrEmpty() && dataSource.Count == LOADING_PRODUCTS_COUNT;
            LoadMoreCommand.RaiseCanExecuteChanged();

            Loading = false;
        }
Esempio n. 23
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);
                }
            }
        }
Esempio n. 24
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);
            }
        }
Esempio n. 25
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;
            }
        }
Esempio n. 26
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)
     {
     }
 }
Esempio n. 27
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);
            }
        }
        protected override async Task LoadMoreContent()
        {
            if (Loading || LoadingMore)
            {
                return;
            }

            LoadingMore = true;

            var dataSource = await VmService.LoadHistoryOrders(LOADING_ORDERS_COUNT, offset : Orders.Count);

            CanLoadMore = !dataSource.IsNullOrEmpty() && dataSource.Count == LOADING_ORDERS_COUNT;
            LoadMoreCommand.RaiseCanExecuteChanged();

            InvokeOnMainThread(() =>
            {
                Orders.AddRange(dataSource);
            });

            LoadingMore = false;
        }
Esempio n. 29
0
        protected override void OnLoadMoreExecute()
        {
            if (Loading || LoadingMore)
                return;

            Task.Run(async () =>
            {
                LoadingMore = true;

                var dataSource = await VmService.LoadMarkedProducts(LOADING_PRODUCTS_COUNT, Items.Count);

                CanLoadMore = !dataSource.IsNullOrEmpty() && dataSource.Count == LOADING_PRODUCTS_COUNT;
                LoadMoreCommand.RaiseCanExecuteChanged();

                InvokeOnMainThread(() =>
                {
                    Items.AddRange(dataSource);
                    Empty = Items.IsNullOrEmpty();
                });

                LoadingMore = false;
            });
        }
        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
                    }
                }
            };
        }