Exemple #1
0
		public override void ViewDidLoad()
		{
			base.ViewDidLoad();

            Title = "Issue #" + ViewModel.Id;
            HeaderView.SetImage(null, Images.Avatar);

            _descriptionElement = new WebElement("description_webview");
			_descriptionElement.UrlRequested = ViewModel.GoToUrlCommand.Execute;

            _commentsElement = new WebElement("body_webview");
			_commentsElement.UrlRequested = ViewModel.GoToUrlCommand.Execute;

			NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Compose, (s, e) => ViewModel.GoToEditCommand.Execute(null));
			NavigationItem.RightBarButtonItem.Enabled = false;
			ViewModel.Bind(x => x.Issue, RenderIssue);
			ViewModel.BindCollection(x => x.Comments, (e) => RenderComments());
		}
Exemple #2
0
		public override void ViewDidLoad()
		{
			base.ViewDidLoad();

            HeaderView.SetImage(null, Images.Avatar);

			var content = System.IO.File.ReadAllText("WebCell/body.html", System.Text.Encoding.UTF8);
            _descriptionElement = new WebElement(content, "description_webview", false);
			_descriptionElement.UrlRequested = ViewModel.GoToUrlCommand.Execute;

			var content2 = System.IO.File.ReadAllText("WebCell/comments.html", System.Text.Encoding.UTF8);
            _commentsElement = new WebElement(content2, "body_webview", true);
			_commentsElement.UrlRequested = ViewModel.GoToUrlCommand.Execute;

			NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Compose, (s, e) => ViewModel.GoToEditCommand.Execute(null));
			NavigationItem.RightBarButtonItem.Enabled = false;
			ViewModel.Bind(x => x.Issue, RenderIssue);
			ViewModel.BindCollection(x => x.Comments, (e) => RenderComments());
		}
        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;
        }