public void Render() { if (ViewModel.PullRequest == null) return; var avatarUrl = ViewModel.PullRequest.Author?.Links?.Avatar?.Href; HeaderView.Text = ViewModel.PullRequest.Title; HeaderView.SubText = "Updated " + ViewModel.PullRequest.UpdatedOn.Humanize(); HeaderView.SetImage(new Avatar(avatarUrl).ToUrl(128), Images.Avatar); RefreshHeaderView(); var split = new SplitButtonElement(); split.AddButton("Comments", ViewModel.Comments.Items.Count.ToString()); split.AddButton("Participants", ViewModel.PullRequest.Participants.Count.ToString()); var root = new RootElement(Title); root.Add(new Section { split }); var secDetails = new Section(); if (!string.IsNullOrEmpty(ViewModel.PullRequest.Description)) { var desc = new MultilinedElement(ViewModel.PullRequest.Description.Trim()) { BackgroundColor = UIColor.White, CaptionColor = Theme.CurrentTheme.MainTitleColor, ValueColor = Theme.CurrentTheme.MainTextColor }; desc.CaptionFont = desc.ValueFont; desc.CaptionColor = desc.ValueColor; secDetails.Add(desc); } var merged = ViewModel.Merged; _split1.Value.Text1 = ViewModel.PullRequest.CreatedOn.ToString("MM/dd/yy"); _split1.Value.Text2 = merged ? "Merged" : "Not Merged"; secDetails.Add(_split1); root.Add(secDetails); root.Add(new Section { new StyledStringElement("Commits", () => ViewModel.GoToCommitsCommand.Execute(null), Images.Commit), }); if (!merged) { Action mergeAction = async () => { try { await this.DoWorkAsync("Merging...", ViewModel.Merge); } catch (Exception e) { MonoTouch.Utilities.ShowAlert("Unable to Merge", e.Message); } }; root.Add(new Section { new StyledStringElement("Merge", mergeAction, Images.Fork) }); } if (ViewModel.Comments.Items.Count > 0) { var commentsSec = new Section(); foreach (var x in ViewModel.Comments.Where(x => !string.IsNullOrEmpty(x.Content.Raw) && x.Inline == null).OrderBy(x => (x.CreatedOn))) { var name = x.User.DisplayName ?? x.User.Username ?? "Unknown"; var avatar = new Avatar(x.User.Links?.Avatar?.Href); commentsSec.Add(new NameTimeStringElement(name, x.Content.Raw, x.CreatedOn, avatar.ToUrl(), Images.Avatar)); } //Load more if there's more comments // if (model.MoreComments != null) // { // var loadMore = new PaginateElement("Load More", "Loading...", // e => this.DoWorkNoHud(() => model.MoreComments(), // x => Utilities.ShowAlert("Unable to load more!", x.Message))) { AutoLoadOnVisible = false, Background = false }; // commentsSec.Add(loadMore); // } if (commentsSec.Elements.Count > 0) root.Add(commentsSec); } var addComment = new StyledStringElement("Add Comment") { Image = Images.Pencil }; addComment.Tapped += AddCommentTapped; root.Add(new Section { addComment }); Root = root; }
public override void ViewDidLoad() { base.ViewDidLoad(); _hud = this.CreateHud(); NavigationItem.RightBarButtonItem = new UIBarButtonItem(Theme.CurrentTheme.SaveButton, UIBarButtonItemStyle.Plain, (s, e) => { View.EndEditing(true); ViewModel.SaveCommand.Execute(null); }); var title = new InputElement("Title", string.Empty, string.Empty) { TextAlignment = UITextAlignment.Right }; title.Changed += (object sender, EventArgs e) => ViewModel.Title = title.Value; var assignedTo = new StyledStringElement("Responsible", "Unassigned", UITableViewCellStyle.Value1); assignedTo.Accessory = UITableViewCellAccessory.DisclosureIndicator; assignedTo.Tapped += () => ViewModel.GoToAssigneeCommand.Execute(null); var kind = new StyledStringElement("Issue Type", ViewModel.Kind, UITableViewCellStyle.Value1); kind.Accessory = UITableViewCellAccessory.DisclosureIndicator; kind.Tapped += () => { var ctrl = new IssueAttributesView(IssueModifyViewModel.Kinds, ViewModel.Kind) { Title = "Issue Type" }; ctrl.SelectedValue = x => ViewModel.Kind = x.ToLower(); NavigationController.PushViewController(ctrl, true); }; var priority = new StyledStringElement("Priority", ViewModel.Priority, UITableViewCellStyle.Value1); priority.Accessory = UITableViewCellAccessory.DisclosureIndicator; priority.Tapped += () => { var ctrl = new IssueAttributesView(IssueModifyViewModel.Priorities, ViewModel.Priority) { Title = "Priority" }; ctrl.SelectedValue = x => ViewModel.Priority = x.ToLower(); NavigationController.PushViewController(ctrl, true); }; var milestone = new StyledStringElement("Milestone", "None", UITableViewCellStyle.Value1); milestone.Accessory = UITableViewCellAccessory.DisclosureIndicator; milestone.Tapped += () => ViewModel.GoToMilestonesCommand.Execute(null); var component = new StyledStringElement("Component", "None", UITableViewCellStyle.Value1); component.Accessory = UITableViewCellAccessory.DisclosureIndicator; component.Tapped += () => ViewModel.GoToComponentsCommand.Execute(null); var version = new StyledStringElement("Version", "None", UITableViewCellStyle.Value1); version.Accessory = UITableViewCellAccessory.DisclosureIndicator; version.Tapped += () => ViewModel.GoToVersionsCommand.Execute(null); var content = new MultilinedElement("Description"); content.Tapped += () => { var composer = new Composer { Title = "Issue Description", Text = content.Value }; composer.NewComment(this, (text) => { ViewModel.Content = text; composer.CloseComposer(); }); }; ViewModel.Bind(x => x.IsSaving, x => { if (x) _hud.Show("Saving..."); else _hud.Hide(); }); Root = new RootElement(Title) { new Section { title, assignedTo, kind, priority }, new Section { milestone, component, version }, new Section { content } }; ViewModel.Bind(x => x.Title, x => { title.Value = x; Root.Reload(title, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.AssignedTo, x => { assignedTo.Value = x == null ? "Unassigned" : x.Username; Root.Reload(assignedTo, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.Kind, x => { kind.Value = x; Root.Reload(kind, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.Priority, x => { priority.Value = x; Root.Reload(priority, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.Milestone, x => { milestone.Value = x ?? "None"; Root.Reload(milestone, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.Component, x => { component.Value = x ?? "None"; Root.Reload(component, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.Version, x => { version.Value = x ?? "None"; Root.Reload(version, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.Content, x => { content.Value = x; Root.Reload(content, UITableViewRowAnimation.None); }, true); }
public void Render(RepositoryDetailedModel model) { Title = model.Name; var avatar = new Avatar(model.Logo).ToUrl(128); var root = new RootElement(Title) { UnevenRows = true }; HeaderView.SubText = "Updated " + model.UtcLastUpdated.Humanize(); HeaderView.SetImage(avatar, Images.RepoPlaceholder); RefreshHeaderView(); var split = new SplitButtonElement(); split.AddButton("Followers", model.FollowersCount.ToString()); split.AddButton("Forks", model.ForkCount.ToString()); var sec1 = new Section(); if (!string.IsNullOrEmpty(model.Description) && !string.IsNullOrWhiteSpace(model.Description)) { var element = new MultilinedElement(model.Description) { BackgroundColor = UIColor.White, CaptionColor = Theme.CurrentTheme.MainTitleColor, ValueColor = Theme.CurrentTheme.MainTextColor }; element.CaptionColor = element.ValueColor; element.CaptionFont = element.ValueFont; sec1.Add(element); } sec1.Add(new SplitElement(new SplitElement.Row { Text1 = model.IsPrivate ? "Private" : "Public", Image1 = model.IsPrivate ? Images.Locked : Images.Unlocked, Text2 = string.IsNullOrEmpty(model.Language) ? "N/A" : model.Language, Image2 = Images.Language })); //Calculate the best representation of the size string size; if (model.Size / 1024f < 1) size = string.Format("{0:0.##}B", model.Size); else if ((model.Size / 1024f / 1024f) < 1) size = string.Format("{0:0.##}KB", model.Size / 1024f); else size = string.Format("{0:0.##}MB", model.Size / 1024f / 1024f); // // sec1.Add(new SplitElement(new SplitElement.Row { // Text1 = model + (model.HasIssues == 1 ? " Issue" : " Issues"), // Image1 = Images.Flag, // Text2 = model.ForkCount.ToString() + (model.ForkCount == 1 ? " Fork" : " Forks"), // Image2 = Images.Fork // })); // sec1.Add(new SplitElement(new SplitElement.Row { Text1 = (model.UtcCreatedOn).ToString("MM/dd/yy"), Image1 = Images.Create, Text2 = size, Image2 = Images.Size })); var owner = new StyledStringElement("Owner", model.Owner) { Image = Images.Person, Accessory = UITableViewCellAccessory.DisclosureIndicator }; owner.Tapped += () => ViewModel.GoToOwnerCommand.Execute(null); sec1.Add(owner); if (model.ForkOf != null) { var parent = new StyledStringElement("Forked From", model.ForkOf.Name) { Image = Images.Fork, Accessory = UITableViewCellAccessory.DisclosureIndicator }; parent.Tapped += () => ViewModel.GoToForkParentCommand.Execute(model.ForkOf); sec1.Add(parent); } var followers = new StyledStringElement("Watchers", "" + model.FollowersCount) { Image = Images.Star, Accessory = UITableViewCellAccessory.DisclosureIndicator }; followers.Tapped += () => ViewModel.GoToStargazersCommand.Execute(null); sec1.Add(followers); var events = new StyledStringElement("Events", () => ViewModel.GoToEventsCommand.Execute(null), Images.Event); var sec2 = new Section { events }; if (model.HasWiki) sec2.Add(new StyledStringElement("Wiki", () => ViewModel.GoToWikiCommand.Execute(null), Images.Pencil)); if (model.HasIssues) sec2.Add(new StyledStringElement("Issues", () => ViewModel.GoToIssuesCommand.Execute(null), Images.Flag)); if (ViewModel.HasReadme) sec2.Add(new StyledStringElement("Readme", () => ViewModel.GoToReadmeCommand.Execute(null), Images.File)); var sec3 = new Section { new StyledStringElement("Commits", () => ViewModel.GoToCommitsCommand.Execute(null), Images.Commit), new StyledStringElement("Pull Requests", () => ViewModel.GoToPullRequestsCommand.Execute(null), Images.Hand), new StyledStringElement("Source", () => ViewModel.GoToSourceCommand.Execute(null), Images.Script), }; root.Add(new[] { new Section { split }, sec1, sec2, sec3 }); if (!String.IsNullOrEmpty(ViewModel.Repository.Website)) { root.Add(new Section { new StyledStringElement("Website", () => ViewModel.GoToUrlCommand.Execute(ViewModel.Repository.Website), Images.Webpage) }); } Root = root; }