public PullRequestsViewModel(ISessionService sessionService) { _sessionService = sessionService; Title = "Pull Requests"; PullRequests = _pullRequests.CreateDerivedCollection(x => { var vm = new PullRequestItemViewModel(x); vm.GoToCommand.Subscribe(_ => { var prViewModel = this.CreateViewModel <PullRequestViewModel>(); prViewModel.Init(RepositoryOwner, RepositoryName, x.Number, x); NavigateTo(prViewModel); prViewModel.WhenAnyValue(y => y.Issue.State) .DistinctUntilChanged() .Skip(1) .Subscribe(y => LoadCommand.ExecuteIfCan()); }); return(vm); }, filter: x => x.Title.ContainsKeyword(SearchKeyword), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { _pullRequests.Reset(await RetrievePullRequests()); }); this.WhenAnyValue(x => x.SelectedFilter).Skip(1).Subscribe(_ => { _pullRequests.Clear(); LoadCommand.ExecuteIfCan(); }); }
internal CommitFilesViewModel Init(string repoOwner, string repoName, string commitSha, string title, IEnumerable <Octokit.GitHubCommitFile> files) { Title = title; RepositoryOwner = repoOwner; RepositoryName = repoName; CommitSha = commitSha; _files.Reset(files); return(this); }
protected BaseIssuesViewModel(ISessionService sessionService) { _sessionService = sessionService; Issues = IssuesBacking.CreateDerivedCollection( x => CreateItemViewModel(x), filter: IssueFilter, signalReset: this.WhenAnyValue(x => x.SearchKeyword)); Issues.Changed.Subscribe(_ => { GroupedIssues = Issues.GroupBy(x => x.RepositoryFullName) .Select(x => new IssueGroupViewModel(x.Key, x)).ToList(); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { IssuesBacking.Reset(await RetrieveIssues()); }); }
public PublicGistsViewModel(ISessionService sessionService) { _sessionService = sessionService; Title = "Public Gists"; Gists = _gists.CreateDerivedCollection(x => CreateGistItemViewModel(x)); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { _gists.Reset(await RetrieveGists()); }); }
protected BaseCommitsViewModel(ISessionService sessionService) { SessionService = sessionService; Title = "Commits"; Commits = _commits.CreateDerivedCollection( x => x, x => x.Description.ContainsKeyword(SearchKeyword) || x.Name.ContainsKeyword(SearchKeyword), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var ret = await RetrieveCommits(); _commits.Reset(ret.Select(x => new CommitItemViewModel(x, GoToCommit))); }); }
public static async Task SimpleCollectionLoad <T>(this IReactiveList <T> viewModel, GitHubRequest <List <T> > request, Action <Func <Task> > assignMore = null) where T : new() { if (assignMore == null) { assignMore = (x) => {} } ; var application = Locator.Current.GetService <ISessionService>(); var response = await application.Client.ExecuteAsync(request); viewModel.CreateMore(response, assignMore, x => viewModel.AddRange(x)); viewModel.Reset(response.Data); } }
public static Task SimpleCollectionLoad <T>(this IReactiveList <T> viewModel, GitHubRequest <List <T> > request, bool?forceDataRefresh, Action <Func <Task> > assignMore = null) where T : new() { if (assignMore == null) { assignMore = (x) => {} } ; return(viewModel.RequestModel(request, forceDataRefresh, response => { viewModel.CreateMore(response, assignMore, x => { // This is f*****g broken for iOS because it can't handle estimated rows and the insertions // that ReactiveUI seems to be producing using (viewModel.SuppressChangeNotifications()) { viewModel.AddRange(x); } }); viewModel.Reset(response.Data); })); } }
public ProfileViewModel(IApplicationService applicationService, INetworkActivityService networkActivity, IFeaturesService featuresService) { StumbleHistory = new ReactiveList <StumbledRepository>(); GoToInterestsCommand = ReactiveCommand.Create(); Username = applicationService.Account.Username; Action updateStumbled = () => { var stumbledRepositories = applicationService.Account.StumbledRepositories.Count(); Interests = applicationService.Account.Interests.Count(); Likes = applicationService.Account.StumbledRepositories.LikedRepositories(); Dislikes = applicationService.Account.StumbledRepositories.DislikedRepositories(); HasMoreHistory = stumbledRepositories > 30; if (stumbledRepositories != StumbledRepositories) { StumbledRepositories = stumbledRepositories; StumbleHistory.Reset(applicationService.Account.StumbledRepositories.Query.OrderByDescending(x => x.CreatedAt).Take(30)); } }; this.WhenActivated(d => { if (applicationService.Account != null) { updateStumbled(); d(applicationService.RepositoryAdded .Buffer(TimeSpan.FromSeconds(5)) .Where(x => x.Count > 0) .ObserveOn(SynchronizationContext.Current) .Subscribe(x => updateStumbled())); } CanPurchase = !featuresService.ProEditionEnabled; }); GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.OfType <StumbledRepository>().Subscribe(x => { var vm = CreateViewModel <RepositoryViewModel>(); vm.RepositoryIdentifier = new BaseRepositoryViewModel.RepositoryIdentifierModel(x.Owner, x.Name); ShowViewModel(vm); }); GoToPurchaseCommand = ReactiveCommand.Create(); GoToPurchaseCommand.Subscribe(_ => CreateAndShowViewModel <PurchaseProViewModel>()); GoToHistoryCommand = ReactiveCommand.Create(); GoToHistoryCommand.Subscribe(_ => CreateAndShowViewModel <HistoryViewModel>()); GoToLikesCommand = ReactiveCommand.Create(); GoToLikesCommand.Subscribe(_ => CreateAndShowViewModel <LikedRepositoriesViewModel>()); GoToDislikesCommand = ReactiveCommand.Create(); GoToDislikesCommand.Subscribe(_ => CreateAndShowViewModel <DislikedRepositoriesViewModel>()); GoToSettingsCommand = ReactiveCommand.Create(); GoToSettingsCommand.Subscribe(_ => CreateAndShowViewModel <SettingsViewModel>()); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { User = await applicationService.Client.User.Current(); }); LoadCommand.TriggerNetworkActivity(networkActivity); }