public CommentElement(string title, string message, DateTimeOffset date, Avatar avatar) { _title = title; _message = message; _date = date.Humanize(); _avatar = avatar; }
public CommitElement(string name, string description, DateTimeOffset date, Avatar avatar) { _name = name; _description = description; _date = date.Humanize(); _avatar = avatar; }
public override void ViewDidLoad() { base.ViewDidLoad(); var vm = (IssueAssignedToViewModel)ViewModel; BindCollection(vm.Users, x => { var avatar = new Avatar(x.Avatar); var el = new UserElement(x.Username, string.Empty, string.Empty, avatar); el.Clicked.Subscribe(_ => { if (vm.SelectedUser != null && string.Equals(vm.SelectedUser.Username, x.Username)) vm.SelectedUser = null; else vm.SelectedUser = x; }); if (vm.SelectedUser != null && string.Equals(vm.SelectedUser.Username, x.Username, StringComparison.OrdinalIgnoreCase)) el.Accessory = UITableViewCellAccessory.Checkmark; else el.Accessory = UITableViewCellAccessory.None; return el; }); vm.Bind(x => x.SelectedUser).Subscribe(x => { var elements = Root.FirstOrDefault()?.Elements ?? Enumerable.Empty<Element>(); foreach (var m in elements.Cast<UserElement>()) m.Accessory = (x != null && string.Equals(vm.SelectedUser.Username, x.Username, StringComparison.OrdinalIgnoreCase)) ? UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.None; }); }
public void RenderIssue() { if (ViewModel.Issue == null) return; var avatar = new Avatar(ViewModel.Issue.ReportedBy?.Avatar); NavigationItem.RightBarButtonItem.Enabled = true; HeaderView.Text = ViewModel.Issue.Title; HeaderView.SetImage(avatar.ToUrl(), Images.Avatar); HeaderView.SubText = ViewModel.Issue.Content ?? "Updated " + ViewModel.Issue.UtcLastUpdated.Humanize(); RefreshHeaderView(); var split = new SplitButtonElement(); split.AddButton("Comments", ViewModel.Comments.Items.Count.ToString()); split.AddButton("Watches", ViewModel.Issue.FollowerCount.ToString()); var root = new RootElement(Title); root.Add(new Section { split }); var secDetails = new Section(); if (!string.IsNullOrEmpty(ViewModel.Issue.Content)) { _descriptionElement.LoadContent(new MarkdownRazorView { Model = ViewModel.Issue.Content }.GenerateString()); secDetails.Add(_descriptionElement); } _split1.Button1.Text = ViewModel.Issue.Status; _split1.Button2.Text = ViewModel.Issue.Priority; secDetails.Add(_split1); _split2.Button1.Text = ViewModel.Issue.Metadata.Kind; _split2.Button2.Text = ViewModel.Issue.Metadata.Component ?? "No Component"; secDetails.Add(_split2); _split3.Button1.Text = ViewModel.Issue.Metadata.Version ?? "No Version"; _split3.Button2.Text = ViewModel.Issue.Metadata.Milestone ?? "No Milestone"; secDetails.Add(_split3); var assigneeElement = new StyledStringElement("Assigned", ViewModel.Issue.Responsible != null ? ViewModel.Issue.Responsible.Username : "******", UITableViewCellStyle.Value1) { Image = AtlassianIcon.User.ToImage(), Accessory = UITableViewCellAccessory.DisclosureIndicator }; assigneeElement.Tapped += () => ViewModel.GoToAssigneeCommand.Execute(null); secDetails.Add(assigneeElement); root.Add(secDetails); if (ViewModel.Comments.Any(x => !string.IsNullOrEmpty(x.Content))) { root.Add(new Section { _commentsElement }); } var addComment = new StyledStringElement("Add Comment") { Image = AtlassianIcon.Addcomment.ToImage() }; addComment.Tapped += AddCommentTapped; root.Add(new Section { addComment }); Root = root; }
public PullRequestElement(string name, DateTimeOffset time, Avatar avatar, UIImage image = null) : base(null) { _name = name; _time = time.Humanize(); _avatar = avatar; _image = image ?? Images.Avatar; }
public RepositoryElement(string name, string description, string owner, Avatar avatar) { _name = name; _description = description; _owner = owner; _avatar = avatar; ShowOwner = true; }
protected Element CreateElement(RepositoryDetailedModel repo) { var description = ViewModel.ShowRepositoryDescription ? repo.Description : string.Empty; var avatarUrl = new Avatar(repo.Logo).ToUrl(); var sse = new RepositoryElement(repo.Name, description, repo.Owner, avatarUrl, Images.RepoPlaceholder); sse.Tapped += () => ViewModel.GoToRepositoryCommand.Execute(repo); return sse; }
public void UpdatedImage(Avatar avatar) { var avatarUrl = avatar?.ToUrl(Convert.ToInt32(imageSize)); if (avatarUrl == null) return; var placeholder = Images.Avatar; _imgView.SetImage(new NSUrl(avatarUrl), placeholder, 0, (img, err, cache, type) => { UIView.Transition(_imgView, 0.50f, UIViewAnimationOptions.TransitionCrossDissolve, () => _imgView.Image = img, null); }); }
public UserElement(string username, string firstName, string lastName, Avatar avatar) : base (username, string.Empty, UITableViewCellStyle.Subtitle) { var realName = firstName ?? "" + " " + (lastName ?? ""); if (!string.IsNullOrWhiteSpace(realName)) Value = realName; Accessory = UITableViewCellAccessory.DisclosureIndicator; Image = Images.Avatar; ImageUri = avatar.ToUri(64); }
public void Bind(string title, string time, Avatar avatar, UIImage placeholderImage) { TitleLabel.Text = title; TimeLabel.Text = time; var avatarUrl = avatar?.ToUrl(); if (avatarUrl == null) MainImageView.Image = placeholderImage; else MainImageView.SetImage(new NSUrl(avatarUrl), placeholderImage); }
public void Bind(string title, string time, Avatar avatar) { TitleLabel.Text = title; TimeLabel.Text = time; var avatarUrl = avatar?.ToUrl(64); if (avatarUrl == null) MainImageView.Image = Images.Avatar; else MainImageView.SetImage(new NSUrl(avatarUrl), Images.Avatar); }
public void Bind(string name, string description, string repoOwner, Avatar logoUri) { RepositoryName.Text = name; RepositoryOwner.Text = repoOwner; RepositoryDescription.Hidden = string.IsNullOrWhiteSpace(description); RepositoryDescription.Text = description ?? string.Empty; ContentConstraint.Constant = RepositoryDescription.Hidden ? 0 : DefaultContentConstraint; var uri = logoUri.ToUri(64); if (uri == null) RepositoryImage.Image = Images.RepoPlaceholder; else RepositoryImage.SetImage(new NSUrl(uri.AbsoluteUri), Images.RepoPlaceholder); }
public void Bind(string name, string description, string time, Avatar avatar) { TitleLabel.Text = name; TimeLabel.Text = time; ContentLabel.Text = description; ContentLabel.Hidden = string.IsNullOrWhiteSpace(description); ContentConstraint.Constant = ContentLabel.Hidden ? 0 : DefaultContentConstraintSize; var logoUri = avatar.ToUri(64); if (logoUri == null) MainImageView.Image = Images.Avatar; else MainImageView.SetImage(new NSUrl(logoUri.AbsoluteUri), Images.Avatar); }
private static Element CreateElement(Tuple<EventModel, BaseEventsViewModel.EventBlock> e) { try { if (e.Item2 == null) return null; var img = ChooseImage(e.Item1); var avatarUrl = e.Item1?.User?.Avatar; var avatar = new Avatar(avatarUrl); var headerBlocks = new System.Collections.Generic.List<NewsFeedElement.TextBlock>(); foreach (var h in e.Item2.Header) { Action act = null; var anchorBlock = h as BaseEventsViewModel.AnchorBlock; if (anchorBlock != null) act = anchorBlock.Tapped; headerBlocks.Add(new NewsFeedElement.TextBlock(h.Text, act)); } var bodyBlocks = new System.Collections.Generic.List<NewsFeedElement.TextBlock>(); foreach (var h in e.Item2.Body) { Action act = null; var anchorBlock = h as BaseEventsViewModel.AnchorBlock; if (anchorBlock != null) act = anchorBlock.Tapped; var block = new NewsFeedElement.TextBlock(h.Text, act); if (act == null) block.Color = UIColor.DarkGray; bodyBlocks.Add(block); } return new NewsFeedElement(avatar.ToUrl(), e.Item1.UtcCreatedOn, headerBlocks, bodyBlocks, img, e.Item2.Tapped); } catch (Exception ex) { Utilities.LogException("Unable to add event", ex); return null; } }
public override void ViewDidLoad() { base.ViewDidLoad(); TableView.RegisterNibForCellReuse(PullRequestCellView.Nib, PullRequestCellView.Key); TableView.RowHeight = UITableView.AutomaticDimension; TableView.EstimatedRowHeight = 80f; var vm = (PullRequestsViewModel)ViewModel; _segmentBarButton.Width = View.Frame.Width - 10f; var set = this.CreateBindingSet<PullRequestsView, PullRequestsViewModel>(); set.Bind(_viewSegment).To(x => x.SelectedFilter); set.Apply(); BindCollection(vm.PullRequests, s => { var avatar = new Avatar(s.Author?.Links?.Avatar?.Href); var sse = new PullRequestElement(s.Title, s.UpdatedOn, avatar, Images.Avatar); sse.Tapped += () => vm.GoToPullRequestCommand.Execute(s); return sse; }); }
public static void SetAvatar(this UIImageView @this, Avatar avatar, int? size = 64) { @this.Image = Images.Avatar; if (avatar == null) return; var avatarUri = avatar.ToUri(size); if (avatarUri != null) { @this.SetImage(new NSUrl(avatarUri.AbsoluteUri), Images.Avatar, (img, err, type, imageUrl) => { if (img == null || err != null) return; if (type == SDImageCacheType.None) { @this.Image = Images.Avatar; @this.BeginInvokeOnMainThread(() => UIView.Transition(@this, 0.25f, UIViewAnimationOptions.TransitionCrossDissolve, () => @this.Image = img, null)); } }); } }
public override void ViewDidLoad() { TableView.RegisterNibForCellReuse(RepositoryCellView.Nib, RepositoryCellView.Key); TableView.RowHeight = UITableView.AutomaticDimension; TableView.EstimatedRowHeight = 80f; base.ViewDidLoad(); _hud = new Hud(View); var vm = (RepositoriesExploreViewModel)ViewModel; var search = (UISearchBar)TableView.TableHeaderView; search.TextChanged += (sender, e) => vm.SearchText = search.Text; vm.Bind(x => x.SearchText, x => search.Text = x); search.SearchButtonClicked += (sender, e) => { search.ResignFirstResponder(); vm.SearchCommand.Execute(null); }; vm.Bind(x => x.IsSearching, x => { if (x) _hud.Show("Searching..."); else _hud.Hide(); }); BindCollection(vm.Repositories, repo => { var description = vm.ShowRepositoryDescription ? repo.Description : string.Empty; var avatarUrl = new Avatar(repo.Logo).ToUrl(); var sse = new RepositoryElement(repo.Name, description, repo.Owner, avatarUrl, Images.RepoPlaceholder); sse.Tapped += () => vm.GoToRepositoryCommand.Execute(repo); return sse; }); }
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 void Render() { if (ViewModel.Commits == null || ViewModel.Commit == null) return; var titleMsg = (ViewModel.Commit.Message ?? string.Empty).Split(new [] { '\n' }, 2).FirstOrDefault(); var avatarUrl = ViewModel.Commit.Author?.User?.Links?.Avatar?.Href; var node = ViewModel.Node.Substring(0, ViewModel.Node.Length > 10 ? 10 : ViewModel.Node.Length); Title = node; HeaderView.Text = titleMsg ?? node; HeaderView.SubText = "Commited " + (ViewModel.Commit.Date).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.Commit.Participants.Count.ToString()); split.AddButton("Approvals", ViewModel.Commit.Participants.Count(x => x.Approved).ToString()); var commitModel = ViewModel.Commits; var root = new RootElement(Title) { UnevenRows = Root.UnevenRows }; root.Add(new Section { split }); var detailSection = new Section(); root.Add(detailSection); var user = ViewModel.Commit.Author?.User?.DisplayName ?? ViewModel.Commit.Author.Raw ?? "Unknown"; detailSection.Add(new MultilinedElement(user, ViewModel.Commit.Message) { CaptionColor = Theme.CurrentTheme.MainTextColor, ValueColor = Theme.CurrentTheme.MainTextColor, BackgroundColor = UIColor.White }); if (ViewModel.ShowRepository) { var repo = new StyledStringElement(ViewModel.Repository) { Accessory = UIKit.UITableViewCellAccessory.DisclosureIndicator, Lines = 1, Font = StyledStringElement.DefaultDetailFont, TextColor = StyledStringElement.DefaultDetailColor, Image = Images.Repo }; repo.Tapped += () => ViewModel.GoToRepositoryCommand.Execute(null); detailSection.Add(repo); } if (_viewSegment.SelectedSegment == 0) { var paths = ViewModel.Commits.GroupBy(y => { var filename = "/" + y.File; 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.File.Substring(x.File.LastIndexOf('/') + 1); var sse = new ChangesetElement(file, x.Type, x.Diffstat.Added, x.Diffstat.Removed); sse.Tapped += () => ViewModel.GoToFileCommand.Execute(y); fileSection.Add(sse); } root.Add(fileSection); } } else if (_viewSegment.SelectedSegment == 1) { var commentSection = new Section(); foreach (var comment in ViewModel.Comments) { var name = comment.User.DisplayName ?? comment.User.Username; var imgUri = new Avatar(comment.User.Links?.Avatar?.Href); commentSection.Add(new NameTimeStringElement(name, comment.Content.Raw, comment.CreatedOn, imgUri.ToUrl(), Images.Avatar)); } if (commentSection.Elements.Count > 0) root.Add(commentSection); var addComment = new StyledStringElement("Add Comment") { Image = Images.Pencil }; addComment.Tapped += AddCommentTapped; root.Add(new Section { addComment }); } else if (_viewSegment.SelectedSegment == 2) { var likeSection = new Section(); likeSection.AddAll(ViewModel.Commit.Participants.Where(x => x.Approved).Select(l => { var el = new UserElement(l.User.DisplayName, string.Empty, string.Empty, l.User.Links.Avatar.Href); el.Tapped += () => ViewModel.GoToUserCommand.Execute(l.User.Username); return el; })); if (likeSection.Elements.Count > 0) root.Add(likeSection); StyledStringElement approveButton; if (ViewModel.Commit.Participants.Any(x => x.User.Username.Equals(ViewModel.GetApplication().Account.Username) && x.Approved)) { approveButton = new StyledStringElement("Unapprove") { Image = Images.Cancel }; approveButton.Tapped += () => this.DoWorkAsync("Unapproving...", ViewModel.Unapprove); } else { approveButton = new StyledStringElement("Approve") { Image = Images.Accept }; approveButton.Tapped += () => this.DoWorkAsync("Approving...", ViewModel.Approve); } root.Add(new Section { approveButton }); } Root = root; }
private void PinRepository() { var repoOwner = Repository.Owner; var repoName = Repository.Name; //Is it pinned already or not? var pinnedRepo = this.GetApplication().Account.PinnnedRepositories.GetPinnedRepository(repoOwner, Repository.Slug); if (pinnedRepo == null) { var avatar = new Avatar(Repository.Logo).ToUrl(); this.GetApplication().Account.PinnnedRepositories.AddPinnedRepository(repoOwner, Repository.Slug, repoName, avatar); } else this.GetApplication().Account.PinnnedRepositories.RemovePinnedRepository(pinnedRepo.Id); }
private async Task AttemptLogin(BitbucketAccount account) { Uri accountAvatarUri = null; var avatarUrl = account.AvatarUrl; if (!string.IsNullOrEmpty(avatarUrl)) { var match = Regex.Match(avatarUrl, @"&s=(\d+)", RegexOptions.IgnoreCase); if (match.Success && match.Groups.Count > 1) avatarUrl = avatarUrl.Replace(match.Groups[0].Value, "&s=128"); } if (Uri.TryCreate(avatarUrl, UriKind.Absolute, out accountAvatarUri)) Avatar = new Avatar(accountAvatarUri.AbsoluteUri); var client = await LoginAccount(account); _applicationService.ActivateUser(account, client); }
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 = string.IsNullOrWhiteSpace(model.Description) ? "Updated " + model.UtcLastUpdated.Humanize() : model.Description; 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(); 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; }
public void UpdatedImage(Avatar avatar) { var avatarUrl = avatar?.ToUrl(Convert.ToInt32(imageSize)); if (avatarUrl == null) { AssignUnknownUserImage(); } else { _imgView.SetImage(new NSUrl(avatarUrl), Images.Avatar, 0, (img, err, cache, type) => { _imgView.Image = Images.Avatar; UIView.Transition(_imgView, 0.50f, UIViewAnimationOptions.TransitionCrossDissolve, () => _imgView.Image = img, null); }); } }
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()); ICollection<Section> root = new LinkedList<Section>(); root.Add(new Section { split }); var secDetails = new Section(); if (!string.IsNullOrWhiteSpace(ViewModel.Description)) { var content = new MarkdownRazorView { Model = ViewModel.Description }.GenerateString(); _descriptionElement.SetValue(content); secDetails.Add(_descriptionElement); } var commitsElement = new StringElement("Commits", AtlassianIcon.Devtoolscommit.ToImage()); commitsElement.Clicked.BindCommand(ViewModel.GoToCommitsCommand); var merged = ViewModel.Merged; _split1.Button1.Text = ViewModel.PullRequest.CreatedOn.ToString("MM/dd/yy"); _split1.Button2.Text = merged ? "Merged" : "Not Merged"; secDetails.Add(_split1); secDetails.Add(commitsElement); root.Add(secDetails); if (!merged) { var mergeElement = new StringElement("Merge", AtlassianIcon.Approve.ToImage()); mergeElement.Clicked.Subscribe(_ => MergeClick()); root.Add(new Section { mergeElement }); } var comments = ViewModel.Comments .Where(x => !string.IsNullOrEmpty(x.Content.Raw) && x.Inline == null) .OrderBy(x => (x.CreatedOn)) .Select(x => { var name = x.User.DisplayName ?? x.User.Username ?? "Unknown"; var avatar = new Avatar(x.User.Links?.Avatar?.Href); return new CommentViewModel(name, x.Content.Html, x.CreatedOn.Humanize(), avatar.ToUrl()); }).ToList(); if (comments.Count > 0) { var content = new CommentsRazorView { Model = comments.ToList() }.GenerateString(); _commentsElement.SetValue(content); root.Add(new Section { _commentsElement }); } var addComment = new StringElement("Add Comment") { Image = AtlassianIcon.Addcomment.ToImage() }; addComment.Clicked.Subscribe(_ => AddCommentTapped()); root.Add(new Section { addComment }); Root.Reset(root); }
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.IsNullOrWhiteSpace(ViewModel.Description)) { if (_descriptionElement == null) { _descriptionElement = new WebElement("description"); _descriptionElement.UrlRequested = ViewModel.GoToUrlCommand.Execute; } _descriptionElement.LoadContent(new MarkdownRazorView { Model = ViewModel.Description }.GenerateString()); secDetails.Add(_descriptionElement); } 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) }); } var comments = ViewModel.Comments .Where(x => !string.IsNullOrEmpty(x.Content.Raw) && x.Inline == null) .OrderBy(x => (x.CreatedOn)) .Select(x => { var name = x.User.DisplayName ?? x.User.Username ?? "Unknown"; var avatar = new Avatar(x.User.Links?.Avatar?.Href); return new CommentViewModel(name, x.Content.Html, x.CreatedOn, avatar.ToUrl()); }).ToList(); if (comments.Count > 0) { if (_commentsElement == null) { _commentsElement = new WebElement("comments"); _commentsElement.UrlRequested = ViewModel.GoToUrlCommand.Execute; } _commentsElement.LoadContent(new CommentsRazorView { Model = comments.ToList() }.GenerateString()); root.Add(new Section { _commentsElement }); } var addComment = new StyledStringElement("Add Comment") { Image = Images.Pencil }; addComment.Tapped += AddCommentTapped; root.Add(new Section { addComment }); Root = root; }
public void Render(RepositoryDetailedModel model) { if (model == null) return; Title = model.Name; var avatar = new Avatar(model.Logo).ToUrl(128); var root = new RootElement(Title) { UnevenRows = true }; HeaderView.SubText = string.IsNullOrWhiteSpace(model.Description) ? "Updated " + model.UtcLastUpdated.Humanize() : model.Description; HeaderView.SetImage(avatar, Images.RepoPlaceholder); RefreshHeaderView(); var stargazersCommand = ViewModel.GoToStargazersCommand; var split = new SplitButtonElement(); split.AddButton("Watchers", model.FollowersCount.ToString(), () => stargazersCommand.Execute(null)); split.AddButton("Forks", model.ForkCount.ToString()); split.AddButton("Branches", ViewModel.Branches?.Count.ToString() ?? "-"); var sec1 = new Section(); _split1.Button1.Image = model.IsPrivate ? AtlassianIcon.Locked.ToImage() : AtlassianIcon.Unlocked.ToImage(); _split1.Button1.Text = model.IsPrivate ? "Private" : "Public"; _split1.Button2.Text = string.IsNullOrEmpty(model.Language) ? "N/A" : model.Language; sec1.Add(_split1); _split3.Button1.Text = model.Scm.ApplyCase(LetterCasing.Title); _split3.Button2.Text = "Issues".ToQuantity(ViewModel.Issues); sec1.Add(_split3); _split2.Button1.Text = (model.UtcCreatedOn).ToString("MM/dd/yy"); _split2.Button2.Text = model.Size.Bytes().ToString("#.##"); sec1.Add(_split2); var owner = new StyledStringElement("Owner", model.Owner) { Image = AtlassianIcon.User.ToImage(), 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 = AtlassianIcon.Devtoolsfork.ToImage(), Accessory = UITableViewCellAccessory.DisclosureIndicator }; parent.Tapped += () => ViewModel.GoToForkParentCommand.Execute(model.ForkOf); sec1.Add(parent); } var events = new StyledStringElement("Events", () => ViewModel.GoToEventsCommand.Execute(null), AtlassianIcon.Blogroll.ToImage()); var sec2 = new Section { events }; if (model.HasWiki) sec2.Add(new StyledStringElement("Wiki", () => ViewModel.GoToWikiCommand.Execute(null), AtlassianIcon.Edit.ToImage())); if (model.HasIssues) sec2.Add(new StyledStringElement("Issues", () => ViewModel.GoToIssuesCommand.Execute(null), AtlassianIcon.Flag.ToImage())); if (ViewModel.HasReadme) sec2.Add(new StyledStringElement("Readme", () => ViewModel.GoToReadmeCommand.Execute(null), AtlassianIcon.Pagedefault.ToImage())); var sec3 = new Section { new StyledStringElement("Commits", () => ViewModel.GoToCommitsCommand.Execute(null), AtlassianIcon.Devtoolscommit.ToImage()), new StyledStringElement("Pull Requests", () => ViewModel.GoToPullRequestsCommand.Execute(null), AtlassianIcon.Devtoolspullrequest.ToImage()), new StyledStringElement("Source", () => ViewModel.GoToSourceCommand.Execute(null), AtlassianIcon.Filecode.ToImage()), }; 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), AtlassianIcon.Homepage.ToImage()) }); } Root = root; }
public void Render() { if (ViewModel.Commits == null || ViewModel.Commit == null) return; var titleMsg = (ViewModel.Commit.Message ?? string.Empty).Split(new [] { '\n' }, 2).FirstOrDefault(); var avatarUrl = ViewModel.Commit.Author?.User?.Links?.Avatar?.Href; var node = ViewModel.Node.Substring(0, ViewModel.Node.Length > 10 ? 10 : ViewModel.Node.Length); Title = node; HeaderView.Text = titleMsg ?? node; HeaderView.SubText = "Commited " + (ViewModel.Commit.Date).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.Commit.Participants.Count.ToString()); split.AddButton("Approvals", ViewModel.Commit.Participants.Count(x => x.Approved).ToString()); var commitModel = ViewModel.Commits; ICollection<Section> root = new LinkedList<Section>(); root.Add(new Section { split }); var detailSection = new Section(); root.Add(detailSection); var user = ViewModel.Commit.Author?.User?.DisplayName ?? ViewModel.Commit.Author.Raw ?? "Unknown"; detailSection.Add(new MultilinedElement(user, ViewModel.Commit.Message)); if (ViewModel.ShowRepository) { var repo = new StringElement(ViewModel.Repository) { Accessory = UIKit.UITableViewCellAccessory.DisclosureIndicator, Lines = 1, TextColor = StringElement.DefaultDetailColor, Image = AtlassianIcon.Devtoolsrepository.ToImage() }; repo.Clicked.BindCommand(ViewModel.GoToRepositoryCommand); detailSection.Add(repo); } if (_viewSegment.SelectedSegment == 0) { var paths = ViewModel.Commits.GroupBy(y => { var filename = "/" + y.File; 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.File.Substring(x.File.LastIndexOf('/') + 1); var sse = new ChangesetElement(file, x.Type, x.Diffstat.Added, x.Diffstat.Removed); sse.Clicked.Select(_ => y).BindCommand(ViewModel.GoToFileCommand); fileSection.Add(sse); } root.Add(fileSection); } } else if (_viewSegment.SelectedSegment == 1) { var commentSection = new Section(); foreach (var comment in ViewModel.Comments) { var name = comment.User.DisplayName ?? comment.User.Username; var avatar = new Avatar(comment.User.Links?.Avatar?.Href); commentSection.Add(new CommentElement(name, comment.Content.Raw, comment.CreatedOn, avatar)); } if (commentSection.Elements.Count > 0) root.Add(commentSection); var addComment = new StringElement("Add Comment") { Image = AtlassianIcon.Addcomment.ToImage() }; addComment.Clicked.Subscribe(_ => AddCommentTapped()); root.Add(new Section { addComment }); } else if (_viewSegment.SelectedSegment == 2) { var likeSection = new Section(); likeSection.AddAll(ViewModel.Commit.Participants.Where(x => x.Approved).Select(l => { var avatar = new Avatar(l.User?.Links?.Avatar?.Href); var el = new UserElement(l.User.DisplayName, string.Empty, string.Empty, avatar); el.Clicked.Select(_ => l.User.Username).BindCommand(ViewModel.GoToUserCommand); return el; })); if (likeSection.Elements.Count > 0) root.Add(likeSection); StringElement approveButton; if (ViewModel.Commit.Participants.Any(x => x.User.Username.Equals(ViewModel.GetApplication().Account.Username) && x.Approved)) { approveButton = new StringElement("Unapprove") { Image = AtlassianIcon.Approve.ToImage() }; approveButton.Clicked.Subscribe(_ => this.DoWorkAsync("Unapproving...", ViewModel.Unapprove)); } else { approveButton = new StringElement("Approve") { Image = AtlassianIcon.Approve.ToImage() }; approveButton.Clicked.Subscribe(_ => this.DoWorkAsync("Approving...", ViewModel.Approve)); } root.Add(new Section { approveButton }); } Root.Reset(root); }
public void Render(RepositoryDetailedModel model) { if (model == null) return; Title = model.Name; var avatar = new Avatar(model.Logo).ToUrl(128); ICollection<Section> root = new LinkedList<Section>(); HeaderView.SubText = string.IsNullOrWhiteSpace(model.Description) ? "Updated " + model.UtcLastUpdated.Humanize() : model.Description; HeaderView.SetImage(avatar, Images.RepoPlaceholder); RefreshHeaderView(); var sec1 = new Section(); _split1.Button1.Image = model.IsPrivate ? AtlassianIcon.Locked.ToImage() : AtlassianIcon.Unlocked.ToImage(); _split1.Button1.Text = model.IsPrivate ? "Private" : "Public"; _split1.Button2.Text = string.IsNullOrEmpty(model.Language) ? "N/A" : model.Language; sec1.Add(_split1); _split3.Button1.Text = model.Scm.ApplyCase(LetterCasing.Title); _split3.Button2.Text = "Issues".ToQuantity(ViewModel.Issues); sec1.Add(_split3); _split2.Button1.Text = (model.UtcCreatedOn).ToString("MM/dd/yy"); _split2.Button2.Text = model.Size.Bytes().ToString("#.##"); sec1.Add(_split2); var owner = new StringElement("Owner", model.Owner) { Image = AtlassianIcon.User.ToImage(), Accessory = UITableViewCellAccessory.DisclosureIndicator }; owner.Clicked.BindCommand(ViewModel.GoToOwnerCommand); sec1.Add(owner); if (model.ForkOf != null) { var parent = new StringElement("Forked From", model.ForkOf.Name) { Image = AtlassianIcon.Devtoolsfork.ToImage(), Accessory = UITableViewCellAccessory.DisclosureIndicator }; parent.Clicked.Select(_ => model.ForkOf).BindCommand(ViewModel.GoToForkParentCommand); sec1.Add(parent); } var events = new StringElement("Events", AtlassianIcon.Blogroll.ToImage()); events.Clicked.BindCommand(ViewModel.GoToEventsCommand); var sec2 = new Section { events }; if (model.HasWiki) { var wiki = new StringElement("Wiki", AtlassianIcon.Edit.ToImage()); wiki.Clicked.BindCommand(ViewModel.GoToWikiCommand); sec2.Add(wiki); } if (model.HasIssues) { var issues = new StringElement("Issues", AtlassianIcon.Flag.ToImage()); issues.Clicked.BindCommand(ViewModel.GoToIssuesCommand); sec2.Add(issues); } if (ViewModel.HasReadme) { var readme = new StringElement("Readme", AtlassianIcon.Pagedefault.ToImage()); readme.Clicked.BindCommand(ViewModel.GoToReadmeCommand); sec2.Add(readme); } var commits = new StringElement("Commits", AtlassianIcon.Devtoolscommit.ToImage()); commits.Clicked.BindCommand(ViewModel.GoToCommitsCommand); var pullRequests = new StringElement("Pull Requests", AtlassianIcon.Devtoolspullrequest.ToImage()); pullRequests.Clicked.BindCommand(ViewModel.GoToPullRequestsCommand); var source = new StringElement("Source", AtlassianIcon.Filecode.ToImage()); source.Clicked.BindCommand(ViewModel.GoToSourceCommand); var sec3 = new Section { commits, pullRequests, source }; foreach (var s in new[] { new Section { _split }, sec1, sec2, sec3 }) root.Add(s); if (!String.IsNullOrEmpty(ViewModel.Repository.Website)) { var website = new StringElement("Website", AtlassianIcon.Homepage.ToImage()); website.Clicked.Select(_ => ViewModel.Repository.Website).BindCommand(ViewModel.GoToUrlCommand); root.Add(new Section { website }); } Root.Reset(root); }