public override void ViewDidLoad() { base.ViewDidLoad(); var typeElement = new StringElement("Type", string.Empty, UITableViewCellStyle.Value1); var stateElement = new StringElement("State", string.Empty, UITableViewCellStyle.Value1); var fieldElement = new StringElement("Field", string.Empty, UITableViewCellStyle.Value1); var ascElement = new BooleanElement("Ascending"); var labelElement = new EntryElement("Labels", "bug,ui,@user", string.Empty) { TextAlignment = UITextAlignment.Right, AutocorrectionType = UITextAutocorrectionType.No, AutocapitalizationType = UITextAutocapitalizationType.None }; var filterSection = new Section("Filter") { typeElement, stateElement, labelElement }; var orderSection = new Section("Order By") { fieldElement, ascElement }; var searchSection = new Section(); var footerButton = new TableFooterButton("Search!"); searchSection.FooterView = footerButton; var source = new DialogTableViewSource(TableView); TableView.Source = source; source.Root.Add(filterSection, orderSection, searchSection); OnActivation(d => { d(typeElement.Clicked.InvokeCommand(ViewModel.SelectFilterTypeCommand)); d(stateElement.Clicked.InvokeCommand(ViewModel.SelectStateCommand)); d(fieldElement.Clicked.InvokeCommand(ViewModel.SelectSortCommand)); d(footerButton.Clicked.InvokeCommand(ViewModel.SaveCommand)); d(ascElement.Changed.Subscribe(x => ViewModel.Ascending = x)); d(labelElement.Changed.Subscribe(x => ViewModel.Labels = x)); d(this.WhenAnyValue(x => x.ViewModel.FilterType).Subscribe(x => typeElement.Value = x.Humanize())); d(this.WhenAnyValue(x => x.ViewModel.State).Subscribe(x => stateElement.Value = x.Humanize())); d(this.WhenAnyValue(x => x.ViewModel.Labels).Subscribe(x => labelElement.Value = x)); d(this.WhenAnyValue(x => x.ViewModel.SortType).Subscribe(x => fieldElement.Value = x.Humanize())); d(this.WhenAnyValue(x => x.ViewModel.Ascending).Subscribe(x => ascElement.Value = x)); d(this.WhenAnyValue(x => x.ViewModel.DismissCommand) .ToBarButtonItem(Images.Cancel, x => NavigationItem.LeftBarButtonItem = x)); d(this.WhenAnyValue(x => x.ViewModel.SaveCommand) .ToBarButtonItem(Images.Search, x => NavigationItem.RightBarButtonItem = x)); }); }
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(); 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)); }))); }); }
protected BaseIssueViewController() { CommentsElement = new HtmlElement("comments"); DescriptionElement = new HtmlElement("description"); 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 ButtonElement("Milestone", Octicon.Milestone.ToImage()); this.WhenAnyValue(x => x.ViewModel.AssignedMilestone) .Select(x => x == null ? "No Milestone" : x.Title) .Subscribe(x => MilestoneElement.Value = x); AssigneeElement = new ButtonElement("Assigned", Octicon.Person.ToImage()); this.WhenAnyValue(x => x.ViewModel.AssignedUser) .Select(x => x == null ? "Unassigned" : x.Login) .Subscribe(x => AssigneeElement.Value = x); LabelsElement = new ButtonElement("Labels", Octicon.Tag.ToImage()); 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); 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); } } }); var footerButton = new TableFooterButton("Add Comment"); CommentsSection.FooterView = footerButton; 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()); this.WhenAnyObservable(x => x.ViewModel.CommentAdded) .Select(_ => Appeared.Take(1)) .Switch() .Delay(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler) .SubscribeSafe(_ => TableView.SetContentOffset(new CoreGraphics.CGPoint(0, TableView.ContentSize.Height - TableView.Bounds.Height), true)); OnActivation(d => { d(MilestoneElement.BindCommand(ViewModel.GoToMilestonesCommand)); d(AssigneeElement.BindCommand(ViewModel.GoToAssigneesCommand)); d(LabelsElement.BindCommand(ViewModel.GoToLabelsCommand)); var canModify = this.WhenAnyValue(x => x.ViewModel.CanModify); d(MilestoneElement.BindDisclosure(canModify)); d(AssigneeElement.BindDisclosure(canModify)); d(LabelsElement.BindDisclosure(canModify)); d(footerButton.Clicked.InvokeCommand(ViewModel.AddCommentCommand)); d(HeaderView.Clicked.InvokeCommand(ViewModel.GoToOwnerCommand)); d(this.WhenAnyValue(x => x.ViewModel.ShowMenuCommand) .ToBarButtonItem(UIBarButtonSystemItem.Action, x => NavigationItem.RightBarButtonItem = x)); d(CommentsElement.UrlRequested.InvokeCommand(ViewModel.GoToUrlCommand)); d(DescriptionElement.UrlRequested.InvokeCommand(ViewModel.GoToUrlCommand)); d(this.WhenAnyObservable(x => x.ViewModel.GoToAssigneesCommand) .Subscribe(_ => IssueAssigneeViewController.Show(this, ViewModel.CreateAssigneeViewModel()))); d(this.WhenAnyObservable(x => x.ViewModel.GoToMilestonesCommand) .Subscribe(_ => IssueMilestonesViewController.Show(this, ViewModel.CreateMilestonesViewModel()))); d(this.WhenAnyObservable(x => x.ViewModel.GoToLabelsCommand) .Subscribe(_ => IssueLabelsViewController.Show(this, ViewModel.CreateLabelsViewModel()))); }); }
public override void ViewDidLoad() { base.ViewDidLoad(); var source = new DialogTableViewSource(TableView); TableView.Source = source; var mentionedElement = new EntryElement("Mentioned", "username", string.Empty) { TextAlignment = UITextAlignment.Right, AutocorrectionType = UITextAutocorrectionType.No, AutocapitalizationType = UITextAutocapitalizationType.None }; var creatorElement = new EntryElement("Creator", "username", string.Empty) { TextAlignment = UITextAlignment.Right, AutocorrectionType = UITextAutocorrectionType.No, AutocapitalizationType = UITextAutocapitalizationType.None }; var stateElement = new ButtonElement("State"); var labelElement = new ButtonElement("Labels"); var assigneeElement = new ButtonElement("Assignee"); var milestoneElement = new ButtonElement("Milestone"); var fieldElement = new ButtonElement("Field"); var ascElement = new BooleanElement("Ascending"); var filterSection = new Section("Filter") { stateElement, mentionedElement, creatorElement, labelElement, assigneeElement, milestoneElement }; var orderSection = new Section("Order By") { fieldElement, ascElement }; var searchSection = new Section(); var footerButton = new TableFooterButton("Search!"); searchSection.FooterView = footerButton; source.Root.Add(filterSection, orderSection, searchSection); OnActivation(d => { d(assigneeElement.Clicked.InvokeCommand(ViewModel.SelectAssigneeCommand)); d(milestoneElement.Clicked.InvokeCommand(ViewModel.SelectMilestoneCommand)); d(fieldElement.Clicked.InvokeCommand(ViewModel.SelectSortCommand)); d(stateElement.Clicked.InvokeCommand(ViewModel.SelectStateCommand)); d(labelElement.Clicked.InvokeCommand(ViewModel.SelectLabelsCommand)); d(footerButton.Clicked.InvokeCommand(ViewModel.SaveCommand)); d(ascElement.Changed.Subscribe(x => ViewModel.Ascending = x)); d(mentionedElement.Changed.Subscribe(x => ViewModel.Mentioned = x)); d(creatorElement.Changed.Subscribe(x => ViewModel.Creator = x)); d(this.WhenAnyValue(x => x.ViewModel.DismissCommand) .ToBarButtonItem(Images.Cancel, x => NavigationItem.LeftBarButtonItem = x)); d(this.WhenAnyValue(x => x.ViewModel.SaveCommand) .ToBarButtonItem(Images.Search, x => NavigationItem.RightBarButtonItem = x)); d(this.WhenAnyValue(x => x.ViewModel.State).Subscribe(x => stateElement.Value = x.Humanize())); d(this.WhenAnyValue(x => x.ViewModel.LabelsString).Subscribe(x => labelElement.Value = x)); d(this.WhenAnyValue(x => x.ViewModel.Mentioned).Subscribe(x => mentionedElement.Value = x)); d(this.WhenAnyValue(x => x.ViewModel.Creator).Subscribe(x => creatorElement.Value = x)); d(this.WhenAnyValue(x => x.ViewModel.AssigneeString).Subscribe(x => assigneeElement.Value = x)); d(this.WhenAnyValue(x => x.ViewModel.MilestoneString).Subscribe(x => milestoneElement.Value = x)); d(this.WhenAnyValue(x => x.ViewModel.SortType).Subscribe(x => fieldElement.Value = x.Humanize())); d(this.WhenAnyValue(x => x.ViewModel.Ascending).Subscribe(x => ascElement.Value = x)); d(this.WhenAnyObservable(x => x.ViewModel.SelectAssigneeCommand) .Subscribe(_ => IssueAssigneeViewController.Show(this, ViewModel.CreateAssigneeViewModel()))); d(this.WhenAnyObservable(x => x.ViewModel.SelectMilestoneCommand) .Subscribe(_ => IssueMilestonesViewController.Show(this, ViewModel.CreateMilestonesViewModel()))); d(this.WhenAnyObservable(x => x.ViewModel.SelectLabelsCommand) .Subscribe(_ => IssueLabelsViewController.Show(this, ViewModel.CreateLabelsViewModel()))); }); }