Exemplo n.º 1
0
 private void InitializeBatchDataLoader(ISupportIncrementalLoading supportIncrementalLoading)
 {
     if (supportIncrementalLoading != null)
     {
         this.BatchDataProvider = new BatchLoadingProvider <object>(supportIncrementalLoading, this.InternalList);
     }
 }
Exemplo n.º 2
0
 private void InitializeBatchDataLoader(ISupportIncrementalLoading incrementalLoadingSource)
 {
     if (incrementalLoadingSource != null)
     {
         this.BatchDataProvider = new BatchLoadingProvider <IDataSourceItem>(incrementalLoadingSource, this.items);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        ///  Handle the LazyLoading of items
        /// </summary>
        /// <param name="isInitialized">Is called with Flipview's Initialization</param>
        /// <returns>Task (void)</returns>

        async private Task LoadNextItemAsync(bool isInitialized = true)
        {
            try
            {
                if (this.ItemsSource != null && CanIncrementalLoadigTrigger())
                {
                    IsBusy = true;
                    ISupportIncrementalLoading incrementalLoadingInterface = this.ItemsSource as ISupportIncrementalLoading;
                    if (incrementalLoadingInterface != null)
                    {
                        if (incrementalLoadingInterface.HasMoreItems)
                        {
                            if (!isInitialized)
                            {
                                await incrementalLoadingInterface.LoadMoreItemsAsync(1);

                                return;
                            }

                            for (int i = 1; i <= this.IncrementalLoadingThreshold; i++)
                            {
                                await incrementalLoadingInterface.LoadMoreItemsAsync((uint)this.DataFetchSize);
                            }
                        }
                    }
                }
            }
            finally
            {
                IsBusy = false;
            }
        }
        protected static void AddOrUpdateListingCache(string navigationId, ISupportIncrementalLoading list, double scrollPosition)
        {
            var hash = navigationId.GetHashCode();

            if (_ListingCache.TryGetValue(hash, out var cached))
            {
                // 登録済みの場合は一旦削除して再登録することで辞書位置を更新する
                _ListingCache.Remove(hash);
                cached.ScrollPosition = scrollPosition;
                _ListingCache.Add(hash, cached);
            }
            else
            {
                // キャッシュ上限以上の場合は古いアイテムを削除
                if (_ListingCache.Count > MaxListingCache)
                {
                    // Dictionary の Last() は辞書へより先に追加されたアイテムが取得できる
                    // https://stackoverflow.com/questions/436954/whos-on-dictionary-first
                    _ListingCache.Remove(_ListingCache.Last().Key);
                }

                _ListingCache.Add(hash, new HohoemaListingCache()
                {
                    List = list, ScrollPosition = scrollPosition
                });
            }
        }
Exemplo n.º 5
0
 public IncrementalLoadingFlipView()
 {
     this.SelectionChanged += (sender, e) =>
     {
         if (this.SelectedIndex == this.Items.Count - 3)
         {
             ISupportIncrementalLoading list = this.ItemsSource as ISupportIncrementalLoading;
             if (list?.HasMoreItems == true)
             {
                 list?.LoadMoreItemsAsync((uint)this.Items.Count);
             }
         }
     };
 }
Exemplo n.º 6
0
        protected override void OnBindingContextChanged()
        {
            base.OnBindingContextChanged();

            if (BindingContext != null)
            {
                incrementalLoading = BindingContext as ISupportIncrementalLoading;

                if (incrementalLoading == null)
                {
                    System.Diagnostics.Debug.WriteLine($"{nameof(IncrementalListView)} BindingContext does not implement {nameof(ISupportIncrementalLoading)}. This is required for incremental loading to work.");
                }
            }
        }
Exemplo n.º 7
0
        public BatchLoadingProvider(ISupportIncrementalLoading incrementalLoadingSource, ICollection <T> loadedItemsCollection)
        {
            if (incrementalLoadingSource == null)
            {
                throw new ArgumentException("The batch loading provider requires ISupportIncrementalLoading to operate!");
            }

            this.incrementalLoadingSource = incrementalLoadingSource;
            this.loadedItemsCollection    = loadedItemsCollection;

            var incrementalBatchLoadingSource = incrementalLoadingSource as IIncrementalBatchLoading;

            if (incrementalBatchLoadingSource != null)
            {
                this.BatchSize = incrementalBatchLoadingSource.BatchSize;
            }
        }
Exemplo n.º 8
0
        protected override async void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            base.OnPropertyChanged(propertyName);

            if (propertyName == ItemsSourceProperty.PropertyName)
            {
                itemsSource = ItemsSource as IList;
                if (itemsSource == null)
                {
                    throw new Exception($"{nameof(IncrementalListView)} requires that {nameof(itemsSource)} be of type IList");
                }
                incrementalLoading = ItemsSource as ISupportIncrementalLoading;
                if (incrementalLoading == null)
                {
                    throw new Exception($"{nameof(IncrementalListView)} requires that {nameof(itemsSource)} be of type ISupportIncrementalLoading");
                }

                await incrementalLoading.LoadMoreItemsAsync();
            }
        }
Exemplo n.º 9
0
        private void UpdateIncrementalItemsSource()
        {
            if (_weakIncrementalItemsSourcePropertyChangedListener != null)
            {
                _weakIncrementalItemsSourcePropertyChangedListener.Detach();
                _weakIncrementalItemsSourcePropertyChangedListener = null;
            }

            // Determine if incremental loading should be used
            if (_dataSource is ISupportIncrementalLoading incrementalDataSource)
            {
                _incrementalItemsSource = incrementalDataSource;
            }
            else if (_owner.ItemsSource is ISupportIncrementalLoading incrementalItemsSource)
            {
                _incrementalItemsSource = incrementalItemsSource;
            }
            else
            {
                _incrementalItemsSource = default(ISupportIncrementalLoading);
            }

            if (_incrementalItemsSource != null && _incrementalItemsSource is INotifyPropertyChanged inpc)
            {
                _weakIncrementalItemsSourcePropertyChangedListener = new WeakEventListener <DataGridDataConnection, object, PropertyChangedEventArgs>(this);
                _weakIncrementalItemsSourcePropertyChangedListener.OnEventAction  = (instance, source, eventArgs) => instance.NotifyingIncrementalItemsSource(source, eventArgs);
                _weakIncrementalItemsSourcePropertyChangedListener.OnDetachAction = (weakEventListener) => inpc.PropertyChanged -= weakEventListener.OnEvent;
                inpc.PropertyChanged += _weakIncrementalItemsSourcePropertyChangedListener.OnEvent;
            }

            if (_loadingOperation != null)
            {
                _loadingOperation.Cancel();
                _loadingOperation = null;
            }
        }
Exemplo n.º 10
0
 public IncrementalCollectionWithDelegate(ISupportIncrementalLoading delegato)
 {
     _delegate = delegato;
 }
 public IncrementalGroupedListViewHelper(ListView listView, ISupportIncrementalLoading supportIncrementalLoading)
 {
     _listView = listView;
     SupportIncrementalLoading = supportIncrementalLoading;
     _listView.Loaded         += ListViewOnLoaded;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Load more items from the source
        /// </summary>
        /// <param name="count">number of items to load</param>
        /// <returns>Async operation of LoadMoreItemsResult</returns>
        /// <exception cref="NotImplementedException">Not implemented yet...</exception>
        public IAsyncOperation <LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
        {
            ISupportIncrementalLoading sil = _source as ISupportIncrementalLoading;

            return(sil?.LoadMoreItemsAsync(count));
        }
        /// <summary>
        /// Invoked to load more items from the source.
        /// </summary>
        /// <param name="count">number of items to load</param>
        /// <returns>Async operation of LoadMoreItemsResult</returns>
        public IAsyncOperation <LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
        {
            ISupportIncrementalLoading sourceAsSupportIncrementalLoading = _sourceCollection as ISupportIncrementalLoading;

            return(sourceAsSupportIncrementalLoading?.LoadMoreItemsAsync(count));
        }