Пример #1
0
        private async void TryRequestMoreItemFromLoadableSource()
        {
            if (is_requesting)
            {
                Log.Debug("Task is running");
                return;
            }

            if (loadable_items == null)
            {
                return;
            }

            OnRequestMoreItemStarted?.Invoke(this);

            var option = SettingManager.LoadSetting <GlobalSetting>();

            is_requesting = true;

            Gallery gallery = Gallery;
            IEnumerable <GalleryItem> source = loadable_items;

            (GalleryItem[] list, bool success) = await Task.Run(() => {
                try
                {
                    var l = FilterTag(source.Skip(current_index), gallery).Take(option.GetPictureCountPerLoad).ToArray();
                    return(l, true);
                }
                catch (Exception e)
                {
                    Toast.ShowMessage($"无法获取图片列表数据:{e.Message}");
                    return(new GalleryItem[0], false);
                }
            });

            Log.Debug($"Skip({current_index}) Take({option.GetPictureCountPerLoad}) ActualTake({list.Length})", "GridViewer_RequestMoreItems");

            Dispatcher.Invoke(new Action(() =>
            {
                if (source != loadable_items)
                {
                    return;
                }

                foreach (var item in list)
                {
                    Items.Add(item);
                }

                if (success && list.Count() < option.GetPictureCountPerLoad)
                {
                    Toast.ShowMessage("已到达图片队列末尾");
                }
                current_index += list.Length;
            }));

            OnRequestMoreItemFinished?.Invoke(this);
            is_requesting = false;
        }
Пример #2
0
        private async void TryRequestMoreItemFromLoadableSource()
        {
            if (is_requesting)
            {
                Log.Debug("Task is running");
                return;
            }

            if (loadable_items == null)
            {
                return;
            }

            OnRequestMoreItemStarted?.Invoke(this);

            var option = SettingManager.LoadSetting <GlobalSetting>();

            is_requesting = true;

            Gallery gallery = Gallery;
            IEnumerable <GalleryItem> source = loadable_items;
            var counter = new SkipCounterWrapper();

            Log.Debug($"开始尝试获取列表({source.GetHashCode()})");

            (GalleryItem[] list, bool success) = await Task.Run(() =>
            {
                try
                {
                    var l = FilterTag(source.Skip(current_index), counter, gallery).Where(x =>
                    {
                        if (unique_items.Contains(x.GalleryItemID))
                        {
                            return(false);
                        }
                        unique_items.Add(x.GalleryItemID);
                        return(true);
                    }).Take(option.GetPictureCountPerLoad).ToArray();
                    return(l, true);
                }
                catch (Exception e)
                {
                    Toast.ShowMessage($"无法获取图片列表数据:{e.Message}");
                    return(new GalleryItem[0], false);
                }
            });

            Log.Debug($"尝试获取列表结束({source.GetHashCode()} - {loadable_items?.GetHashCode()})");

            if (source == loadable_items)
            {
                Log.Debug($"Skip({current_index}) Filter({counter.Count}) Take({option.GetPictureCountPerLoad}) ActualTake({list.Length})", "GridViewer_RequestMoreItems");

                foreach (var item in list)
                {
                    Items.Add(item);
                }

                if (success && list.Count() < option.GetPictureCountPerLoad)
                {
                    Toast.ShowMessage("已到达图片队列末尾");
                }
                current_index += list.Length + counter.Count;
            }

            OnRequestMoreItemFinished?.Invoke(this);
            is_requesting = false;

            if (source != loadable_items && loadable_items != null)
            {
                TryRequestMoreItemFromLoadableSource();
            }
        }