public ShowcaseViewModel(INetworkActivityService networkActivity, ShowcaseRepository showcaseRepository) { Title = "Showcase"; GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.OfType <Octokit.Repository>().Subscribe(x => { var vm = CreateViewModel <RepositoryViewModel>(); vm.RepositoryIdentifier = new BaseRepositoryViewModel.RepositoryIdentifierModel(x.Owner.Login, x.Name); ShowViewModel(vm); }); var repositories = new ReactiveList <Octokit.Repository>(); Repositories = repositories; LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var showcaseRepos = await showcaseRepository.GetShowcaseRepositories(ShowcaseSlug); Title = showcaseRepos.Name; Showcase = new Showcase { Slug = showcaseRepos.Slug, Description = showcaseRepos.Description, Name = showcaseRepos.Name }; repositories.Reset(showcaseRepos.Repositories); }); LoadCommand.TriggerNetworkActivity(networkActivity); }
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 TrendingViewModel(INetworkActivityService networkActivity, TrendingRepository trendingRepository) { SelectedLanguage = _defaultLanguage; var repositories = new ReactiveList <TrendingRepositoryViewModel>(); Repositories = repositories.CreateDerivedCollection(x => x); GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.OfType <Octokit.Repository>().Subscribe(x => { var vm = CreateViewModel <RepositoryViewModel>(); vm.RepositoryIdentifier = new BaseRepositoryViewModel.RepositoryIdentifierModel(x.Owner.Login, x.Name); ShowViewModel(vm); }); GoToLanguages = ReactiveCommand.Create(); GoToLanguages.Subscribe(_ => { var vm = CreateViewModel <LanguagesViewModel>(); vm.ExtraLanguages.Add(_defaultLanguage); vm.SelectedLanguage = SelectedLanguage; vm.WhenAnyValue(x => x.SelectedLanguage).Skip(1).Subscribe(x => { SelectedLanguage = x; vm.DismissCommand.ExecuteIfCan(); }); ShowViewModel(vm); }); this.WhenAnyValue(x => x.SelectedLanguage).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan()); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { var tempRepos = new List <TrendingRepositoryViewModel>(); foreach (var t in _times) { var language = SelectedLanguage == null ? null : SelectedLanguage.Slug; var repos = await trendingRepository.GetTrendingRepositories(t.Slug, language); tempRepos.AddRange(repos.Select(x => new TrendingRepositoryViewModel { Repository = x, Time = t.Name })); } repositories.Reset(tempRepos); }); LoadCommand.TriggerNetworkActivity(networkActivity); }
public ShowcasesViewModel(INetworkActivityService networkActivity, ShowcaseRepository showcaseRepository) { GoToShowcaseCommand = ReactiveCommand.Create(); GoToShowcaseCommand.OfType <Showcase>().Subscribe(x => { var vm = CreateViewModel <ShowcaseViewModel>(); vm.ShowcaseSlug = x.Slug; vm.Title = x.Name; ShowViewModel(vm); }); var showcases = new ReactiveList <Showcase>(); Showcases = showcases; LoadCommand = ReactiveCommand.CreateAsyncTask(async t => showcases.Reset(await showcaseRepository.GetShowcases())); LoadCommand.TriggerNetworkActivity(networkActivity); }
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()); }
protected BaseRepositoryViewModel(IApplicationService applicationService, INetworkActivityService networkActivity) { LikeCommand = ReactiveCommand.Create(); LikeCommand.Subscribe(_ => { if (StumbledRepository == null) { var repo = CreateStumbledRepository(); repo.Liked = true; applicationService.Account.StumbledRepositories.Insert(repo); StumbledRepository = repo; } else { StumbledRepository.Liked = true; StumbledRepository.Description = Repository.Description; StumbledRepository.Forks = Repository.ForksCount; StumbledRepository.Stars = Repository.WatchersCount; StumbledRepository.ImageUrl = Repository.Owner.AvatarUrl; applicationService.Account.StumbledRepositories.Update(StumbledRepository); } if (applicationService.Account.SyncWithGitHub) { applicationService.Client.Activity.Starring.StarRepo(Repository.Owner.Login, Repository.Name); } Liked = true; }); DislikeCommand = ReactiveCommand.Create(); DislikeCommand.Subscribe(_ => { if (StumbledRepository == null) { var repo = CreateStumbledRepository(); repo.Liked = false; applicationService.Account.StumbledRepositories.Insert(repo); StumbledRepository = repo; } else { StumbledRepository.Liked = false; StumbledRepository.Description = Repository.Description; StumbledRepository.Forks = Repository.ForksCount; StumbledRepository.Stars = Repository.WatchersCount; StumbledRepository.ImageUrl = Repository.Owner.AvatarUrl; applicationService.Account.StumbledRepositories.Update(StumbledRepository); } if (applicationService.Account.SyncWithGitHub) { applicationService.Client.Activity.Starring.RemoveStarFromRepo(Repository.Owner.Login, Repository.Name); } Liked = false; }); this.WhenAnyValue(x => x.RepositoryIdentifier) .Where(x => x != null) .Subscribe(x => { StumbledRepository = applicationService.Account.StumbledRepositories.FindByFullname(x.Owner, x.Name); }); this.WhenAnyValue(x => x.StumbledRepository) .Where(x => x != null) .Subscribe(x => Liked = x.Liked); GoToGitHubCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository).Select(x => x != null)); GoToGitHubCommand.Subscribe(_ => GoToUrlCommand.ExecuteIfCan(Repository.HtmlUrl)); LoadCommand = ReactiveCommand.CreateAsyncTask(this.WhenAnyValue(x => x.RepositoryIdentifier).Select(x => x != null), async t => { Repository = (await applicationService.Client.Repository.Get(RepositoryIdentifier.Owner, RepositoryIdentifier.Name)); ContributorCount = (await applicationService.Client.Repository.GetAllContributors(RepositoryIdentifier.Owner, RepositoryIdentifier.Name)).Count; try { Readme = await applicationService.Client.Repository.GetReadmeHtml(RepositoryIdentifier.Owner, RepositoryIdentifier.Name); } catch (Exception e) { Readme = "<center>There is no readme for this repository :(</center>"; Debug.WriteLine(e.Message + " for " + RepositoryIdentifier.Owner + "/" + RepositoryIdentifier.Name); } }); LoadCommand.TriggerNetworkActivity(networkActivity); }