public override void ViewDidLoad() { base.ViewDidLoad(); var additions = _split.AddButton("Additions", "-"); var deletions = _split.AddButton("Deletions", "-"); var parents = _split.AddButton("Parents", "-"); var commentsElement = new WebElement("comments"); commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan; //commentsSection.Add(commentsElement); var headerSection = new Section(HeaderView) { _split }; Root.Reset(headerSection); ViewModel.WhenAnyValue(x => x.Commit).IsNotNull().SubscribeSafe(x => { HeaderView.Image = Images.LoginUserUnknown; HeaderView.ImageUri = x.GenerateGravatarUrl(); var msg = x.Commit.Message ?? string.Empty; var firstLine = msg.IndexOf("\n", StringComparison.Ordinal); HeaderView.Text = firstLine > 0 ? msg.Substring(0, firstLine) : msg; HeaderView.SubText = "Commited " + (x.Commit.Committer.Date).ToDaysAgo(); additions.Text = x.Stats.Additions.ToString(); deletions.Text = x.Stats.Deletions.ToString(); parents.Text = x.Parents.Count.ToString(); ReloadData(); }); ViewModel.WhenAnyValue(x => x.Commit).Where(x => x != null).Subscribe(Render); ViewModel.Comments.Changed .Select(_ => new Unit()) .StartWith(new Unit()) .Subscribe(x => { var commentModels = ViewModel.Comments.Select(c => new Comment(c.User.AvatarUrl, c.User.Login, c.BodyHtml, c.CreatedAt.ToDaysAgo())); var razorView = new CommentsView { Model = commentModels }; var html = razorView.GenerateString(); commentsElement.Value = html; if (commentsElement.GetRootElement() == null && ViewModel.Comments.Count > 0) { _commentSection.Add(commentsElement); } }); }
public void RenderComments() { var comments = ViewModel.Comments .Select(x => new Comment(x.User.AvatarUrl, x.User.Login, ViewModel.ConvertToMarkdown(x.Body), x.CreatedAt)) .Concat(ViewModel.Events.Select(x => new Comment(x.Actor.AvatarUrl, x.Actor.Login, CreateEventBody(x.Event, x.CommitId), x.CreatedAt))) .Where(x => !string.IsNullOrEmpty(x.Body)) .OrderBy(x => x.Date) .ToList(); var commentModel = new CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize); var razorView = new CommentsView { Model = commentModel }; var html = razorView.GenerateString(); InvokeOnMainThread(() => { _commentsElement.SetValue(!comments.Any() ? null : html); Render(); }); }
public override void ViewDidLoad() { base.ViewDidLoad(); var commentsElement = new HtmlElement("comments"); commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan; ViewModel.Comments.Changed .Select(_ => new Unit()) .StartWith(new Unit()) .Subscribe(x => { var comments = ViewModel.Comments.Select(c => new Comment(c.Avatar.ToUri(), c.Actor, c.Body, c.UtcCreatedAt.Humanize())).ToList(); var commentModel = new CodeHub.WebViews.CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize); var razorView = new CommentsView { Model = commentModel }; var html = razorView.GenerateString(); commentsElement.Value = html; if (commentsElement.GetRootElement() == null && ViewModel.Comments.Count > 0) { _commentsSection.Add(commentsElement); } TableView.ReloadData(); }); ViewModel.WhenAnyValue(x => x.Commit).IsNotNull().Subscribe(commitModel => { var detailSection = new Section(); Root.Reset(_headerSection, detailSection); var user = commitModel.GenerateCommiterName(); detailSection.Add(new MultilinedElement(user, commitModel.Commit.Message) { CaptionColor = Theme.MainTextColor, ValueColor = Theme.MainTextColor, BackgroundColor = UIColor.White }); if (ViewModel.ShowRepository) { var repo = new StringElement(ViewModel.RepositoryName) { Font = StringElement.DefaultDetailFont, TextColor = StringElement.DefaultDetailColor, Image = Octicon.Repo.ToImage() }; repo.Tapped += () => ViewModel.GoToRepositoryCommand.Execute(null); detailSection.Add(repo); } var paths = commitModel.Files.GroupBy(y => { var filename = "/" + y.Filename; return(filename.Substring(0, filename.LastIndexOf("/", System.StringComparison.Ordinal) + 1)); }).OrderBy(y => y.Key); foreach (var p in paths) { var fileSection = new Section(p.Key); foreach (var x in p) { var y = x; var file = x.Filename.Substring(x.Filename.LastIndexOf('/') + 1); var sse = new ChangesetElement(file, x.Status, x.Additions, x.Deletions); sse.Tapped += () => ViewModel.GoToFileCommand.Execute(y); fileSection.Add(sse); } Root.Add(fileSection); } Root.Add(_commentsSection); }); }
protected BaseIssueViewController() { CommentsElement = new HtmlElement("comments"); this.WhenAnyValue(x => x.ViewModel.GoToUrlCommand) .Subscribe(x => CommentsElement.UrlRequested = x.ExecuteIfCan); DescriptionElement = new HtmlElement("description"); this.WhenAnyValue(x => x.ViewModel.GoToUrlCommand) .Subscribe(x => DescriptionElement.UrlRequested = x.ExecuteIfCan); this.WhenAnyValue(x => x.ViewModel.ShowMenuCommand) .Select(x => x.ToBarButtonItem(UIBarButtonSystemItem.Action)) .Subscribe(x => NavigationItem.RightBarButtonItem = x); this.WhenAnyObservable(x => x.ViewModel.GoToAssigneesCommand) .Subscribe(_ => IssueAssigneeViewController.Show(this, ViewModel.CreateAssigneeViewModel())); this.WhenAnyObservable(x => x.ViewModel.GoToMilestonesCommand) .Subscribe(_ => IssueMilestonesViewController.Show(this, ViewModel.CreateMilestonesViewModel())); this.WhenAnyObservable(x => x.ViewModel.GoToLabelsCommand) .Subscribe(_ => IssueLabelsViewController.Show(this, ViewModel.CreateLabelsViewModel())); this.WhenAnyValue(x => x.ViewModel.GoToOwnerCommand) .Subscribe(x => HeaderView.ImageButtonAction = x != null ? new Action(() => ViewModel.GoToOwnerCommand.ExecuteIfCan()) : null); Appeared.Take(1) .Select(_ => Observable.Timer(TimeSpan.FromSeconds(0.2f))) .Switch() .ObserveOn(RxApp.MainThreadScheduler) .Select(_ => this.WhenAnyValue(x => x.ViewModel.IsClosed)) .Switch() .Subscribe(x => { HeaderView.SubImageView.TintColor = x ? UIColor.FromRGB(0xbd, 0x2c, 0) : UIColor.FromRGB(0x6c, 0xc6, 0x44); HeaderView.SetSubImage((x ? Octicon.IssueClosed :Octicon.IssueOpened).ToImage()); }); MilestoneElement = new StringElement("Milestone", string.Empty, UITableViewCellStyle.Value1) { Image = Octicon.Milestone.ToImage() }; MilestoneElement.Tapped = () => ViewModel.GoToMilestonesCommand.ExecuteIfCan(); this.WhenAnyValue(x => x.ViewModel.AssignedMilestone) .Select(x => x == null ? "No Milestone" : x.Title) .Subscribe(x => MilestoneElement.Value = x); AssigneeElement = new StringElement("Assigned", string.Empty, UITableViewCellStyle.Value1) { Image = Octicon.Person.ToImage() }; AssigneeElement.Tapped = () => ViewModel.GoToAssigneesCommand.ExecuteIfCan(); this.WhenAnyValue(x => x.ViewModel.AssignedUser) .Select(x => x == null ? "Unassigned" : x.Login) .Subscribe(x => AssigneeElement.Value = x); LabelsElement = new StringElement("Labels", string.Empty, UITableViewCellStyle.Value1) { Image = Octicon.Tag.ToImage() }; LabelsElement.Tapped = () => ViewModel.GoToLabelsCommand.ExecuteIfCan(); this.WhenAnyValue(x => x.ViewModel.AssignedLabels) .Select(x => (x == null || x.Count == 0) ? "None" : string.Join(",", x.Select(y => y.Name))) .Subscribe(x => LabelsElement.Value = x); this.WhenAnyValue(x => x.ViewModel.CanModify) .Select(x => x ? UITableViewCellAccessory.DisclosureIndicator : UITableViewCellAccessory.None) .Subscribe(x => MilestoneElement.Accessory = AssigneeElement.Accessory = LabelsElement.Accessory = x); DetailsSection.Add(MilestoneElement); DetailsSection.Add(AssigneeElement); DetailsSection.Add(LabelsElement); this.WhenAnyValue(x => x.ViewModel.Avatar) .SubscribeSafe(x => HeaderView.SetImage(x?.ToUri(128), Images.LoginUserUnknown)); this.WhenAnyValue(x => x.ViewModel.Issue) .IsNotNull() .Subscribe(x => { HeaderView.Text = x.Title; HeaderView.SubText = x.UpdatedAt.HasValue ? ("Updated " + x.UpdatedAt.Value.UtcDateTime.Humanize()) : ("Created " + x.CreatedAt.UtcDateTime.Humanize()); RefreshHeaderView(); }); this.WhenAnyValue(x => x.ViewModel.MarkdownDescription) .Subscribe(x => { if (string.IsNullOrEmpty(x)) { DetailsSection.Remove(DescriptionElement); } else { var model = new DescriptionModel(x, (int)UIFont.PreferredSubheadline.PointSize); var markdown = new MarkdownView { Model = model }; var html = markdown.GenerateString(); DescriptionElement.Value = html; if (!DetailsSection.Contains(DescriptionElement)) { DetailsSection.Insert(0, UITableViewRowAnimation.Fade, DescriptionElement); } } }); CommentsSection.FooterView = new TableFooterButton("Add Comment", () => ViewModel.AddCommentCommand.ExecuteIfCan()); this.WhenAnyValue(x => x.ViewModel.Events) .Select(x => x.Changed) .Switch() .Select(x => ViewModel.Events) .Subscribe(events => { var comments = events.Select(x => { var body = string.Empty; var comment = x as IssueCommentItemViewModel; var @event = x as IssueEventItemViewModel; if (comment != null) { body = comment.Comment; } else if (@event != null) { body = CreateEventBody(@event.EventInfo, @event.Commit); } return(new Comment(x.AvatarUrl.ToUri(), x.Actor, body, x.CreatedAt.Humanize())); }) .Where(x => !string.IsNullOrEmpty(x.Body)) .ToList(); if (comments.Count > 0) { var commentModel = new CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize); var razorView = new CommentsView { Model = commentModel }; var html = razorView.GenerateString(); CommentsElement.Value = html; if (!CommentsSection.Contains(CommentsElement)) { CommentsSection.Insert(0, UITableViewRowAnimation.Fade, CommentsElement); } } else { CommentsSection.Remove(CommentsElement); } }); var commentsButton = SplitButton.AddButton("Comments", "-"); var participantsButton = SplitButton.AddButton("Participants", "-"); this.WhenAnyValue(x => x.ViewModel.CommentCount) .Subscribe(x => commentsButton.Text = x.ToString()); this.WhenAnyValue(x => x.ViewModel.Participants) .Subscribe(x => participantsButton.Text = x.ToString()); }
public override void ViewDidLoad() { base.ViewDidLoad(); HeaderView.Image = Images.LoginUserUnknown; var split = new SplitButtonElement(); var headerSection = new Section { split }; var descriptionElement = new MultilinedElement(); var detailsSection = new Section(); var footerButton = new TableFooterButton("Add Comment"); var commentsSection = new Section(null, footerButton); var diffButton = new StringElement(Octicon.DiffAdded.ToImage()); var removedButton = new StringElement(Octicon.DiffRemoved.ToImage()); var modifiedButton = new StringElement(Octicon.DiffModified.ToImage()); var allChangesButton = new StringElement("All Changes", Octicon.Diff.ToImage()); detailsSection.Add(new [] { diffButton, removedButton, modifiedButton, allChangesButton }); var additions = split.AddButton("Additions"); var deletions = split.AddButton("Deletions"); var parents = split.AddButton("Parents"); var commentsElement = new HtmlElement("comments"); ViewModel.Comments.Changed .Select(_ => new Unit()) .StartWith(new Unit()) .Subscribe(x => { var comments = ViewModel.Comments.Select(c => new Comment(c.Avatar.ToUri(), c.Actor, c.Body, c.UtcCreatedAt.Humanize())).ToList(); var commentModel = new CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize); var razorView = new CommentsView { Model = commentModel }; var html = razorView.GenerateString(); commentsElement.Value = html; if (commentsElement.GetRootElement() == null && ViewModel.Comments.Count > 0) { commentsSection.Add(commentsElement); } TableView.ReloadData(); }); this.WhenAnyValue(x => x.ViewModel.Commit) .IsNotNull() .Take(1) .Subscribe(_ => Root.Reset(headerSection, detailsSection, commentsSection)); Appeared .Take(1) .Select(_ => this.WhenAnyValue(x => x.ViewModel.CommitMessage, y => y.ViewModel.CommiterName)) .Switch() .Where(x => x.Item1 != null && x.Item2 != null) .Take(1) .Subscribe(_ => detailsSection.Insert(0, UITableViewRowAnimation.Automatic, descriptionElement)); OnActivation(d => { d(allChangesButton.BindCommand(ViewModel.GoToAllFiles)); d(footerButton.Clicked.InvokeCommand(ViewModel.AddCommentCommand)); d(this.WhenAnyValue(x => x.ViewModel.Avatar) .Subscribe(x => HeaderView.SetImage(x?.ToUri(128), Images.LoginUserUnknown))); d(this.WhenAnyValue(x => x.ViewModel.CommitMessage) .Subscribe(x => descriptionElement.Details = x ?? string.Empty)); d(descriptionElement.BindCaption(this.WhenAnyValue(x => x.ViewModel.CommiterName))); d(diffButton.BindCommand(ViewModel.GoToAddedFiles)); d(diffButton.BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffAdditions).Select(x => x > 0))); d(diffButton.BindCaption(this.WhenAnyValue(x => x.ViewModel.DiffAdditions).StartWith(0).Select(x => string.Format("{0} added", x)))); d(removedButton.BindCommand(ViewModel.GoToRemovedFiles)); d(removedButton.BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffDeletions).Select(x => x > 0))); d(removedButton.BindCaption(this.WhenAnyValue(x => x.ViewModel.DiffDeletions).StartWith(0).Select(x => string.Format("{0} removed", x)))); d(modifiedButton.BindCommand(ViewModel.GoToModifiedFiles)); d(modifiedButton.BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffModifications).Select(x => x > 0))); d(modifiedButton.BindCaption(this.WhenAnyValue(x => x.ViewModel.DiffModifications).StartWith(0).Select(x => string.Format("{0} modified", x)))); d(allChangesButton.BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffAdditions, x => x.ViewModel.DiffDeletions, x => x.ViewModel.DiffModifications) .Select(x => x.Item1 + x.Item2 + x.Item3 > 0))); d(commentsElement.UrlRequested.InvokeCommand(ViewModel.GoToUrlCommand)); d(this.WhenAnyValue(x => x.ViewModel.ShowMenuCommand) .ToBarButtonItem(UIBarButtonSystemItem.Action, x => NavigationItem.RightBarButtonItem = x)); d(this.WhenAnyValue(x => x.ViewModel.CommitMessageSummary).Subscribe(x => RefreshHeaderView(x))); d(this.WhenAnyValue(x => x.ViewModel.Commit).IsNotNull() .Select(x => "Commited " + x.Commit.Committer.Date.LocalDateTime.Humanize()) .Subscribe(x => RefreshHeaderView(subtext: x))); var statsObs = this.WhenAnyValue(x => x.ViewModel.Commit.Stats); d(additions.BindText(statsObs.Select(x => x != null ? x.Additions.ToString() : "-"))); d(deletions.BindText(statsObs.Select(x => x != null ? x.Deletions.ToString() : "-"))); d(this.WhenAnyValue(x => x.ViewModel.Commit.Parents) .Subscribe(x => parents.Text = x != null ? x.Count.ToString() : "-")); }); }
public override void ViewDidLoad() { base.ViewDidLoad(); var commentsElement = new HtmlElement("comments"); commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan; ViewModel.WhenAnyValue(x => x.Commit).IsNotNull().SubscribeSafe(x => { HeaderView.ImageUri = x.GenerateGravatarUrl(); HeaderView.SubText = "Commited " + x.Commit.Committer.Date.LocalDateTime.Humanize(); RefreshHeaderView(); }); ViewModel.Comments.Changed.Select(_ => new Unit()).StartWith(new Unit()).Subscribe(x => { var commentModels = ViewModel.Comments.Select(c => new Comment(c.User.AvatarUrl, c.User.Login, c.Body, c.CreatedAt.UtcDateTime.Humanize())); var razorView = new CommentsView { Model = commentModels }; var html = razorView.GenerateString(); commentsElement.Value = html; if (commentsElement.GetRootElement() == null && ViewModel.Comments.Count > 0) { _commentSection.Add(commentsElement); } TableView.ReloadData(); }); ViewModel.WhenAnyValue(x => x.Commit).IsNotNull().Subscribe(commitModel => { var detailSection = new Section(); Root.Reset(_headerSection, detailSection); var user = commitModel.GenerateCommiterName(); detailSection.Add(new MultilinedElement(user, commitModel.Commit.Message) { CaptionColor = Theme.MainTextColor, ValueColor = Theme.MainTextColor, BackgroundColor = UIColor.White }); if (ViewModel.ShowRepository) { var repo = new StyledStringElement(ViewModel.RepositoryName) { Accessory = UIKit.UITableViewCellAccessory.DisclosureIndicator, Lines = 1, Font = StyledStringElement.DefaultDetailFont, TextColor = StyledStringElement.DefaultDetailColor, Image = Images.Repo }; repo.Tapped += () => ViewModel.GoToRepositoryCommand.Execute(null); detailSection.Add(repo); } var paths = commitModel.Files.GroupBy(y => { var filename = "/" + y.Filename; return(filename.Substring(0, filename.LastIndexOf("/", System.StringComparison.Ordinal) + 1)); }).OrderBy(y => y.Key); foreach (var p in paths) { var fileSection = new Section(p.Key); foreach (var x in p) { var y = x; var file = x.Filename.Substring(x.Filename.LastIndexOf('/') + 1); var sse = new ChangesetElement(file, x.Status, x.Additions, x.Deletions); sse.Tapped += () => ViewModel.GoToFileCommand.Execute(y); fileSection.Add(sse); } Root.Add(fileSection); } Root.Add(_commentSection); var addComment = new StyledStringElement("Add Comment") { Image = Images.Pencil }; addComment.Tapped += () => ViewModel.GoToCommentCommand.ExecuteIfCan(); Root.Add(new Section { addComment }); }); }
public override void ViewDidLoad() { base.ViewDidLoad(); var headerSection = new Section(); var filesSection = new Section("Files"); var split = new SplitButtonElement(); var files = split.AddButton("Files", "-"); var comments = split.AddButton("Comments", "-"); var forks = split.AddButton("Forks", "-"); headerSection.Add(split); var commentsSection = new Section("Comments") { FooterView = new TableFooterButton("Add Comment", ViewModel.AddCommentCommand.ExecuteIfCan) }; var commentsElement = new HtmlElement("comments"); commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan; commentsSection.Add(commentsElement); var detailsSection = new Section { _splitRow1, _splitRow2 }; Root.Reset(headerSection, detailsSection, filesSection, commentsSection); var updatedGistObservable = ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null); ViewModel.WhenAnyValue(x => x.Gist) .IsNotNull() .Select(x => x.Owner) .Subscribe(x => { if (x == null) { detailsSection.Remove(_ownerElement); } else if (x != null && !detailsSection.Contains(_ownerElement)) { detailsSection.Add(_ownerElement); } }); updatedGistObservable.SubscribeSafe(x => { if (x.Owner == null) { _ownerElement.Value = "Anonymous"; _ownerElement.Accessory = UITableViewCellAccessory.None; } else { _ownerElement.Value = x.Owner.Login; _ownerElement.Accessory = UITableViewCellAccessory.DisclosureIndicator; } Root.Reload(_ownerElement); }); updatedGistObservable.SubscribeSafe(x => { HeaderView.SubText = x.Description; if (x.Owner != null) { HeaderView.ImageUri = x.Owner.AvatarUrl; } else { HeaderView.Image = Images.LoginUserUnknown; } TableView.ReloadData(); }); updatedGistObservable.Select(x => x.Files == null ? 0 : x.Files.Count()).SubscribeSafe(x => files.Text = x.ToString()); updatedGistObservable.SubscribeSafe(x => comments.Text = x.Comments.ToString()); updatedGistObservable.Select(x => x.Forks == null ? 0 : x.Forks.Count()).SubscribeSafe(x => forks.Text = x.ToString()); updatedGistObservable.Subscribe(x => { var elements = new List <Element>(); foreach (var file in x.Files.Keys) { var sse = new StyledStringElement(file, x.Files[file].Size + " bytes", UITableViewCellStyle.Subtitle) { Accessory = UITableViewCellAccessory.DisclosureIndicator, LineBreakMode = UILineBreakMode.TailTruncation, Lines = 1 }; sse.Tapped += () => ViewModel.GoToFileSourceCommand.Execute(x.Files[file]); elements.Add(sse); } filesSection.Reset(elements); }); ViewModel.Comments.Changed.Subscribe(_ => { var commentModels = ViewModel.Comments .Select(x => new Comment(x.User.AvatarUrl, x.User.Login, x.BodyHtml, x.CreatedAt.UtcDateTime.Humanize())) .ToList(); if (commentModels.Count > 0) { var razorView = new CommentsView { Model = commentModels }; var html = razorView.GenerateString(); commentsElement.Value = html; if (!commentsSection.Contains(commentsElement)) { commentsSection.Insert(0, UITableViewRowAnimation.Fade, commentsElement); } } else { commentsSection.Remove(commentsElement); } }); }
public override void ViewDidLoad() { base.ViewDidLoad(); var updatedGistObservable = ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null); var headerSection = new Section(HeaderView); var filesSection = new Section("Files"); var split = new SplitButtonElement(); var files = split.AddButton("Files", "-"); var comments = split.AddButton("Comments", "-"); var forks = split.AddButton("Forks", "-"); headerSection.Add(split); var commentsSection = new Section("Comments"); var commentsElement = new WebElement("comments"); commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan; commentsSection.Add(commentsElement); var detailsSection = new Section(); var splitElement1 = new SplitElement(); splitElement1.Button1 = new SplitElement.SplitButton(Images.Locked, string.Empty); splitElement1.Button2 = new SplitElement.SplitButton(Images.Language, string.Empty); detailsSection.Add(splitElement1); var splitElement2 = new SplitElement(); splitElement2.Button1 = new SplitElement.SplitButton(Images.Update, string.Empty); splitElement2.Button2 = new SplitElement.SplitButton(Images.Star2, string.Empty); detailsSection.Add(splitElement2); var owner = new StyledStringElement("Owner", string.Empty) { Image = Images.Person }; owner.Tapped += () => ViewModel.GoToUserCommand.ExecuteIfCan(); detailsSection.Add(owner); updatedGistObservable.SubscribeSafe(x => { var publicGist = x.Public.HasValue && x.Public.Value; var revisionCount = x.History == null ? 0 : x.History.Count; splitElement1.Button1.Text = publicGist ? "Public" : "Private"; splitElement1.Button1.Image = publicGist ? Images.Unlocked : Images.Locked; splitElement1.Button2.Text = revisionCount + " Revisions"; splitElement2.Button1.Text = x.UpdatedAt.ToLocalTime().ToString("MM/dd/yy"); }); updatedGistObservable.SubscribeSafe(x => { if (x.Owner == null) { owner.Value = "Anonymous"; owner.Accessory = UITableViewCellAccessory.None; } else { owner.Value = x.Owner.Login; owner.Accessory = UITableViewCellAccessory.DisclosureIndicator; } Root.Reload(owner); }); ViewModel.WhenAnyValue(x => x.IsStarred).Where(x => x.HasValue).Subscribe(x => { splitElement2.Button2.Text = x.Value ? "Starred!" : "Unstarred"; splitElement2.Button2.Image = x.Value ? Images.Star : Images.Star2; }); Root.Reset(headerSection, detailsSection, filesSection); updatedGistObservable.SubscribeSafe(x => { HeaderView.SubText = x.Description; if (x.Owner != null) { HeaderView.ImageUri = x.Owner.AvatarUrl; } Root.Reload(headerSection); }); updatedGistObservable.Select(x => x.Files == null ? 0 : x.Files.Count()).SubscribeSafe(x => files.Text = x.ToString()); updatedGistObservable.SubscribeSafe(x => comments.Text = x.Comments.ToString()); updatedGistObservable.Select(x => x.Forks == null ? 0 : x.Forks.Count()).SubscribeSafe(x => forks.Text = x.ToString()); updatedGistObservable.Subscribe(x => { var elements = new List <Element>(); foreach (var file in x.Files.Keys) { var sse = new StyledStringElement(file, x.Files[file].Size + " bytes", UITableViewCellStyle.Subtitle) { Accessory = UITableViewCellAccessory.DisclosureIndicator, LineBreakMode = UILineBreakMode.TailTruncation, Lines = 1 }; var fileSaved = file; var gistFileModel = x.Files[fileSaved]; // if (string.Equals(gistFileModel.Language, "markdown", StringComparison.OrdinalIgnoreCase)) // sse.Tapped += () => ViewModel.GoToViewableFileCommand.Execute(gistFileModel); // else sse.Tapped += () => ViewModel.GoToFileSourceCommand.Execute(gistFileModel); elements.Add(sse); } filesSection.Reset(elements); }); // // updatedGistObservable.Take(1).Subscribe(_ => Root.Add(filesSection)); ViewModel.Comments.Changed.Subscribe(_ => { var commentModels = ViewModel.Comments.Select(x => new Comment(x.User.AvatarUrl, x.User.Login, x.BodyHtml, x.CreatedAt.ToDaysAgo())); var razorView = new CommentsView { Model = commentModels }; var html = razorView.GenerateString(); commentsElement.Value = html; }); ViewModel.Comments.Changed.Take(1).Select(x => ViewModel.Comments).Where(x => x.Count > 0) .Subscribe(_ => Root.Insert(Root.Count, commentsSection)); ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null).Subscribe(gist => { if (string.Equals(_applicationService.Account.Username, ViewModel.Gist.Owner.Login, StringComparison.OrdinalIgnoreCase)) { NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Compose, (s, e) => { }); // try // { // var data = await this.DoWorkAsync("Loading...", () => app.Client.ExecuteAsync(app.Client.Gists[ViewModel.Id].Get())); // var gistController = new EditGistController(data.Data); // gistController.Created = editedGist => ViewModel.Gist = editedGist; // var navController = new UINavigationController(gistController); // PresentViewController(navController, true, null); // // } // catch (Exception ex) // { // MonoTouch.Utilities.ShowAlert("Error", ex.Message); // } } else { NavigationItem.RightBarButtonItem = new UIBarButtonItem(Theme.CurrentTheme.ForkButton, UIBarButtonItemStyle.Plain, (s, e) => ViewModel.ForkCommand.ExecuteIfCan()); NavigationItem.RightBarButtonItem.EnableIfExecutable(ViewModel.ForkCommand.CanExecuteObservable); } }); ViewModel.ForkCommand.IsExecuting.Subscribe(x => { if (x) { _statusIndicatorService.Show("Forking..."); } else { _statusIndicatorService.Hide(); } }); }
public override void ViewDidLoad() { base.ViewDidLoad(); HeaderView.Image = Images.LoginUserUnknown; var split = new SplitButtonElement(); var headerSection = new Section { split }; var descriptionElement = new MultilinedElement(); var detailsSection = new Section(); var commentsSection = new Section(null, new TableFooterButton("Add Comment", () => ViewModel.AddCommentCommand.ExecuteIfCan())); var additions = split.AddButton("Additions"); var deletions = split.AddButton("Deletions"); var parents = split.AddButton("Parents"); var gotoRepositoryElement = new StringElement(string.Empty) { Font = StringElement.DefaultDetailFont, TextColor = StringElement.DefaultDetailColor, Image = Octicon.Repo.ToImage() }; gotoRepositoryElement.Tapped += () => ViewModel.GoToRepositoryCommand.ExecuteIfCan(); detailsSection.Add( new StringElement(Octicon.DiffAdded.ToImage()) .BindCommand(() => ViewModel.GoToAddedFiles) .BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffAdditions).Select(x => x > 0)) .BindCaption(this.WhenAnyValue(x => x.ViewModel.DiffAdditions).StartWith(0).Select(x => string.Format("{0} added", x)))); detailsSection.Add( new StringElement(Octicon.DiffRemoved.ToImage()) .BindCommand(() => ViewModel.GoToRemovedFiles) .BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffDeletions).Select(x => x > 0)) .BindCaption(this.WhenAnyValue(x => x.ViewModel.DiffDeletions).StartWith(0).Select(x => string.Format("{0} removed", x)))); detailsSection.Add( new StringElement(Octicon.DiffModified.ToImage()) .BindCommand(() => ViewModel.GoToModifiedFiles) .BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffModifications).Select(x => x > 0)) .BindCaption(this.WhenAnyValue(x => x.ViewModel.DiffModifications).StartWith(0).Select(x => string.Format("{0} modified", x)))); detailsSection.Add(new StringElement("All Changes", () => ViewModel.GoToAllFiles.ExecuteIfCan(), Octicon.Diff.ToImage())); var commentsElement = new HtmlElement("comments"); commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan; ViewModel.Comments.Changed .Select(_ => new Unit()) .StartWith(new Unit()) .Subscribe(x => { var comments = ViewModel.Comments.Select(c => new Comment(c.Avatar.ToUri(), c.Actor, c.Body, c.UtcCreatedAt.Humanize())).ToList(); var commentModel = new CodeHub.WebViews.CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize); var razorView = new CommentsView { Model = commentModel }; var html = razorView.GenerateString(); commentsElement.Value = html; if (commentsElement.GetRootElement() == null && ViewModel.Comments.Count > 0) { commentsSection.Add(commentsElement); } TableView.ReloadData(); }); this.WhenAnyValue(x => x.ViewModel.Commit) .IsNotNull() .Take(1) .Subscribe(_ => Root.Reset(headerSection, detailsSection, commentsSection)); Appeared .Take(1) .Select(_ => this.WhenAnyValue(x => x.ViewModel.CommitMessage, y => y.ViewModel.CommiterName)) .Switch() .Where(x => x.Item1 != null && x.Item2 != null) .Take(1) .Subscribe(_ => detailsSection.Insert(0, UITableViewRowAnimation.Automatic, descriptionElement)); this.WhenAnyValue(x => x.ViewModel.CommiterName) .Subscribe(x => descriptionElement.Caption = x ?? string.Empty); this.WhenAnyValue(x => x.ViewModel.CommitMessage) .Subscribe(x => descriptionElement.Details = x ?? string.Empty); this.WhenAnyValue(x => x.ViewModel.RepositoryName) .Subscribe(x => gotoRepositoryElement.Caption = x); this.WhenAnyValue(x => x.ViewModel.ShowRepository) .StartWith(false) .Where(x => x) .Take(1) .Subscribe(x => detailsSection.Add(gotoRepositoryElement)); this.WhenAnyValue(x => x.ViewModel.Commit) .SubscribeSafe(x => { additions.Text = x != null ? x.Stats.Additions.ToString() : "-"; deletions.Text = x != null ? x.Stats.Deletions.ToString() : "-"; parents.Text = x != null ? x.Parents.Count.ToString() : "-"; }); this.WhenAnyValue(x => x.ViewModel.ShowMenuCommand) .Select(x => x.ToBarButtonItem(UIBarButtonSystemItem.Action)) .Subscribe(x => NavigationItem.RightBarButtonItem = x); this.WhenAnyValue(x => x.ViewModel.CommitMessageSummary) .Subscribe(x => { HeaderView.Text = x; RefreshHeaderView(); }); this.WhenAnyValue(x => x.ViewModel.Avatar) .Subscribe(x => HeaderView.SetImage(x?.ToUri(128), Images.LoginUserUnknown)); this.WhenAnyValue(x => x.ViewModel.Commit) .IsNotNull() .Subscribe(x => { HeaderView.SubText = "Commited " + x.Commit.Committer.Date.LocalDateTime.Humanize(); RefreshHeaderView(); }); }
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)); }))); }); }
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 commentsSection = new Section() { FooterView = new TableFooterButton("Add Comment", ViewModel.AddCommentCommand.ExecuteIfCan) }; var commentsElement = new HtmlElement("comments"); commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan; commentsSection.Add(commentsElement); var detailsSection = new Section { _splitRow1, _splitRow2 }; Root.Reset(headerSection, detailsSection, filesSection, commentsSection); var updatedGistObservable = ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null); ViewModel.WhenAnyValue(x => x.Gist) .IsNotNull() .Select(x => x.Owner) .Subscribe(x => { if (x == null) { detailsSection.Remove(_ownerElement); } else if (x != null && !detailsSection.Contains(_ownerElement)) { detailsSection.Add(_ownerElement); } }); updatedGistObservable .Select(x => x?.Owner?.Login ?? "Anonymous") .Subscribe(x => _ownerElement.Value = x); updatedGistObservable .Select(x => x.Owner != null ? () => ViewModel.GoToOwnerCommand.ExecuteIfCan() : (Action)null) .SubscribeSafe(x => _ownerElement.Tapped = x); this.WhenAnyValue(x => x.ViewModel.Avatar) .Subscribe(x => HeaderView.SetImage(x?.ToUri(64), Images.LoginUserUnknown)); updatedGistObservable.SubscribeSafe(x => { HeaderView.SubText = x.Description; RefreshHeaderView(); }); updatedGistObservable.Select(x => x.Files == null ? 0 : x.Files.Count()).SubscribeSafe(x => files.Text = x.ToString()); updatedGistObservable.SubscribeSafe(x => comments.Text = x.Comments.ToString()); updatedGistObservable.Select(x => x.Forks == null ? 0 : x.Forks.Count()).SubscribeSafe(x => forks.Text = x.ToString()); updatedGistObservable.Subscribe(x => { var elements = new List <Element>(); foreach (var file in x.Files.Keys) { var sse = new StringElement(file); sse.Image = Octicon.FileCode.ToImage(); sse.Tapped += () => ViewModel.GoToFileSourceCommand.Execute(x.Files[file]); elements.Add(sse); } filesSection.Reset(elements); }); 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); } }); }
public override void ViewDidLoad() { base.ViewDidLoad(); var headerSection = new Section(HeaderView); var filesSection = new Section("Files"); var split = new SplitButtonElement(); var files = split.AddButton("Files", "-"); var comments = split.AddButton("Comments", "-"); var forks = split.AddButton("Forks", "-"); headerSection.Add(split); var commentsSection = new Section("Comments"); var commentsElement = new WebElement("comments"); commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan; commentsSection.Add(commentsElement); var detailsSection = new Section(); var splitElement1 = new SplitElement(); splitElement1.Button1 = new SplitElement.SplitButton(Images.Locked, string.Empty); splitElement1.Button2 = new SplitElement.SplitButton(Images.Language, string.Empty); detailsSection.Add(splitElement1); var splitElement2 = new SplitElement(); splitElement2.Button1 = new SplitElement.SplitButton(Images.Update, string.Empty); splitElement2.Button2 = new SplitElement.SplitButton(Images.Star2, string.Empty, ViewModel.ToggleStarCommand.ExecuteIfCan); detailsSection.Add(splitElement2); var owner = new StyledStringElement("Owner", string.Empty) { Image = Images.Person }; owner.Tapped += () => ViewModel.GoToUserCommand.ExecuteIfCan(); var addComment = new StyledStringElement("Add Comment", ViewModel.AddCommentCommand.ExecuteIfCan, Images.Pencil); commentsSection.Add(addComment); Root.Reset(headerSection, detailsSection, filesSection, commentsSection); var updatedGistObservable = ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null); ViewModel.WhenAnyValue(x => x.Gist).IsNotNull().Select(x => x.Owner).Subscribe(x => { if (x == null) { detailsSection.Remove(owner); } else if (x != null && !detailsSection.Contains(owner)) { detailsSection.Add(owner); } }); updatedGistObservable.SubscribeSafe(x => { var publicGist = x.Public.HasValue && x.Public.Value; var revisionCount = x.History == null ? 0 : x.History.Count; splitElement1.Button1.Text = publicGist ? "Public" : "Private"; splitElement1.Button1.Image = publicGist ? Images.Unlocked : Images.Locked; splitElement1.Button2.Text = revisionCount + " Revisions"; splitElement2.Button1.Text = x.UpdatedAt.ToLocalTime().ToString("MM/dd/yy"); }); updatedGistObservable.SubscribeSafe(x => { if (x.Owner == null) { owner.Value = "Anonymous"; owner.Accessory = UITableViewCellAccessory.None; } else { owner.Value = x.Owner.Login; owner.Accessory = UITableViewCellAccessory.DisclosureIndicator; } Root.Reload(owner); }); ViewModel.WhenAnyValue(x => x.IsStarred).Where(x => x.HasValue).Subscribe(x => { splitElement2.Button2.Text = x.Value ? "Starred!" : "Unstarred"; splitElement2.Button2.Image = x.Value ? Images.Star : Images.Star2; }); updatedGistObservable.SubscribeSafe(x => { HeaderView.SubText = x.Description; if (x.Owner != null) { HeaderView.ImageUri = x.Owner.AvatarUrl; } else { HeaderView.Image = Images.LoginUserUnknown; } ReloadData(); }); updatedGistObservable.Select(x => x.Files == null ? 0 : x.Files.Count()).SubscribeSafe(x => files.Text = x.ToString()); updatedGistObservable.SubscribeSafe(x => comments.Text = x.Comments.ToString()); updatedGistObservable.Select(x => x.Forks == null ? 0 : x.Forks.Count()).SubscribeSafe(x => forks.Text = x.ToString()); updatedGistObservable.Subscribe(x => { var elements = new List <Element>(); foreach (var file in x.Files.Keys) { var sse = new StyledStringElement(file, x.Files[file].Size + " bytes", UITableViewCellStyle.Subtitle) { Accessory = UITableViewCellAccessory.DisclosureIndicator, LineBreakMode = UILineBreakMode.TailTruncation, Lines = 1 }; sse.Tapped += () => ViewModel.GoToFileSourceCommand.Execute(x.Files[file]); elements.Add(sse); } filesSection.Reset(elements); }); ViewModel.Comments.Changed.Subscribe(_ => { var commentModels = ViewModel.Comments .Select(x => new Comment(x.User.AvatarUrl, x.User.Login, x.BodyHtml, x.CreatedAt.ToDaysAgo())) .ToList(); if (commentModels.Count > 0) { var razorView = new CommentsView { Model = commentModels }; var html = razorView.GenerateString(); commentsElement.Value = html; if (!commentsSection.Contains(commentsElement)) { commentsSection.Insert(0, UITableViewRowAnimation.Fade, commentsElement); } } else { commentsSection.Remove(commentsElement); } }); }
public override void ViewDidLoad() { base.ViewDidLoad(); var secDetails = new Section(); var commentsSection = new Section(null, new TableFooterButton("Add Comment", () => ViewModel.AddCommentCommand.ExecuteIfCan())); var commentsElement = new HtmlElement("comments"); commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan; var descriptionElement = new HtmlElement("description"); descriptionElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan; secDetails.Add(_milestoneElement); secDetails.Add(_assigneeElement); secDetails.Add(_labelsElement); var addCommentElement = new StyledStringElement("Add Comment") { Image = Images.Pencil }; this.WhenViewModel(x => x.MarkdownDescription).Subscribe(x => { if (string.IsNullOrEmpty(x)) { secDetails.Remove(descriptionElement); } else { var markdown = new DescriptionView { Model = x }; var html = markdown.GenerateString(); descriptionElement.Value = html; if (!secDetails.Contains(descriptionElement)) { secDetails.Insert(0, UITableViewRowAnimation.Fade, descriptionElement); } } }); ViewModel.Events.Changed.Subscribe(_ => { var commentModels = ViewModel.Events .Select(x => { var body = string.Empty; var comment = x as IssueCommentItemViewModel; var @event = x as IssueEventItemViewModel; if (comment != null) { body = comment.Comment; } else if (@event != null) { body = CreateEventBody(@event.EventInfo, @event.Commit); } return(new Comment(x.AvatarUrl, x.Actor, body, x.CreatedAt.LocalDateTime.Humanize())); }) .Where(x => !string.IsNullOrEmpty(x.Body)) .ToList(); if (commentModels.Count > 0) { var razorView = new CommentsView { Model = commentModels }; var html = razorView.GenerateString(); commentsElement.Value = html; if (!commentsSection.Contains(commentsElement)) { commentsSection.Insert(0, UITableViewRowAnimation.Fade, commentsElement); } } else { commentsSection.Remove(commentsElement); } }); Root.Reset(new Section(), secDetails, commentsSection); }