Пример #1
0
        protected override async Task<IAsyncEnumerable<VideoInfoControlViewModel>> GetPagedItemsImpl(int head, int count)
        {
            VideoListingResponse res = null;
            if (SearchOption.SearchTarget == SearchTarget.Keyword)
            {
                res = await SearchProvider.GetKeywordSearch(SearchOption.Keyword, (uint)head, (uint)count, SearchOption.Sort, SearchOption.Order);
            }
            else if (SearchOption.SearchTarget == SearchTarget.Tag)
            {
                res = await SearchProvider.GetTagSearch(SearchOption.Keyword, (uint)head, (uint)count, SearchOption.Sort, SearchOption.Order);
            }


            if (res == null || res.VideoInfoItems == null)
            {
                return AsyncEnumerable.Empty<VideoInfoControlViewModel>();
            }
            else
            {
                return res.VideoInfoItems.Where(x => x != null).Select(item =>
                {
                    var vm = new VideoInfoControlViewModel(item.Video.Id);

                    vm.SetupDisplay(item);
                    return vm;
                })
                .ToAsyncEnumerable();
            }
        }
Пример #2
0
        protected override async Task<int> ResetSourceImpl()
        {
            int totalCount = 0;
            if (SearchOption.SearchTarget == SearchTarget.Keyword)
            {
                var res = await SearchProvider.GetKeywordSearch(SearchOption.Keyword, 0, 2, SearchOption.Sort, SearchOption.Order);
                totalCount = (int)res.GetTotalCount();

            }
            else if (SearchOption.SearchTarget == SearchTarget.Tag)
            {
                var res = await SearchProvider.GetTagSearch(SearchOption.Keyword, 0, 2, SearchOption.Sort, SearchOption.Order);
                totalCount = (int)res.GetTotalCount();
            }

            return totalCount;
        }
Пример #3
0
        public SearchSummaryPageViewModel(
            SearchProvider searchProvider,
            Services.PageManager pageManager
            )
            : base(pageManager)
        {
            RelatedVideoTags = new ObservableCollection <string>();

            KeywordSearchResultItems = this.ObserveProperty(x => x.Keyword)
                                       .Where(x => !string.IsNullOrWhiteSpace(x))
                                       .SelectMany(async(x, i, cancelToken) =>
            {
                RelatedVideoTags.Clear();
                var res = await SearchProvider.GetKeywordSearch(x, 0, 10);

                if (res.IsOK)
                {
                    KeywordSearchItemsTotalCount = (int)res.GetTotalCount();

                    if (res.Tags != null)
                    {
                        foreach (var tag in res.Tags.TagItems)
                        {
                            RelatedVideoTags.Add(tag.Name);
                        }
                    }

                    return(res.VideoInfoItems?.AsEnumerable() ?? Enumerable.Empty <Mntone.Nico2.Searches.Video.VideoInfo>());
                }
                else
                {
                    return(Enumerable.Empty <Mntone.Nico2.Searches.Video.VideoInfo>());
                }
            })
                                       .SelectMany(x => x)
                                       .Select(x =>
            {
                var vm = new VideoInfoControlViewModel(x.Video.Id);
                vm.SetTitle(x.Video.Title);
                vm.SetThumbnailImage(x.Video.ThumbnailUrl.OriginalString);
                return(vm);
            })
                                       .ToReadOnlyReactiveCollection(onReset: this.ObserveProperty(x => x.Keyword).ToUnit())
                                       .AddTo(_CompositeDisposable);
            HasKeywordSearchResultItems = KeywordSearchResultItems
                                          .ObserveProperty(x => x.Count)
                                          .Select(x => x > 0)
                                          .ToReadOnlyReactiveProperty()
                                          .AddTo(_CompositeDisposable);

            RelatedLiveTags       = new ObservableCollection <string>();
            LiveSearchResultItems = this.ObserveProperty(x => x.Keyword)
                                    .Where(x => !string.IsNullOrWhiteSpace(x))
                                    .SelectMany(async(x, i, cancelToken) =>
            {
                RelatedLiveTags.Clear();
                var res = await SearchProvider.LiveSearchAsync(x, false, length: 10);
                if (res.IsStatusOK)
                {
                    if (res.Tags != null)
                    {
                        foreach (var tag in res.Tags.Tag)
                        {
                            RelatedLiveTags.Add(tag.Name);
                        }
                    }

                    LiveSearchItemsTotalCount = res.TotalCount.FilteredCount;
                    return(res.VideoInfo?.AsEnumerable() ?? Enumerable.Empty <Mntone.Nico2.Searches.Live.VideoInfo>());
                }
                else
                {
                    return(Enumerable.Empty <Mntone.Nico2.Searches.Live.VideoInfo>());
                }
            })
                                    .SelectMany(x => x)
                                    .Select(x =>
            {
                var liveInfoVM = new LiveInfoListItemViewModel(x.Video.Id);
                liveInfoVM.Setup(x);
                return(liveInfoVM);
            })
                                    .ToReadOnlyReactiveCollection(onReset: this.ObserveProperty(x => x.Keyword).ToUnit());
            HasLiveSearchResultItems = LiveSearchResultItems
                                       .ObserveProperty(x => x.Count)
                                       .Select(x => x > 0)
                                       .ToReadOnlyReactiveProperty()
                                       .AddTo(_CompositeDisposable);
            SearchProvider = searchProvider;
        }