public override void ViewDidLoad() { base.ViewDidLoad(); var commitsElement = new ButtonElement("Commits", Octicon.GitCommit.ToImage()); var filesElement = new ButtonElement("Files Changed", Octicon.Diff.ToImage()); var mergeButton = new StringElement("Merge", Octicon.GitMerge.ToImage()); var pullRequestSection = new Section { commitsElement, filesElement, mergeButton }; OnActivation(d => { var commitsObs = this.WhenAnyValue(x => x.ViewModel.PullRequest.Commits); d(commitsElement.BindValue(commitsObs)); d(commitsElement.BindCommand(ViewModel.GoToCommitsCommand)); d(commitsElement.BindDisclosure(commitsObs.Select(x => x > 0))); var filesObs = this.WhenAnyValue(x => x.ViewModel.PullRequest.ChangedFiles); d(filesElement.BindValue(filesObs)); d(filesElement.BindCommand(ViewModel.GoToFilesCommand)); d(filesElement.BindDisclosure(filesObs.Select(x => x > 0))); d(mergeButton.Clicked.SubscribeSafe(_ => { if (!ViewModel.PullRequest.Merged && ViewModel.CanMerge && ViewModel.PullRequest.State == Octokit.ItemState.Open) { PromptForCommitMessage(); } })); d(this.WhenAnyValue(x => x.ViewModel.PullRequest.Merged, x => x.ViewModel.CanMerge, x => x.ViewModel.PullRequest.State) .Subscribe(x => { if (x.Item1) { mergeButton.Caption = "Merged"; mergeButton.SelectionStyle = UITableViewCellSelectionStyle.None; mergeButton.Accessory = UITableViewCellAccessory.Checkmark; } else if (!x.Item1 && x.Item2 && x.Item3 == Octokit.ItemState.Open) { mergeButton.Caption = "Merge"; mergeButton.SelectionStyle = UITableViewCellSelectionStyle.Blue; mergeButton.Accessory = UITableViewCellAccessory.DisclosureIndicator; } else { mergeButton.Caption = "Not Merged"; mergeButton.SelectionStyle = UITableViewCellSelectionStyle.None; mergeButton.Accessory = UITableViewCellAccessory.None; } })); }); Root.Insert(Root.Count - 1, pullRequestSection); }
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); }); }
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)); }))); }); }