Exemplo n.º 1
0
        public GistView()
        {
            HeaderView.Image = Images.LoginUserUnknown;
            HeaderView.SubImageView.TintColor = UIColor.FromRGB(243, 156, 18);

            this.WhenAnyValue(x => x.ViewModel.ShowMenuCommand)
            .Select(x => x.ToBarButtonItem(UIBarButtonSystemItem.Action))
            .Subscribe(x => NavigationItem.RightBarButtonItem = x);

            this.WhenAnyValue(x => x.ViewModel.GoToOwnerCommand)
            .Select(x => x != null ? new Action(() => ViewModel.GoToOwnerCommand.ExecuteIfCan()) : null)
            .Subscribe(x => HeaderView.ImageButtonAction = x);

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

            _splitRow1         = new SplitViewElement();
            _splitRow1.Button1 = new SplitViewElement.SplitButton(Octicon.Lock.ToImage(), string.Empty);
            _splitRow1.Button2 = new SplitViewElement.SplitButton(Octicon.Package.ToImage(), string.Empty);

            _splitRow2         = new SplitViewElement();
            _splitRow2.Button1 = new SplitViewElement.SplitButton(Octicon.Pencil.ToImage(), string.Empty);
            _splitRow2.Button2 = new SplitViewElement.SplitButton(Octicon.Star.ToImage(), string.Empty, () => ViewModel.ToggleStarCommand.ExecuteIfCan());

            _ownerElement = new StringElement("Owner", string.Empty)
            {
                Image          = Octicon.Person.ToImage(),
                ImageTintColor = Theme.PrimaryNavigationBarColor
            };

            this.WhenAnyValue(x => x.ViewModel.IsStarred)
            .Where(x => x.HasValue)
            .Select(x => x.Value ? "Starred!" : "Unstarred")
            .Subscribe(x => _splitRow2.Button2.Text = x);

            this.WhenAnyValue(x => x.ViewModel.Gist)
            .IsNotNull()
            .SubscribeSafe(x =>
            {
                var publicGist    = x.Public.HasValue && x.Public.Value;
                var revisionCount = x.History == null ? 0 : x.History.Count;

                _splitRow1.Button1.Text = publicGist ? "Public" : "Private";
                _splitRow1.Button2.Text = revisionCount + " Revisions";

                var delta = DateTimeOffset.UtcNow.UtcDateTime - x.UpdatedAt.UtcDateTime;
                if (delta.Days <= 0)
                {
                    _splitRow2.Button1.Text = "Created Today";
                }
                else
                {
                    _splitRow2.Button1.Text = string.Format("{0} Days Old", delta.Days);
                }
            });
        }
Exemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.Image = Images.LoginUserUnknown;

            _sourceSection = new Section
            {
                new StringElement("Commits", () => ViewModel.GoToCommitsCommand.ExecuteIfCan(), Octicon.GitCommit.ToImage()),
                new StringElement("Pull Requests", () => ViewModel.GoToPullRequestsCommand.ExecuteIfCan(), Octicon.GitPullRequest.ToImage()),
                new StringElement("Source", () => ViewModel.GoToSourceCommand.ExecuteIfCan(), Octicon.Code.ToImage()),
            };

            _ownerElement = new StringElement("Owner", string.Empty)
            {
                Image = Octicon.Person.ToImage()
            };
            _ownerElement.Tapped += () => ViewModel.GoToOwnerCommand.ExecuteIfCan();
            this.WhenAnyValue(x => x.ViewModel.Repository)
            .Subscribe(x => _ownerElement.Value = x == null ? string.Empty : x.Owner.Login);

            HeaderView.SubImageView.TintColor = UIColor.FromRGB(243, 156, 18);
            this.WhenAnyValue(x => x.ViewModel.GoToOwnerCommand).Subscribe(x =>
                                                                           HeaderView.ImageButtonAction = x != null ? new Action(() => ViewModel.GoToOwnerCommand.ExecuteIfCan()) : null);

            _splitElements[0]         = new SplitViewElement();
            _splitElements[0].Button1 = new SplitViewElement.SplitButton(Octicon.Lock.ToImage(), string.Empty);
            _splitElements[0].Button2 = new SplitViewElement.SplitButton(Octicon.Package.ToImage(), string.Empty);

            _splitElements[1]         = new SplitViewElement();
            _splitElements[1].Button1 = new SplitViewElement.SplitButton(Octicon.IssueOpened.ToImage(), string.Empty, () => ViewModel.GoToIssuesCommand.ExecuteIfCan());
            _splitElements[1].Button2 = new SplitViewElement.SplitButton(Octicon.Organization.ToImage(), string.Empty, () => ViewModel.GoToContributors.ExecuteIfCan());

            _splitElements[2]         = new SplitViewElement();
            _splitElements[2].Button1 = new SplitViewElement.SplitButton(Octicon.Tag.ToImage(), string.Empty, () => ViewModel.GoToReleasesCommand.ExecuteIfCan());
            _splitElements[2].Button2 = new SplitViewElement.SplitButton(Octicon.GitBranch.ToImage(), string.Empty, () => ViewModel.GoToBranchesCommand.ExecuteIfCan());

            var stargazers = _split.AddButton("Stargazers", "-", () => ViewModel.GoToStargazersCommand.ExecuteIfCan());
            var watchers   = _split.AddButton("Watchers", "-", () => ViewModel.GoToWatchersCommand.ExecuteIfCan());
            var forks      = _split.AddButton("Forks", "-", () => ViewModel.GoToForksCommand.ExecuteIfCan());

            this.WhenAnyValue(x => x.ViewModel.Stargazers)
            .Select(x => x != null ? x.ToString() : "-")
            .Subscribe(x => stargazers.Text = x);

            this.WhenAnyValue(x => x.ViewModel.Watchers)
            .Select(x => x != null ? x.ToString() : "-")
            .Subscribe(x => watchers.Text = x);

            this.WhenAnyValue(x => x.ViewModel.Repository.ForksCount)
            .Subscribe(x => forks.Text = x.ToString());

            this.WhenAnyValue(x => x.ViewModel.Repository)
            .IsNotNull()
            .Subscribe(x =>
            {
                _splitElements[0].Button1.Text = x.Private ? "Private" : "Public";
                _splitElements[0].Button2.Text = x.Language ?? "N/A";
                _splitElements[1].Button1.Text = x.OpenIssuesCount + (x.OpenIssuesCount == 1 ? " Issue" : " Issues");
            });

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

            this.WhenAnyValue(x => x.ViewModel.RepositoryName)
            .Subscribe(x => HeaderView.Text = x);

            this.WhenAnyValue(x => x.ViewModel.ShowMenuCommand)
            .Select(x => x.ToBarButtonItem(UIBarButtonSystemItem.Action))
            .Subscribe(x => NavigationItem.RightBarButtonItem = x);

            this.WhenAnyValue(x => x.ViewModel.Branches)
            .Select(x => x == null ? "- Branches" : (x.Count >= 100 ? "100+" : x.Count.ToString()) + (x.Count == 1 ? " Branch" : " Branches"))
            .SubscribeSafe(x => _splitElements[2].Button2.Text = x);

            this.WhenAnyValue(x => x.ViewModel.Contributors)
            .Select(x => x == null ? "- Contributors" : (x >= 100 ? "100+" : x.ToString()) + (x == 1 ? " Contributor" : " Contributors"))
            .SubscribeSafe(x => _splitElements[1].Button2.Text = x);

            this.WhenAnyValue(x => x.ViewModel.Releases)
            .Select(x => x == null ? "- Releases" : (x >= 100 ? "100+" : x.ToString()) + (x == 1 ? " Release" : " Releases"))
            .SubscribeSafe(x => _splitElements[2].Button1.Text = x);

            this.WhenAnyValue(x => x.ViewModel.Description)
            .Subscribe(x => {
                HeaderView.SubText = x;
                RefreshHeaderView();
            });

            this.WhenAnyValue(x => x.ViewModel.Avatar)
            .Subscribe(x => HeaderView.SetImage(x?.ToUri(128), Images.LoginUserUnknown));

            this.WhenAnyValue(x => x.ViewModel.Repository)
            .IsNotNull()
            .Subscribe(_ => Render());

            this.WhenAnyValue(x => x.ViewModel.Readme)
            .Where(x => x != null && ViewModel.Repository != null)
            .Subscribe(_ => Render());
        }
Exemplo n.º 3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Gist";

            var editButton = NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action);

            HeaderView.SetImage(null, Images.Avatar);
            HeaderView.Text = "Gist #" + ViewModel.Id;
            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))
            .Switch()
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x => HeaderView.SetSubImage(x ? Octicon.Star.ToImage() : null));

            TableView.RowHeight          = UITableView.AutomaticDimension;
            TableView.EstimatedRowHeight = 44f;

            _split = new SplitButtonElement();
            var files    = _split.AddButton("Files", "-");
            var comments = _split.AddButton("Comments", "-");
            var forks    = _split.AddButton("Forks", "-");

            _splitRow1    = new SplitViewElement(Octicon.Lock.ToImage(), Octicon.Package.ToImage());
            _splitRow2    = new SplitViewElement(Octicon.Calendar.ToImage(), Octicon.Star.ToImage());
            _ownerElement = new StringElement("Owner", string.Empty, UITableViewCellStyle.Value1)
            {
                Image     = Octicon.Person.ToImage(),
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };

            OnActivation(d =>
            {
                d(editButton.GetClickedObservable().Subscribe(_ => ShareButtonTap(editButton)));
                d(_ownerElement.Clicked.BindCommand(ViewModel.GoToUserCommand));

                d(ViewModel.Bind(x => x.IsStarred, true).Subscribe(isStarred => _splitRow2.Button2.Text = isStarred ? "Starred" : "Not Starred"));

                d(ViewModel.BindCollection(x => x.Comments, true).Subscribe(_ => RenderGist()));
                d(HeaderView.Clicked.BindCommand(ViewModel.GoToUserCommand));

                d(ViewModel.Bind(x => x.Gist, true).Where(x => x != null).Subscribe(gist =>
                {
                    var daysOld = gist.CreatedAt.TotalDaysAgo();

                    _splitRow1.Button1.Text = gist.Public ? "Public" : "Private";
                    _splitRow1.Button2.Text = (gist.History?.Count ?? 0) + " Revisions";
                    _splitRow2.Button1.Text = daysOld == 0 ? "Created today" : "day".ToQuantity(daysOld) + " old";
                    _ownerElement.Value     = gist.Owner?.Login ?? "Unknown";
                    files.Text         = gist.Files?.Count.ToString() ?? "-";
                    comments.Text      = gist.Comments.ToString();
                    forks.Text         = gist.Forks?.Count.ToString() ?? "-";
                    HeaderView.SubText = gist.Description;
                    HeaderView.Text    = gist.Files?.Select(x => x.Key).FirstOrDefault() ?? HeaderView.Text;
                    HeaderView.SetImage(gist.Owner?.AvatarUrl, Images.Avatar);
                    RenderGist();
                    RefreshHeaderView();
                }));
            });
        }
Exemplo n.º 4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.Image = Images.LoginUserUnknown;
            HeaderView.SubImageView.TintColor = UIColor.FromRGB(243, 156, 18);

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

            var events = new StringElement("Events", Octicon.Rss.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var issuesElement = new StringElement("Issues", Octicon.IssueOpened.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var commitsElement = new StringElement("Commits", Octicon.GitCommit.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var pullRequestsElement = new StringElement("Pull Requests", Octicon.GitPullRequest.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var sourceElement = new StringElement("Source", Octicon.Code.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var websiteElement = new StringElement("Website", Octicon.Globe.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var readmeElement = new StringElement("Readme", Octicon.Book.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var forkedElement = new StringElement("Fork", string.Empty)
            {
                Image     = Octicon.RepoForked.ToImage(),
                Font      = StringElement.DefaultDetailFont,
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };

            _splitElements[0] = new SplitViewElement(Octicon.Lock.ToImage(), Octicon.Package.ToImage());
            _splitElements[1] = new SplitViewElement(Octicon.IssueOpened.ToImage(), Octicon.Organization.ToImage());
            _splitElements[2] = new SplitViewElement(Octicon.Tag.ToImage(), Octicon.GitBranch.ToImage());

            var stargazers = _split.AddButton("Stargazers", "-");
            var watchers   = _split.AddButton("Watchers", "-");
            var forks      = _split.AddButton("Forks", "-");

            var renderFunc = new Action(() => {
                var model = ViewModel.Repository;
                var sec1  = new Section();
                sec1.Add(_splitElements);

                if (model.Parent != null)
                {
                    forkedElement.Value = model.Parent.FullName;
                    sec1.Add(forkedElement);
                }

                var sec2 = new Section {
                    events
                };

                if (model.HasIssues)
                {
                    sec2.Add(issuesElement);
                }

                if (ViewModel.Readme != null)
                {
                    sec2.Add(readmeElement);
                }

                Root.Reset(new Section {
                    _split
                }, sec1, sec2, new Section {
                    commitsElement, pullRequestsElement, sourceElement
                });

                if (!string.IsNullOrEmpty(model.Homepage))
                {
                    Root.Add(new Section {
                        websiteElement
                    });
                }
            });

            OnActivation(d => {
                d(HeaderView.Clicked.InvokeCommand(ViewModel.GoToOwnerCommand));

                d(_splitElements[1].Button1.Clicked.InvokeCommand(ViewModel.GoToIssuesCommand));
                d(_splitElements[1].Button2.Clicked.InvokeCommand(ViewModel.GoToContributors));
                d(_splitElements[2].Button1.Clicked.InvokeCommand(ViewModel.GoToReleasesCommand));
                d(_splitElements[2].Button2.Clicked.InvokeCommand(ViewModel.GoToBranchesCommand));

                d(events.Clicked.InvokeCommand(ViewModel.GoToEventsCommand));
                d(issuesElement.Clicked.InvokeCommand(ViewModel.GoToIssuesCommand));
                d(websiteElement.Clicked.InvokeCommand(ViewModel.GoToHomepageCommand));
                d(forkedElement.Clicked.InvokeCommand(ViewModel.GoToForkParentCommand));
                d(readmeElement.Clicked.InvokeCommand(ViewModel.GoToReadmeCommand));

                d(stargazers.Clicked.InvokeCommand(ViewModel.GoToStargazersCommand));
                d(watchers.Clicked.InvokeCommand(ViewModel.GoToWatchersCommand));
                d(forks.Clicked.InvokeCommand(ViewModel.GoToForksCommand));

                d(commitsElement.Clicked.InvokeCommand(ViewModel.GoToCommitsCommand));
                d(pullRequestsElement.Clicked.InvokeCommand(ViewModel.GoToPullRequestsCommand));
                d(sourceElement.Clicked.InvokeCommand(ViewModel.GoToSourceCommand));

                d(this.WhenAnyValue(x => x.ViewModel.Stargazers)
                  .Select(x => x != null ? x.ToString() : "-")
                  .Subscribe(x => stargazers.Text = x));

                d(this.WhenAnyValue(x => x.ViewModel.Watchers)
                  .Select(x => x != null ? x.ToString() : "-")
                  .Subscribe(x => watchers.Text = x));

                d(this.WhenAnyValue(x => x.ViewModel.Repository.ForksCount)
                  .Subscribe(x => forks.Text = x.ToString()));

                d(this.WhenAnyValue(x => x.ViewModel.Repository)
                  .IsNotNull()
                  .Subscribe(x =>
                {
                    _splitElements[0].Button1.Text = x.Private ? "Private" : "Public";
                    _splitElements[0].Button2.Text = x.Language ?? "N/A";
                    _splitElements[1].Button1.Text = x.OpenIssuesCount + (x.OpenIssuesCount == 1 ? " Issue" : " Issues");
                }));

                d(this.WhenAnyValue(x => x.ViewModel.RepositoryName)
                  .Subscribe(x => HeaderView.Text = x));

                d(this.WhenAnyValue(x => x.ViewModel.ShowMenuCommand)
                  .ToBarButtonItem(UIBarButtonSystemItem.Action, x => NavigationItem.RightBarButtonItem = x));

                d(this.WhenAnyValue(x => x.ViewModel.Branches)
                  .Select(x => x == null ? "Branches" : (x.Count >= 100 ? "100+" : x.Count.ToString()) + (x.Count == 1 ? " Branch" : " Branches"))
                  .SubscribeSafe(x => _splitElements[2].Button2.Text = x));

                d(this.WhenAnyValue(x => x.ViewModel.Contributors)
                  .Select(x => x == null ? "Contributors" : (x >= 100 ? "100+" : x.ToString()) + (x == 1 ? " Contributor" : " Contributors"))
                  .SubscribeSafe(x => _splitElements[1].Button2.Text = x));

                d(this.WhenAnyValue(x => x.ViewModel.Releases)
                  .Select(x => x == null ? "Releases" : (x >= 100 ? "100+" : x.ToString()) + (x == 1 ? " Release" : " Releases"))
                  .SubscribeSafe(x => _splitElements[2].Button1.Text = x));

                d(this.WhenAnyValue(x => x.ViewModel.Description).Subscribe(x => RefreshHeaderView(subtext: x)));

                d(this.WhenAnyValue(x => x.ViewModel.Avatar)
                  .Subscribe(x => HeaderView.SetImage(x?.ToUri(128), Images.LoginUserUnknown)));

                d(this.WhenAnyValue(x => x.ViewModel.Repository)
                  .IsNotNull()
                  .Subscribe(_ => renderFunc()));

                d(this.WhenAnyValue(x => x.ViewModel.Readme)
                  .Where(x => x != null && ViewModel.Repository != null)
                  .Subscribe(_ => renderFunc()));
            });
        }
Exemplo n.º 5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.SetImage(null, Images.Avatar);

            var compose = new UIBarButtonItem(UIBarButtonSystemItem.Compose);
            var more    = new UIBarButtonItem(UIBarButtonSystemItem.Action);

            NavigationItem.RightBarButtonItems = new[] { more, compose };

            var split        = new SplitButtonElement();
            var commentCount = split.AddButton("Comments", "-");
            var watchers     = split.AddButton("Watchers", "-");

            ICollection <Section> root = new LinkedList <Section>();

            root.Add(new Section {
                split
            });

            var secDetails = new Section();

            root.Add(secDetails);

            this.WhenAnyValue(x => x.ViewModel.ShowDescription)
            .DistinctUntilChanged()
            .Subscribe(x =>
            {
                if (x)
                {
                    secDetails.Insert(0, UITableViewRowAnimation.None, _descriptionElement);
                }
                else
                {
                    secDetails.Remove(_descriptionElement);
                }
            });

            this.WhenAnyValue(x => x.ViewModel.Description)
            .Where(x => !string.IsNullOrWhiteSpace(x))
            .Select(x => new DescriptionModel(x, (int)UIFont.PreferredSubheadline.PointSize, true))
            .Select(x => new MarkdownView {
                Model = x
            }.GenerateString())
            .Subscribe(_descriptionElement.SetValue);

            var split1 = new SplitViewElement(AtlassianIcon.Configure.ToImage(), AtlassianIcon.Error.ToImage());
            var split2 = new SplitViewElement(AtlassianIcon.Flag.ToImage(), AtlassianIcon.Spacedefault.ToImage());
            var split3 = new SplitViewElement(AtlassianIcon.Copyclipboard.ToImage(), AtlassianIcon.Calendar.ToImage());

            secDetails.Add(split1);
            secDetails.Add(split2);
            secDetails.Add(split3);

            var assigneeElement = new ButtonElement("Assigned", string.Empty, UITableViewCellStyle.Value1)
            {
                Image = AtlassianIcon.User.ToImage(),
            };

            secDetails.Add(assigneeElement);

            var commentsSection = new Section("Comments");

            root.Add(commentsSection);

            var addComment = new ButtonElement("Add Comment")
            {
                Image = AtlassianIcon.Addcomment.ToImage()
            };

            commentsSection.Reset(new[] { addComment });

            ViewModel
            .Comments
            .ChangedObservable()
            .Subscribe(x =>
            {
                if (x.Count > 0)
                {
                    var comments     = x.Select(y => new Comment(y.Avatar.ToUrl(), y.Name, y.Content, y.CreatedOn)).ToList();
                    var commentModel = new CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize);
                    var content      = new CommentsView {
                        Model = commentModel
                    }.GenerateString();
                    _commentsElement.SetValue(content);
                    commentsSection.Insert(0, UITableViewRowAnimation.None, _commentsElement);
                }
                else
                {
                    commentsSection.Remove(_commentsElement);
                }
            });

            Root.Reset(root);

            OnActivation(d =>
            {
                this.WhenAnyValue(x => x.ViewModel.Issue)
                .Where(x => x != null)
                .Subscribe(x =>
                {
                    var avatarUrl      = x.ReportedBy?.Avatar;
                    HeaderView.Text    = x.Title;
                    HeaderView.SubText = "Updated " + ViewModel.Issue.UtcLastUpdated.Humanize();
                    HeaderView.SetImage(new Avatar(avatarUrl).ToUrl(128), Images.Avatar);
                    TableView.TableHeaderView = HeaderView;
                })
                .AddTo(d);

                this.WhenAnyObservable(x => x.ViewModel.DismissCommand)
                .Subscribe(_ => NavigationController.PopViewController(true))
                .AddTo(d);

                this.WhenAnyValue(x => x.ViewModel.Issue)
                .Subscribe(x =>
                {
                    split1.Button1.Text = x?.Status;
                    split1.Button2.Text = x?.Priority;
                    split2.Button1.Text = x?.Metadata?.Kind;
                    split2.Button2.Text = x?.Metadata?.Component ?? "No Component";
                    split3.Button1.Text = x?.Metadata?.Version ?? "No Version";
                    split3.Button2.Text = x?.Metadata?.Milestone ?? "No Milestone";
                })
                .AddTo(d);

                HeaderView
                .Clicked
                .BindCommand(this, x => x.ViewModel.GoToReporterCommand)
                .AddTo(d);

                compose
                .GetClickedObservable()
                .SelectUnit()
                .BindCommand(ViewModel.GoToEditCommand)
                .AddTo(d);

                addComment
                .Clicked
                .Subscribe(_ => NewCommentViewController.Present(this, ViewModel.AddComment))
                .AddTo(d);

                assigneeElement
                .BindValue(this.WhenAnyValue(x => x.ViewModel.Assigned))
                .AddTo(d);

                assigneeElement
                .BindDisclosure(
                    this.WhenAnyValue(x => x.ViewModel.Assigned)
                    .Select(x => !string.Equals(x, "Unassigned", StringComparison.OrdinalIgnoreCase)))
                .AddTo(d);

                assigneeElement
                .Clicked
                .SelectUnit()
                .BindCommand(ViewModel.GoToAssigneeCommand)
                .AddTo(d);

                more.Bind(ViewModel.ShowMenuCommand)
                .AddTo(d);

                this.WhenAnyValue(x => x.ViewModel.Issue)
                .Select(x => x != null)
                .Subscribe(x => compose.Enabled = x)
                .AddTo(d);

                this.WhenAnyObservable(x => x.ViewModel.Comments.CountChanged)
                .StartWith(ViewModel.Comments.Count)
                .Subscribe(x => commentCount.Text = x.ToString())
                .AddTo(d);

                this.WhenAnyValue(x => x.ViewModel.Issue.FollowerCount)
                .Subscribe(x => watchers.Text = x.ToString())
                .AddTo(d);
            });
        }
Exemplo n.º 6
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.Image = Images.LoginUserUnknown;
            HeaderView.SubImageView.TintColor = UIColor.FromRGB(243, 156, 18);

            var headerSection = new Section();
            var filesSection  = new Section();

            var split    = new SplitButtonElement();
            var files    = split.AddButton("Files", "-");
            var comments = split.AddButton("Comments", "-");
            var forks    = split.AddButton("Forks", "-");

            headerSection.Add(split);

            var footerButton    = new TableFooterButton("Add Comment");
            var commentsSection = new Section(null, footerButton);
            var commentsElement = new HtmlElement("comments");

            commentsSection.Add(commentsElement);

            var splitRow1      = new SplitViewElement(Octicon.Lock.ToImage(), Octicon.Package.ToImage());
            var splitRow2      = new SplitViewElement(Octicon.Pencil.ToImage(), Octicon.Star.ToImage());
            var ownerElement   = new ButtonElement("Owner", Octicon.Person.ToImage());
            var detailsSection = new Section {
                splitRow1, splitRow2, ownerElement
            };

            Root.Reset(headerSection, detailsSection, filesSection, commentsSection);

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

            ViewModel.Comments.Changed.Subscribe(_ => {
                var commentModels = ViewModel.Comments
                                    .Select(x => {
                    var avatarUrl = x?.User?.AvatarUrl;
                    var avatar    = new GitHubAvatar(avatarUrl);
                    return(new Comment(avatar.ToUri(), x.User.Login, x.BodyHtml, x.CreatedAt.UtcDateTime.Humanize()));
                }).ToList();

                if (commentModels.Count > 0)
                {
                    var model     = new CommentModel(commentModels, (int)UIFont.PreferredSubheadline.PointSize);
                    var razorView = new CommentsView {
                        Model = model
                    };
                    var html = razorView.GenerateString();
                    commentsElement.Value = html;

                    if (!commentsSection.Contains(commentsElement))
                    {
                        commentsSection.Insert(0, UITableViewRowAnimation.Fade, commentsElement);
                    }
                }
                else
                {
                    commentsSection.Remove(commentsElement);
                }
            });

            OnActivation(d => {
                d(footerButton.Clicked.InvokeCommand(ViewModel.AddCommentCommand));
                d(HeaderView.Clicked.InvokeCommand(ViewModel.GoToOwnerCommand));
                d(commentsElement.UrlRequested.InvokeCommand(ViewModel.GoToUrlCommand));
                d(splitRow2.Button2.Clicked.InvokeCommand(ViewModel.ToggleStarCommand));
                d(ownerElement.Clicked.InvokeCommand(ViewModel.GoToOwnerCommand));
                d(DialogSource.SelectedObservable.OfType <FileElement>().Select(x => x.File).InvokeCommand(ViewModel.GoToFileSourceCommand));

                var updatedGistObservable = ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null);
                d(updatedGistObservable.SubscribeSafe(x => RefreshHeaderView(subtext: x.Description)));
                d(updatedGistObservable.Subscribe(x => filesSection.Reset(x.Files.Select(y => new FileElement(y.Value)))));
                d(ownerElement.BindValue(updatedGistObservable.Select(x => x.Owner?.Login ?? "Anonymous")));
                d(files.BindText(updatedGistObservable.Select(x => x.Files?.Count() ?? 0)));
                d(forks.BindText(updatedGistObservable.Select(x => x.Forks?.Count() ?? 0)));
                d(comments.BindText(updatedGistObservable.Select(x => x.Comments.ToString())));
                d(splitRow1.Button1.BindText(updatedGistObservable.Select(x => x.Public ? "Public" : "Private")));
                d(splitRow1.Button2.BindText(updatedGistObservable.Select(x => "Revisions".ToQuantity(x.History?.Count ?? 0))));

                d(this.WhenAnyValue(x => x.ViewModel.Gist.Owner).Select(x => x == null)
                  .Subscribe(x => ownerElement.Hidden = x));

                d(this.WhenAnyValue(x => x.ViewModel.Avatar)
                  .Subscribe(x => HeaderView.SetImage(x?.ToUri(64), Images.LoginUserUnknown)));

                d(this.WhenAnyValue(x => x.ViewModel.ShowMenuCommand)
                  .ToBarButtonItem(UIBarButtonSystemItem.Action, x => NavigationItem.RightBarButtonItem = x));

                d(this.WhenAnyValue(x => x.ViewModel.IsStarred)
                  .Where(x => x.HasValue)
                  .Select(x => x.Value ? "Starred!" : "Unstarred")
                  .Subscribe(x => splitRow2.Button2.Text = x));

                d(splitRow2.Button1.BindText(this.WhenAnyValue(x => x.ViewModel.Gist).Select(x => {
                    var delta = DateTimeOffset.UtcNow.UtcDateTime - x.UpdatedAt.UtcDateTime;
                    return((delta.Days <= 0) ? "Created Today" : string.Format("{0} Days Old", delta.Days));
                })));
            });
        }
Exemplo n.º 7
0
        public PullRequestView()
        {
            _descriptionElement = new HtmlElement("body");
            _commentsElement    = new HtmlElement("comments");

            _milestoneElement = new StyledStringElement("Milestone", "No Milestone", UITableViewCellStyle.Value1)
            {
                Image = Images.Milestone
            };
            _milestoneElement.Tapped += () => ViewModel.GoToMilestoneCommand.ExecuteIfCan();

            _assigneeElement = new StyledStringElement("Assigned", "Unassigned", UITableViewCellStyle.Value1)
            {
                Image = Images.Person
            };
            _assigneeElement.Tapped += () => ViewModel.GoToAssigneeCommand.ExecuteIfCan();

            _labelsElement = new StyledStringElement("Labels", "None", UITableViewCellStyle.Value1)
            {
                Image = Images.Tag
            };
            _labelsElement.Tapped += () => ViewModel.GoToLabelsCommand.ExecuteIfCan();

            _addCommentElement = new StyledStringElement("Add Comment")
            {
                Image = Images.Pencil
            };
            _addCommentElement.Tapped += AddCommentTapped;

            _split1 = new SplitViewElement
            {
                Button1 = new SplitViewElement.SplitButton(Images.Gear, string.Empty),
                Button2 = new SplitViewElement.SplitButton(Images.Gear, string.Empty)
            };

            _split2 = new SplitViewElement
            {
                Button1 = new SplitViewElement.SplitButton(Images.Gear, string.Empty),
                Button2 = new SplitViewElement.SplitButton(Images.Gear, string.Empty)
            };

            _commitsElement = new StyledStringElement("Commits", () => ViewModel.GoToCommitsCommand.ExecuteIfCan(), Images.Commit);
            _filesElement   = new StyledStringElement("Files", () => ViewModel.GoToFilesCommand.ExecuteIfCan(), Images.Code);

            this.WhenViewModel(x => x.GoToUrlCommand).Subscribe(x =>
            {
                _commentsElement.UrlRequested    = x.Execute;
                _descriptionElement.UrlRequested = x.Execute;
            });

            this.WhenViewModel(x => x.MarkdownDescription).Subscribe(x =>
            {
                var markdown = new DescriptionView {
                    Model = x
                };
                var html = markdown.GenerateString();
                _descriptionElement.Value = html;
            });

            this.WhenViewModel(x => x.ShowMenuCommand)
            .Select(x => x.ToBarButtonItem(UIBarButtonSystemItem.Action))
            .Subscribe(x => NavigationItem.RightBarButtonItem = x);
        }
Exemplo n.º 8
0
        public RepositoryView()
        {
            HeaderView.Image = Images.LoginUserUnknown;

            _sourceSection = new Section
            {
                new DialogStringElement("Commits", () => ViewModel.GoToCommitsCommand.ExecuteIfCan(), Images.Commit),
                new DialogStringElement("Pull Requests", () => ViewModel.GoToPullRequestsCommand.ExecuteIfCan(), Images.PullRequest),
                new DialogStringElement("Source", () => ViewModel.GoToSourceCommand.ExecuteIfCan(), Images.Code),
            };

            _ownerElement = new StyledStringElement("Owner", string.Empty)
            {
                Image = Images.Person, Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            _ownerElement.Tapped += () => ViewModel.GoToOwnerCommand.ExecuteIfCan();
            this.WhenAnyValue(x => x.ViewModel.Repository)
            .Subscribe(x => _ownerElement.Value = x == null ? string.Empty : x.Owner.Login);

            HeaderView.SubImageView.TintColor = UIColor.FromRGB(243, 156, 18);
            this.WhenAnyValue(x => x.ViewModel.GoToOwnerCommand).Subscribe(x =>
                                                                           HeaderView.ImageButtonAction = x != null ? new Action(() => ViewModel.GoToOwnerCommand.ExecuteIfCan()) : null);

            _splitElements[0]         = new SplitViewElement();
            _splitElements[0].Button1 = new SplitViewElement.SplitButton(Images.Lock, string.Empty);
            _splitElements[0].Button2 = new SplitViewElement.SplitButton(Images.Package, string.Empty);

            _splitElements[1]         = new SplitViewElement();
            _splitElements[1].Button1 = new SplitViewElement.SplitButton(Images.IssueOpened, string.Empty, () => ViewModel.GoToIssuesCommand.ExecuteIfCan());
            _splitElements[1].Button2 = new SplitViewElement.SplitButton(Images.Organization, string.Empty, () => ViewModel.GoToContributors.ExecuteIfCan());

            _splitElements[2]         = new SplitViewElement();
            _splitElements[2].Button1 = new SplitViewElement.SplitButton(Images.Tag, string.Empty, () => ViewModel.GoToReleasesCommand.ExecuteIfCan());
            _splitElements[2].Button2 = new SplitViewElement.SplitButton(Images.Branch, string.Empty, () => ViewModel.GoToBranchesCommand.ExecuteIfCan());

            var stargazers = _split.AddButton("Stargazers", "-", () => ViewModel.GoToStargazersCommand.ExecuteIfCan());
            var watchers   = _split.AddButton("Watchers", "-", () => ViewModel.GoToWatchersCommand.ExecuteIfCan());
            var forks      = _split.AddButton("Forks", "-", () => ViewModel.GoToForksCommand.ExecuteIfCan());

            this.WhenAnyValue(x => x.ViewModel.Stargazers)
            .Select(x => x != null ? x.ToString() : "-")
            .Subscribe(x => stargazers.Text = x);

            this.WhenAnyValue(x => x.ViewModel.Watchers)
            .Select(x => x != null ? x.ToString() : "-")
            .Subscribe(x => watchers.Text = x);

            this.WhenAnyValue(x => x.ViewModel.Repository.ForksCount)
            .Subscribe(x => forks.Text = x.ToString());

            this.WhenAnyValue(x => x.ViewModel.Repository)
            .IsNotNull()
            .Subscribe(x =>
            {
                _splitElements[0].Button1.Text = x.Private ? "Private" : "Public";
                _splitElements[0].Button2.Text = x.Language ?? "N/A";
                _splitElements[1].Button1.Text = x.OpenIssues + (x.OpenIssues == 1 ? " Issue" : " Issues");
            });

            Appeared.Take(1)
            .Select(_ => Observable.Timer(TimeSpan.FromSeconds(0.35f)))
            .Switch()
            .ObserveOn(RxApp.MainThreadScheduler)
            .Select(_ => this.WhenAnyValue(x => x.ViewModel.IsStarred).Where(x => x.HasValue))
            .Switch()
            .Subscribe(x => HeaderView.SetSubImage(x.Value ? Images.Star.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) : null));

            this.WhenAnyValue(x => x.ViewModel.RepositoryName)
            .Subscribe(x => HeaderView.Text = x);

            this.WhenAnyValue(x => x.ViewModel.ShowMenuCommand)
            .Select(x => x.ToBarButtonItem(UIBarButtonSystemItem.Action))
            .Subscribe(x => NavigationItem.RightBarButtonItem = x);

            this.WhenAnyValue(x => x.ViewModel.Branches)
            .SubscribeSafe(x =>
            {
                if (x == null)
                {
                    _splitElements[2].Button2.Text = "- Branches";
                }
                else
                {
                    _splitElements[2].Button2.Text = (x.Count >= 100 ? "100+" : x.Count.ToString()) + (x.Count == 1 ? " Branch" : " Branches");
                }
            });

            this.WhenAnyValue(x => x.ViewModel.Contributors)
            .SubscribeSafe(x =>
            {
                if (x == null)
                {
                    _splitElements[1].Button2.Text = "- Contributors";
                }
                else
                {
                    _splitElements[1].Button2.Text = (x >= 100 ? "100+" : x.ToString()) + (x == 1 ? " Contributor" : " Contributors");
                }
            });


            this.WhenAnyValue(x => x.ViewModel.Releases)
            .SubscribeSafe(x =>
            {
                if (x == null)
                {
                    _splitElements[2].Button1.Text = "- Releases";
                }
                else
                {
                    _splitElements[2].Button1.Text = (x >= 100 ? "100+" : x.ToString()) + (x == 1 ? " Release" : " Releases");
                }
            });
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var split        = new SplitButtonElement();
            var commentCount = split.AddButton("Comments", "-");
            var participants = split.AddButton("Participants", "-");
            var approvals    = split.AddButton("Approvals", "-");

            this.WhenAnyValue(x => x.ViewModel.Title)
            .Subscribe(x => RefreshHeaderView(x));

            ViewModel.WhenAnyValue(x => x.PullRequest).Subscribe(x =>
            {
                if (x != null)
                {
                    var avatarUrl      = x?.Author?.Links?.Avatar?.Href;
                    HeaderView.SubText = "Updated " + ViewModel.PullRequest.UpdatedOn.Humanize();
                    HeaderView.SetImage(new Avatar(avatarUrl).ToUrl(128), Images.Avatar);
                }
                else
                {
                    HeaderView.SetImage(null, Images.Avatar);
                    HeaderView.SubText = null;
                }
            });

            var root = new List <Section>();

            root.Add(new Section {
                split
            });

            var secDetails = new Section();

            root.Add(secDetails);

            this.WhenAnyValue(x => x.ViewModel.Description)
            .Where(x => !string.IsNullOrWhiteSpace(x))
            .Select(x => new DescriptionModel(x, (int)UIFont.PreferredSubheadline.PointSize, true))
            .Select(x => new MarkdownView {
                Model = x
            }.GenerateString())
            .Subscribe(content =>
            {
                _descriptionElement.SetValue(content);
                secDetails.Insert(0, UITableViewRowAnimation.None, _descriptionElement);
            });

            var split1 = new SplitViewElement(AtlassianIcon.Calendar.ToImage(), AtlassianIcon.Devtoolsbranch.ToImage());

            secDetails.Add(split1);

            this.WhenAnyValue(x => x.ViewModel.PullRequest.State)
            .Select(x => x?.ToLower().Humanize(LetterCasing.Title))
            .Subscribe(x => split1.Button2.Text = x ?? "Open");

            this.WhenAnyValue(x => x.ViewModel.PullRequest)
            .Select(x => x?.CreatedOn.ToString("MM/dd/yy"))
            .Subscribe(x => split1.Button1.Text = x);

            var commitsElement = new ButtonElement("Commits", AtlassianIcon.Devtoolscommit.ToImage());

            commitsElement.Clicked.SelectUnit().BindCommand(ViewModel.GoToCommitsCommand);
            secDetails.Add(commitsElement);

            var mergeElement = new ButtonElement("Merge", AtlassianIcon.ListAdd.ToImage());

            mergeElement.Accessory = UITableViewCellAccessory.None;

            var rejectElement = new LoaderButtonElement("Reject", AtlassianIcon.ListRemove.ToImage());

            rejectElement.Accessory = UITableViewCellAccessory.None;
            rejectElement.BindLoader(ViewModel.RejectCommand);

            var mergeSection = new Section {
                mergeElement, rejectElement
            };

            var approvalSection = new Section("Approvals");
            var approveElement  = new LoaderButtonElement("Approve", AtlassianIcon.Approve.ToImage());

            approveElement.Accessory = UITableViewCellAccessory.None;
            approveElement.BindLoader(ViewModel.ToggleApproveButton);
            approveElement.BindCaption(this.WhenAnyValue(x => x.ViewModel.Approved).Select(x => x ? "Unapprove" : "Approve"));
            root.Add(approvalSection);

            this.WhenAnyValue(x => x.ViewModel.Approvals)
            .Select(x => x.Select(y => new UserElement(y)).OfType <Element>())
            .Subscribe(x => approvalSection.Reset(x.Concat(new[] { approveElement })));

            var commentsSection = new Section("Comments");

            root.Add(commentsSection);

            var addComment = new ButtonElement("Add Comment")
            {
                Image = AtlassianIcon.Addcomment.ToImage()
            };

            commentsSection.Reset(new[] { addComment });

            ViewModel
            .Comments
            .ChangedObservable()
            .Subscribe(x =>
            {
                if (x.Count > 0)
                {
                    var comments     = x.Select(y => new Comment(y.Avatar.ToUrl(), y.Name, y.Content, y.CreatedOn)).ToList();
                    var commentModel = new CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize);
                    var content      = new CommentsView {
                        Model = commentModel
                    }.GenerateString();
                    _commentsElement.SetValue(content);
                    commentsSection.Insert(0, UITableViewRowAnimation.None, _commentsElement);
                }
                else
                {
                    commentsSection.Remove(_commentsElement);
                }
            });

            Root.Reset(root);

            this.WhenAnyValue(x => x.ViewModel.IsOpen).Subscribe(x =>
            {
                if (x)
                {
                    Root.Insert(root.IndexOf(secDetails) + 1, mergeSection);
                }
                else
                {
                    Root.Remove(mergeSection);
                }
            });

            OnActivation(disposable =>
            {
                mergeElement
                .Clicked
                .SelectUnit()
                .BindCommand(this, x => x.ViewModel.MergeCommand)
                .AddTo(disposable);

                addComment
                .Clicked
                .Subscribe(_ => NewCommentViewController.Present(this, ViewModel.AddComment))
                .AddTo(disposable);

                this.WhenAnyValue(x => x.ViewModel.ParticipantCount)
                .Subscribe(x => participants.Text = x?.ToString() ?? "-")
                .AddTo(disposable);

                this.WhenAnyValue(x => x.ViewModel.ApprovalCount)
                .Subscribe(x => approvals.Text = x?.ToString() ?? "-")
                .AddTo(disposable);

                this.WhenAnyValue(x => x.ViewModel.CommentCount)
                .Subscribe(x => commentCount.Text = x?.ToString() ?? "-")
                .AddTo(disposable);

                this.WhenAnyObservable(x => x.ViewModel.MergeCommand)
                .Subscribe(_ =>
                {
                    var vc = new PullRequestApproveViewController(
                        ViewModel.Username, ViewModel.Repository, ViewModel.PullRequestId);
                    vc.DeleteSourceBranch = ViewModel.PullRequest.CloseSourceBranch;
                    vc.MergeCommand
                    .Do(x => ViewModel.PullRequest = x)
                    .Do(x => DismissViewController(true, null))
                    .Subscribe();
                    this.PresentModal(vc);
                })
                .AddTo(disposable);
            });
        }