示例#1
0
        public RepositoryItemViewModel(Octokit.Repository repository, bool showOwner, bool showDescription, Action <RepositoryItemViewModel> gotoCommand)
        {
            if (showDescription)
            {
                if (!string.IsNullOrEmpty(repository.Description) && repository.Description.IndexOf(':') >= 0)
                {
                    Description = Emojis.FindAndReplace(repository.Description);
                }
                else
                {
                    Description = repository.Description;
                }
            }
            else
            {
                Description = null;
            }

            Name        = repository.Name;
            Owner       = repository.Owner?.Login ?? string.Empty;
            Avatar      = new GitHubAvatar(repository.Owner?.AvatarUrl);
            Stars       = repository.StargazersCount.ToString();
            Forks       = repository.ForksCount.ToString();
            ShowOwner   = showOwner;
            GoToCommand = ReactiveCommand.Create(() => gotoCommand?.Invoke(this));
        }
示例#2
0
        protected Element CreateElement(RepositoryModel repo)
        {
            var description = ViewModel.ShowRepositoryDescription ? Emojis.FindAndReplace(repo.Description) : string.Empty;
            var avatar      = new GitHubAvatar(repo.Owner?.AvatarUrl);
            var vm          = new WeakReference <RepositoriesViewModel>(ViewModel);
            var sse         = new RepositoryElement(repo.Name, repo.Watchers, repo.Forks, description, repo.Owner.Login, avatar)
            {
                ShowOwner = ViewModel.ShowRepositoryOwner
            };

            sse.Tapped += () => vm.Get()?.GoToRepositoryCommand.Execute(repo);
            return(sse);
        }
示例#3
0
        internal RepositoryItemViewModel(Octokit.Repository repository, bool showOwner, Action <RepositoryItemViewModel> gotoCommand)
        {
            if (!string.IsNullOrEmpty(repository.Description) && repository.Description.IndexOf(':') >= 0)
            {
                Description = Emojis.FindAndReplace(repository.Description);
            }
            else
            {
                Description = repository.Description;
            }

            Repository  = repository;
            Name        = repository.Name;
            Owner       = repository.Owner?.Login ?? string.Empty;
            Avatar      = new GitHubAvatar(repository.Owner?.AvatarUrl);
            Stars       = repository.StargazersCount;
            Forks       = repository.ForksCount;
            ShowOwner   = showOwner;
            GoToCommand = ReactiveCommand.Create().WithSubscription(x => gotoCommand(this));
        }
示例#4
0
        internal CommitItemViewModel(GitHubCommit commit, Action <CommitItemViewModel> action)
        {
            var msg         = commit?.Commit?.Message ?? string.Empty;
            var firstLine   = msg.IndexOf("\n", StringComparison.Ordinal);
            var description = firstLine > 0 ? msg.Substring(0, firstLine) : msg;

            _description = new Lazy <string>(() => Emojis.FindAndReplace(description));

            var time = DateTimeOffset.MinValue;

            if (commit.Commit.Committer != null)
            {
                time = commit.Commit.Committer.Date;
            }
            Time = time.UtcDateTime.Humanize();

            Name        = commit.GenerateCommiterName();
            Avatar      = new GitHubAvatar(commit.GenerateGravatarUrl());
            Commit      = commit;
            GoToCommand = ReactiveCommand.Create().WithSubscription(_ => action(this));
        }
示例#5
0
        public RepositoryItemViewModel(Octokit.Repository repository, bool showOwner, bool showDescription, Action <RepositoryItemViewModel> gotoCommand)
        {
            if (showDescription)
            {
                if (!string.IsNullOrEmpty(repository.Description) && repository.Description.IndexOf(':') >= 0)
                {
                    Description = Emojis.FindAndReplace(repository.Description);
                }
                else
                {
                    Description = repository.Description;
                }
            }
            else
            {
                Description = null;
            }

            Repository  = repository;
            ShowOwner   = showOwner;
            GoToCommand = ReactiveCommand.Create(() => gotoCommand?.Invoke(this));
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = ViewModel.Username;
            HeaderView.SetImage(null, Images.Avatar);
            HeaderView.Text = ViewModel.RepositoryName;
            HeaderView.SubImageView.TintColor = UIColor.FromRGB(243, 156, 18);

            Appeared.Take(1)
            .Select(_ => Observable.Timer(TimeSpan.FromSeconds(0.35f)).Take(1))
            .Switch()
            .Select(_ => ViewModel.Bind(x => x.IsStarred, true).Where(x => x.HasValue))
            .Switch()
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x => HeaderView.SetSubImage(x.Value ? Octicon.Star.ToImage() : null));

            var actionButton = NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action)
            {
                Enabled = false
            };

            _split      = new SplitButtonElement();
            _stargazers = _split.AddButton("Stargazers", "-");
            _watchers   = _split.AddButton("Watchers", "-");
            _forks      = _split.AddButton("Forks", "-");

            OnActivation(d =>
            {
                d(_watchers.Clicked
                  .Select(_ => ViewModel)
                  .Select(x => UsersViewController.CreateWatchersViewController(x.Username, x.RepositoryName))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));

                d(_stargazers.Clicked
                  .Select(_ => ViewModel)
                  .Select(x => UsersViewController.CreateStargazersViewController(x.Username, x.RepositoryName))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));

                d(actionButton.GetClickedObservable().Subscribe(_ => ShowExtraMenu()));

                d(_forks.Clicked.Subscribe(_ =>
                {
                    var vc = RepositoriesViewController.CreateForkedViewController(ViewModel.Username, ViewModel.RepositoryName);
                    NavigationController?.PushViewController(vc, true);
                }));

                d(_eventsElement.Clicked.BindCommand(ViewModel.GoToEventsCommand));
                d(_ownerElement.Clicked.BindCommand(ViewModel.GoToOwnerCommand));

                d(_commitsElement.Clicked.BindCommand(ViewModel.GoToCommitsCommand));
                d(_pullRequestsElement.Clicked.BindCommand(ViewModel.GoToPullRequestsCommand));
                d(_sourceElement.Clicked.BindCommand(ViewModel.GoToSourceCommand));

                d(ViewModel.Bind(x => x.Branches, true).Subscribe(_ => Render()));
                d(ViewModel.Bind(x => x.Readme, true).Subscribe(_ => Render()));

                d(_forkElement.Value.Clicked.Select(x => ViewModel.Repository.Parent).BindCommand(ViewModel.GoToForkParentCommand));
                d(_issuesElement.Value.Clicked.BindCommand(ViewModel.GoToIssuesCommand));
                d(_readmeElement.Value.Clicked.BindCommand(ViewModel.GoToReadmeCommand));
                d(_websiteElement.Value.Clicked.Select(x => ViewModel.Repository.Homepage).BindCommand(ViewModel.GoToUrlCommand));

                d(HeaderView.Clicked.BindCommand(ViewModel.GoToOwnerCommand));

                d(ViewModel.Bind(x => x.Repository, true).Where(x => x != null).Subscribe(x =>
                {
                    if (x.Private && !_featuresService.IsProEnabled)
                    {
                        if (_privateView == null)
                        {
                            _privateView = this.ShowPrivateView();
                        }
                        actionButton.Enabled = false;
                    }
                    else
                    {
                        actionButton.Enabled = true;
                        _privateView?.Dispose();
                    }

                    ViewModel.ImageUrl = x.Owner?.AvatarUrl;
                    HeaderView.SubText = Emojis.FindAndReplace(x.Description);
                    HeaderView.SetImage(x.Owner?.AvatarUrl, Images.Avatar);
                    Render();
                    RefreshHeaderView();
                }));
            });
        }
示例#7
0
        public RepositoryViewModel(ISessionService applicationService,
                                   IAccountsRepository accountsService, IActionMenuFactory actionMenuService)
        {
            ApplicationService = applicationService;
            _accountsService   = accountsService;

            var validRepositoryObservable = this.WhenAnyValue(x => x.Repository).Select(x => x != null);

            this.WhenAnyValue(x => x.RepositoryName).Subscribe(x => Title = x);

            this.WhenAnyValue(x => x.Repository.Owner.AvatarUrl)
            .Select(x => new GitHubAvatar(x))
            .ToProperty(this, x => x.Avatar, out _avatar);

            this.WhenAnyValue(x => x.Repository).Subscribe(x =>
            {
                Stargazers = (int?)x?.StargazersCount;
                Watchers   = (int?)x?.SubscribersCount;
            });

            this.WhenAnyValue(x => x.Repository.Description)
            .Select(x => Emojis.FindAndReplace(x))
            .ToProperty(this, x => x.Description, out _description);

            ToggleStarCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue), t => ToggleStar());

            ToggleWatchCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.IsWatched, x => x.HasValue), t => ToggleWatch());

            GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository).Select(x => x != null));
            GoToOwnerCommand.Select(_ => Repository.Owner).Subscribe(x => {
                if (AccountType.Organization.Equals(x.Type))
                {
                    var vm = this.CreateViewModel <OrganizationViewModel>();
                    vm.Init(RepositoryOwner);
                    NavigateTo(vm);
                }
                else
                {
                    var vm = this.CreateViewModel <UserViewModel>();
                    vm.Init(RepositoryOwner);
                    NavigateTo(vm);
                }
            });

            PinCommand = ReactiveCommand.Create(validRepositoryObservable);
            PinCommand.Subscribe(x => PinRepository());

            GoToForkParentCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && x.Fork && x.Parent != null));
            GoToForkParentCommand.Subscribe(x =>
            {
                var vm             = this.CreateViewModel <RepositoryViewModel>();
                vm.RepositoryOwner = Repository.Parent.Owner.Login;
                vm.RepositoryName  = Repository.Parent.Name;
                vm.Repository      = Repository.Parent;
                NavigateTo(vm);
            });

            GoToStargazersCommand = ReactiveCommand.Create();
            GoToStargazersCommand.Subscribe(_ =>
            {
                var vm = this.CreateViewModel <RepositoryStargazersViewModel>();
                vm.Init(RepositoryOwner, RepositoryName);
                NavigateTo(vm);
            });

            GoToWatchersCommand = ReactiveCommand.Create();
            GoToWatchersCommand.Subscribe(_ =>
            {
                var vm = this.CreateViewModel <RepositoryWatchersViewModel>();
                vm.Init(RepositoryOwner, RepositoryName);
                NavigateTo(vm);
            });

            GoToEventsCommand = ReactiveCommand.Create();
            GoToEventsCommand.Subscribe(_ => {
                var vm = this.CreateViewModel <RepositoryEventsViewModel>();
                vm.Init(RepositoryOwner, RepositoryName);
                NavigateTo(vm);
            });

            GoToIssuesCommand = ReactiveCommand.Create();
            GoToIssuesCommand
            .Select(_ => this.CreateViewModel <IssuesViewModel>())
            .Select(x => x.Init(RepositoryOwner, RepositoryName))
            .Subscribe(NavigateTo);

            GoToReadmeCommand = ReactiveCommand.Create();
            GoToReadmeCommand
            .Select(_ => this.CreateViewModel <ReadmeViewModel>())
            .Select(x => x.Init(RepositoryOwner, RepositoryName))
            .Subscribe(NavigateTo);

            GoToBranchesCommand = ReactiveCommand.Create();
            GoToBranchesCommand
            .Select(_ => this.CreateViewModel <CommitBranchesViewModel>())
            .Select(x => x.Init(RepositoryOwner, RepositoryName))
            .Subscribe(NavigateTo);

            GoToCommitsCommand = ReactiveCommand.Create();
            GoToCommitsCommand.Subscribe(_ =>
            {
                if (Branches != null && Branches.Count == 1)
                {
                    var vm     = this.CreateViewModel <CommitsViewModel>();
                    var branch = Repository == null ? null : Repository.DefaultBranch;
                    NavigateTo(vm.Init(RepositoryOwner, RepositoryName, branch));
                }
                else
                {
                    GoToBranchesCommand.ExecuteIfCan();
                }
            });

            GoToPullRequestsCommand = ReactiveCommand.Create();
            GoToPullRequestsCommand.Subscribe(_ =>
            {
                var vm             = this.CreateViewModel <PullRequestsViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                NavigateTo(vm);
            });

            GoToSourceCommand = ReactiveCommand.Create();
            GoToSourceCommand.Subscribe(_ =>
            {
                var vm             = this.CreateViewModel <BranchesAndTagsViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                NavigateTo(vm);
            });

            GoToContributors = ReactiveCommand.Create();
            GoToContributors.Subscribe(_ =>
            {
                var vm = this.CreateViewModel <RepositoryContributorsViewModel>();
                vm.Init(RepositoryOwner, RepositoryName);
                NavigateTo(vm);
            });

            GoToForksCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm             = this.CreateViewModel <RepositoryForksViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                NavigateTo(vm);
            });

            GoToReleasesCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm             = this.CreateViewModel <ReleasesViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                NavigateTo(vm);
            });

            ShareCommand = ReactiveCommand.Create(validRepositoryObservable);
            ShareCommand.Subscribe(sender => actionMenuService.ShareUrl(sender, Repository.HtmlUrl));

            var canShowMenu = this.WhenAnyValue(x => x.Repository, x => x.IsStarred, x => x.IsWatched)
                              .Select(x => x.Item1 != null && x.Item2 != null && x.Item3 != null);

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(canShowMenu, sender => {
                var menu = actionMenuService.Create();
                menu.AddButton(IsPinned ? "Unpin from Slideout Menu" : "Pin to Slideout Menu", PinCommand);
                menu.AddButton(IsStarred.Value ? "Unstar This Repo" : "Star This Repo", ToggleStarCommand);
                menu.AddButton(IsWatched.Value ? "Unwatch This Repo" : "Watch This Repo", ToggleWatchCommand);
                menu.AddButton("Show in GitHub", GoToHtmlUrlCommand);
                menu.AddButton("Share", ShareCommand);
                return(menu.Show(sender));
            });

            var gotoWebUrl = new Action <string>(x =>
            {
                var vm = this.CreateViewModel <WebBrowserViewModel>();
                vm.Init(x);
                NavigateTo(vm);
            });

            GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && !string.IsNullOrEmpty(x.HtmlUrl)));
            GoToHtmlUrlCommand.Select(_ => Repository.HtmlUrl).Subscribe(gotoWebUrl);

            GoToHomepageCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && !string.IsNullOrEmpty(x.Homepage)));
            GoToHomepageCommand.Select(_ => Repository.Homepage).Subscribe(gotoWebUrl);

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                var t1 = applicationService.GitHubClient.Repository.Get(RepositoryOwner, RepositoryName);

                applicationService.GitHubClient.Repository.Content.GetReadme(RepositoryOwner, RepositoryName)
                .ToBackground(x => Readme = x);

                applicationService.GitHubClient.Repository.GetAllBranches(RepositoryOwner, RepositoryName)
                .ToBackground(x => Branches = x);

                applicationService.GitHubClient.Activity.Watching.CheckWatched(RepositoryOwner, RepositoryName)
                .ToBackground(x => IsWatched = x);

                applicationService.GitHubClient.Activity.Starring.CheckStarred(RepositoryOwner, RepositoryName)
                .ToBackground(x => IsStarred = x);

                applicationService.Client.ExecuteAsync(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetContributors())
                .ToBackground(x => Contributors = x.Data.Count);

//                applicationService.GitHubClient.Repository.GetAllLanguages(RepositoryOwner, RepositoryName)
//                    .ToBackground(x => Languages = x.Count);

                applicationService.Client.ExecuteAsync(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetReleases())
                .ToBackground(x => Releases = x.Data.Count);

                Repository = await t1;
            });
        }
示例#8
0
        public CommitViewModel(ISessionService applicationService, IActionMenuFactory actionMenuService, IAlertDialogFactory alertDialogFactory)
        {
            Title = "Commit";

            var comments = new ReactiveList <CommentModel>();

            Comments = comments.CreateDerivedCollection(x => new CommitCommentItemViewModel(x));

            this.WhenAnyValue(x => x.Commit)
            .Select(x => new GitHubAvatar(x.GenerateGravatarUrl()))
            .ToProperty(this, x => x.Avatar, out _avatar);

            var files = this.WhenAnyValue(x => x.Commit.Files).IsNotNull();

            files.Select(x => x.Count(y => string.Equals(y.Status, "added")))
            .ToProperty(this, x => x.DiffAdditions, out _diffAdditions);

            files.Select(x => x.Count(y => string.Equals(y.Status, "removed")))
            .ToProperty(this, x => x.DiffDeletions, out _diffDeletions);

            files.Select(x => x.Count(y => string.Equals(y.Status, "modified")))
            .ToProperty(this, x => x.DiffModifications, out _diffModifications);

            GoToAddedFiles = ReactiveCommand.Create(this.WhenAnyValue(x => x.DiffAdditions).Select(x => x > 0));
            GoToAddedFiles
            .Select(_ => new CommitFilesViewModel())
            .Select(y => y.Init(RepositoryOwner, RepositoryName, Node, "Added", Commit.Files.Where(x => string.Equals(x.Status, "added"))))
            .Subscribe(NavigateTo);

            GoToRemovedFiles = ReactiveCommand.Create(this.WhenAnyValue(x => x.DiffDeletions).Select(x => x > 0));
            GoToRemovedFiles
            .Select(_ => new CommitFilesViewModel())
            .Select(y => y.Init(RepositoryOwner, RepositoryName, Node, "Removed", Commit.Files.Where(x => string.Equals(x.Status, "removed"))))
            .Subscribe(NavigateTo);

            GoToModifiedFiles = ReactiveCommand.Create(this.WhenAnyValue(x => x.DiffModifications).Select(x => x > 0));
            GoToModifiedFiles
            .Select(_ => new CommitFilesViewModel())
            .Select(y => y.Init(RepositoryOwner, RepositoryName, Node, "Modified", Commit.Files.Where(x => string.Equals(x.Status, "modified"))))
            .Subscribe(NavigateTo);

            GoToAllFiles = ReactiveCommand.Create(this.WhenAnyValue(x => x.Commit.Files).Select(x => x != null));
            GoToAllFiles
            .Select(_ => new CommitFilesViewModel())
            .Select(y => y.Init(RepositoryOwner, RepositoryName, Node, "All Changes", Commit.Files))
            .Subscribe(NavigateTo);

            this.WhenAnyValue(x => x.Commit)
            .IsNotNull()
            .Select(x => x.GenerateCommiterName())
            .ToProperty(this, x => x.CommiterName, out _commiterName);

            this.WhenAnyValue(x => x.Commit)
            .IsNotNull()
            .Select(x => x.Commit.Message ?? string.Empty)
            .Select(x => Emojis.FindAndReplace(x))
            .ToProperty(this, x => x.CommitMessage, out _commitMessage);

            this.WhenAnyValue(x => x.CommitMessage)
            .IsNotNull()
            .Select(x => {
                var firstNewLine = x.IndexOf("\n", StringComparison.Ordinal);
                return(firstNewLine > 0 ? x.Substring(0, firstNewLine) : x);
            })
            .ToProperty(this, x => x.CommitMessageSummary, out _commitMessageSummary);

            GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Commit).Select(x => x != null));
            GoToHtmlUrlCommand
            .Select(_ => this.CreateViewModel <WebBrowserViewModel>())
            .Select(x => x.Init(Commit.HtmlUrl))
            .Subscribe(NavigateTo);

            GoToRepositoryCommand = ReactiveCommand.Create();
            GoToRepositoryCommand.Subscribe(_ => {
                var vm = this.CreateViewModel <RepositoryViewModel>();
                vm.Init(RepositoryOwner, RepositoryName);
                NavigateTo(vm);
            });

            AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => {
                var vm = new ComposerViewModel(async s => {
                    var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Commits[Node].Comments.Create(s);
                    comments.Add((await applicationService.Client.ExecuteAsync(request)).Data);
                }, alertDialogFactory);
                NavigateTo(vm);
            });

            var validCommitObservable = this.WhenAnyValue(x => x.Commit).Select(x => x != null);

            var copyShaCommand = ReactiveCommand.Create(validCommitObservable)
                                 .WithSubscription(x => actionMenuService.SendToPasteBoard(this.Commit.Sha));

            var shareCommand = ReactiveCommand.Create(validCommitObservable)
                               .WithSubscription(sender => actionMenuService.ShareUrl(sender, this.Commit.HtmlUrl));

            var browseCodeCommand = ReactiveCommand.Create(validCommitObservable)
                                    .WithSubscription(x =>
            {
                var vm             = this.CreateViewModel <SourceTreeViewModel>();
                vm.RepositoryName  = RepositoryName;
                vm.RepositoryOwner = RepositoryOwner;
                vm.Branch          = this.Commit.Sha;
                NavigateTo(vm);
            });

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(sender => {
                var menu = actionMenuService.Create();
                menu.AddButton("Add Comment", AddCommentCommand);
                menu.AddButton("Copy SHA", copyShaCommand);
                menu.AddButton("Browse Code", browseCodeCommand);
                menu.AddButton("Share", shareCommand);
                menu.AddButton("Show in GitHub", GoToHtmlUrlCommand);
                return(menu.Show(sender));
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t => {
                var commentRequest = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Commits[Node].Comments.GetAll();
                applicationService.Client.ExecuteAsync(commentRequest).ToBackground(x => comments.Reset(x.Data.Where(y => y.Position.HasValue)));
                Commit = await applicationService.GitHubClient.Repository.Commits.Get(RepositoryOwner, RepositoryName, Node);
            });
        }