public RepositoriesTrendingViewModel(IApplicationService applicationService,
                                             IJsonHttpClientService jsonHttpClient, INetworkActivityService networkActivityService)
        {
            _applicationService = applicationService;
            _jsonHttpClient     = jsonHttpClient;

            Title = "Trending";

            var defaultLanguage = LanguagesViewModel.DefaultLanguage;

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

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

            var gotoRepository = new Action <RepositoryItemViewModel>(x =>
            {
                var vm             = CreateViewModel <RepositoryViewModel>();
                vm.RepositoryOwner = x.Owner;
                vm.RepositoryName  = x.Name;
                ShowViewModel(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                var requests = _times.Select(t =>
                {
                    var query = "?since=" + t.Slug;
                    if (SelectedLanguage != null && SelectedLanguage.Slug != null)
                    {
                        query += string.Format("&language={0}", SelectedLanguage.Slug);
                    }
                    return(new { Time = t, Query = _jsonHttpClient.Get <List <TrendingRepositoryModel> >(TrendingUrl + query) });
                }).ToArray();

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

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

            LoadCommand.TriggerNetworkActivity(networkActivityService);
            this.WhenAnyValue(x => x.SelectedLanguage).Subscribe(_ => LoadCommand.ExecuteIfCan());
        }
        public RepositoriesTrendingViewModel(IApplicationService applicationService, 
            IJsonHttpClientService jsonHttpClient, INetworkActivityService networkActivityService)
        {
            _applicationService = applicationService;
            _jsonHttpClient = jsonHttpClient;

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

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

            var gotoRepository = new Action<RepositoryItemViewModel>(x =>
            {
                var vm = CreateViewModel<RepositoryViewModel>();
                vm.RepositoryOwner = x.Owner;
                vm.RepositoryName = x.Name;
                ShowViewModel(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                var requests = _times.Select(t =>
                {
                    var query = "?since=" + t.Slug;
                    if (SelectedLanguage != null && SelectedLanguage.Slug != null)
                        query += string.Format("&language={0}", SelectedLanguage.Slug);
                    return new { Time = t, Query = _jsonHttpClient.Get<List<TrendingRepositoryModel>>(TrendingUrl + query) };
                }).ToArray();

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

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

            LoadCommand.TriggerNetworkActivity(networkActivityService);
            this.WhenAnyValue(x => x.SelectedLanguage).Subscribe(_ => LoadCommand.ExecuteIfCan());
        }
        public RepositoriesTrendingViewModel(IApplicationService applicationService, TrendingRepository trendingRepository)
        {
            ShowRepositoryDescription = applicationService.Account.ShowRepositoryDescriptionInList;

            Title = "Trending";

            var defaultLanguage = LanguageRepository.DefaultLanguage;

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

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

            var gotoRepository = new Action <RepositoryItemViewModel>(x =>
            {
                var vm             = CreateViewModel <RepositoryViewModel>();
                vm.RepositoryOwner = x.Owner;
                vm.RepositoryName  = x.Name;
                ShowViewModel(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                Repositories = null;

                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.Name, x.Owner.Login, x.Owner.AvatarUrl, x.Description, x.StargazersCount, x.ForksCount, true, gotoRepository));
                    return(new GroupedCollection <RepositoryItemViewModel>(r.Time.Name, new ReactiveList <RepositoryItemViewModel>(transformedRepos)));
                }).ToList();
            });

            this.WhenAnyValue(x => x.SelectedLanguage).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan());
        }
        public RepositoriesTrendingViewModel(ISessionService applicationService)
        {
            ShowRepositoryDescription = applicationService.Account.ShowRepositoryDescriptionInList;
            var trendingRepository = new TrendingRepository();

            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);
            });

            var gotoRepository = new Action<RepositoryItemViewModel>(x =>
            {
                var vm = this.CreateViewModel<RepositoryViewModel>();
                vm.RepositoryOwner = x.Owner;
                vm.RepositoryName = x.Name;
                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.Name, x.Owner.Login, x.Owner.AvatarUrl, x.Description, x.StargazersCount, x.ForksCount, 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();
            });
        }
Exemple #5
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();
            });
        }