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, IJsonHttpClientService jsonHttpClient) { _applicationService = applicationService; _jsonHttpClient = jsonHttpClient; Languages = new ReactiveList <LanguageModel>(); Repositories = new ReactiveList <RepositoryModel>(); GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.OfType <RepositoryModel>().Subscribe(x => { var vm = CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = x.Owner; vm.RepositoryName = x.Name; ShowViewModel(vm); }); SelectedTime = Times[0]; SelectedLanguage = _defaultLanguage; GetLanguages().FireAndForget(); this.WhenAnyValue(x => x.SelectedTime, x => x.SelectedLanguage, (x, y) => Unit.Default) .Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan()); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var query = "?"; if (SelectedLanguage != null && SelectedLanguage.Slug != null) { query += string.Format("language={0}&", SelectedLanguage.Slug); } if (SelectedTime != null && SelectedTime.Slug != null) { query += string.Format("since={0}", SelectedTime.Slug); } var repos = await _jsonHttpClient.Get <List <RepositoryModel> >(TrendingUrl + query); Repositories.Reset(repos); }); }
public RepositoriesTrendingViewModel(IApplicationService applicationService, IJsonHttpClientService jsonHttpClient) { _applicationService = applicationService; _jsonHttpClient = jsonHttpClient; Languages = new ReactiveList<LanguageModel>(); Repositories = new ReactiveCollection<RepositoryModel>(); GoToRepositoryCommand = new ReactiveCommand(); GoToRepositoryCommand.OfType<RepositoryModel>().Subscribe(x => { var vm = CreateViewModel<RepositoryViewModel>(); vm.RepositoryOwner = x.Owner; vm.RepositoryName = x.Name; ShowViewModel(vm); }); SelectedTime = Times[0]; SelectedLanguage = _defaultLanguage; GetLanguages().FireAndForget(); this.WhenAnyValue(x => x.SelectedTime, x => x.SelectedLanguage, (x, y) => Unit.Default) .Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan()); LoadCommand.RegisterAsyncTask(async t => { var query = "?"; if (SelectedLanguage != null && SelectedLanguage.Slug != null) query += string.Format("language={0}&", SelectedLanguage.Slug); if (SelectedTime != null && SelectedTime.Slug != null) query += string.Format("since={0}", SelectedTime.Slug); var repos = await _jsonHttpClient.Get<List<RepositoryModel>>(TrendingUrl + query); Repositories.Reset(repos); }); }