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 override void ViewDidLoad() { base.ViewDidLoad(); var vm = (BaseUserCollectionViewModel)ViewModel; var weakVm = new WeakReference<BaseUserCollectionViewModel>(vm); BindCollection(vm.Users, x => { var e = new UserElement(x.Username, string.Empty, string.Empty, new Avatar(x.Avatar)); e.Clicked.Subscribe(_ => weakVm.Get()?.GoToUserCommand.Execute(x)); return e; }); }
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); }