Пример #1
0
        private async Task Load()
        {
            var items = new List <Tuple <string, IList <RepositoryItemViewModel> > >();

            foreach (var t in Times)
            {
                var repos = await _trendingRepository.GetTrendingRepositories(t.Item2, SelectedLanguage.Slug);

                var viewModels = repos
                                 .Select(x => new RepositoryItemViewModel(x, true, true, vm => RepositoryItemSelected.ExecuteNow(vm)))
                                 .ToList();

                items.Add(Tuple.Create(t.Item1, viewModels as IList <RepositoryItemViewModel>));
            }

            Items = items;
        }
        public RepositoriesTrendingViewModel(ISessionService applicationService, ITrendingRepository trendingRepository)
        {
            ShowRepositoryDescription = applicationService.Account.ShowRepositoryDescriptionInList;

            Title = "Trending";

            var defaultLanguage = LanguageRepository.DefaultLanguage;
            SelectedLanguage = new LanguageItemViewModel(defaultLanguage.Name, defaultLanguage.Slug);

            GoToLanguages = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm = this.CreateViewModel<LanguagesViewModel>();
                vm.SelectedLanguage = SelectedLanguage;
                vm.WhenAnyValue(x => x.SelectedLanguage).Skip(1)
                    .Subscribe(x => SelectedLanguage = x);
                NavigateTo(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {

                var requests = _times.Select(t =>
                {
                    var language = (SelectedLanguage != null && SelectedLanguage.Slug != null) ? SelectedLanguage.Slug : null;
                    return new { Time = t, Query = trendingRepository.GetTrendingRepositories(t.Slug, language) };
                }).ToArray();

                await Task.WhenAll(requests.Select(x => x.Query));

                Repositories = requests.Select(r =>
                {
                    var transformedRepos = r.Query.Result.Select(x => new RepositoryItemViewModel(x, true, GoToRepository));
                    return new GroupedCollection<RepositoryItemViewModel>(r.Time.Name, new ReactiveList<RepositoryItemViewModel>(transformedRepos));
                }).ToList();
            });

            this.WhenAnyValue(x => x.SelectedLanguage).Skip(1).Subscribe(_ => 
            {
                Repositories = null;
                LoadCommand.ExecuteIfCan();
            });
        }
Пример #3
0
        public RepositoriesTrendingViewModel(ISessionService applicationService, ITrendingRepository trendingRepository)
        {
            ShowRepositoryDescription = applicationService.Account.ShowRepositoryDescriptionInList;

            Title = "Trending";

            var defaultLanguage = LanguageRepository.DefaultLanguage;

            SelectedLanguage = new LanguageItemViewModel(defaultLanguage.Name, defaultLanguage.Slug);

            GoToLanguages = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm = this.CreateViewModel <LanguagesViewModel>();
                vm.SelectedLanguage = SelectedLanguage;
                vm.WhenAnyValue(x => x.SelectedLanguage).Skip(1)
                .Subscribe(x => SelectedLanguage = x);
                NavigateTo(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                var requests = _times.Select(t =>
                {
                    var language = (SelectedLanguage != null && SelectedLanguage.Slug != null) ? SelectedLanguage.Slug : null;
                    return(new { Time = t, Query = trendingRepository.GetTrendingRepositories(t.Slug, language) });
                }).ToArray();

                await Task.WhenAll(requests.Select(x => x.Query));

                Repositories = requests.Select(r =>
                {
                    var transformedRepos = r.Query.Result.Select(x => new RepositoryItemViewModel(x, true, GoToRepository));
                    return(new GroupedCollection <RepositoryItemViewModel>(r.Time.Name, new ReactiveList <RepositoryItemViewModel>(transformedRepos)));
                }).ToList();
            });

            this.WhenAnyValue(x => x.SelectedLanguage).Skip(1).Subscribe(_ =>
            {
                Repositories = null;
                LoadCommand.ExecuteIfCan();
            });
        }