public ProfileViewController(string username)
        {
            Title     = username;
            ViewModel = new ProfileViewModel(username);

            ViewModel.Bind(x => x.User, () => {
                _header.Subtitle = string.IsNullOrEmpty(ViewModel.User.Name) ? ViewModel.User.Login : ViewModel.User.Name;
                _header.Image    = ImageLoader.DefaultRequestImage(new System.Uri(ViewModel.User.AvatarUrl), this);
                _header.SetNeedsDisplay();
            });
        }
        public OrganizationViewController(string name)
        {
            Title     = name;
            Name      = name;
            ViewModel = new OrganizationViewModel(name);

            ViewModel.Bind(x => x.Organization, model => {
                _header.Subtitle = string.IsNullOrEmpty(model.Name) ? model.Login : model.Name;
                _header.Image    = ImageLoader.DefaultRequestImage(new System.Uri(model.AvatarUrl), this);
                _header.SetNeedsDisplay();
            });
        }
示例#3
0
 public void UpdatedImage(Uri uri)
 {
     _header.Image = ImageLoader.DefaultRequestImage(uri, this);
     if (_header.Image != null)
     {
         _header.SetNeedsDisplay();
     }
 }
示例#4
0
        public void RenderGist(GistModel model)
        {
            _shareButton.Enabled = _userButton.Enabled = model != null;
            var root = new RootElement(Title)
            {
                UnevenRows = true
            };
            var sec = new Section();

            _header.Subtitle = "Updated " + model.UpdatedAt.ToDaysAgo();


            var str = string.IsNullOrEmpty(model.Description) ? "Gist " + model.Id : model.Description;
            var d   = new NameTimeStringElement()
            {
                Time               = model.UpdatedAt.ToDaysAgo(),
                String             = str,
                Image              = Theme.CurrentTheme.AnonymousUserImage,
                BackgroundColor    = UIColor.White,
                UseBackgroundColor = true,
            };

            //Sometimes there's no user!
            d.Name     = (model.User == null) ? "Anonymous" : model.User.Login;
            d.ImageUri = (model.User == null) ? null : new Uri(model.User.AvatarUrl);

            sec.Add(d);

            var sec2 = new Section();

            foreach (var file in model.Files.Keys)
            {
                var sse = new StyledStringElement(file, model.Files[file].Size + " bytes", UITableViewCellStyle.Subtitle)
                {
                    Accessory     = MonoTouch.UIKit.UITableViewCellAccessory.DisclosureIndicator,
                    LineBreakMode = MonoTouch.UIKit.UILineBreakMode.TailTruncation,
                    Lines         = 1
                };

                var fileSaved     = file;
                var gistFileModel = model.Files[fileSaved];

                if (string.Equals(gistFileModel.Language, "markdown", StringComparison.OrdinalIgnoreCase))
                {
                    sse.Tapped += () => NavigationController.PushViewController(new GistViewableFileController(gistFileModel, ViewModel.Gist.HtmlUrl), true);
                }
                else
                {
                    sse.Tapped += () => NavigationController.PushViewController(new GistFileViewController(gistFileModel, ViewModel.Gist.HtmlUrl), true);
                }

                sec2.Add(sse);
            }

            _header.SetNeedsDisplay();
            root.Add(new [] { sec, sec2 });
            Root = root;
        }
示例#5
0
        public void Render()
        {
            if (ViewModel.PullRequest == null)
            {
                return;
            }

            var root = new RootElement(Title);

            _header.Title    = ViewModel.PullRequest.Title;
            _header.Subtitle = "Updated " + (ViewModel.PullRequest.UpdatedOn).ToDaysAgo();
            _header.SetNeedsDisplay();
            root.Add(new Section(_header));

            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)
//            {
//                MonoTouch.Foundation.NSAction 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".t(), 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)))
                {
                    commentsSec.Add(new CommentElement
                    {
                        Name            = x.User.Username,
                        Time            = x.CreatedOn.ToDaysAgo(),
                        String          = x.Content.Raw,
                        Image           = Theme.CurrentTheme.AnonymousUserImage,
                        ImageUri        = new Uri(x.User.Links.Avatar.Href),
                        BackgroundColor = UIColor.White,
                    });
                }

                //Load more if there's more comments
//                if (model.MoreComments != null)
//                {
//                    var loadMore = new PaginateElement("Load More".t(), "Loading...".t(),
//                                                       e => this.DoWorkNoHud(() => model.MoreComments(),
//                                          x => Utilities.ShowAlert("Unable to load more!".t(), 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;
        }
示例#6
0
        public void Render()
        {
            if (ViewModel.PullRequest == null)
            {
                return;
            }

            var root = new RootElement(Title);

            _header.Title    = ViewModel.PullRequest.Title;
            _header.Subtitle = "Updated " + (ViewModel.PullRequest.UpdatedAt).ToDaysAgo();
            _header.SetNeedsDisplay();
            root.Add(new Section(_header));

            var secDetails = new Section();

            if (!string.IsNullOrEmpty(ViewModel.PullRequest.Body))
            {
                var desc = new MultilinedElement(ViewModel.PullRequest.Body.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.PullRequest.Merged == null || !ViewModel.PullRequest.Merged.Value) ? false : true;

            _split1.Value.Text1 = ViewModel.PullRequest.State;
            _split1.Value.Text2 = merged ? "Merged" : "Not Merged";
            secDetails.Add(_split1);
            root.Add(secDetails);

            root.Add(new Section {
                new StyledStringElement("Commits", () => NavigationController.PushViewController(new ChangesetsViewController(ViewModel.User, ViewModel.Repo, ViewModel.PullRequestId), true), Images.Commit),
                new StyledStringElement("Files", () => NavigationController.PushViewController(new PullRequestFilesViewController(ViewModel.User, ViewModel.Repo, ViewModel.PullRequestId), true), Images.File),
            });

            if (!merged)
            {
                MonoTouch.Foundation.NSAction mergeAction = async() =>
                {
                    try
                    {
                        await this.DoWorkTest("Merging...", () => ViewModel.Merge());
                    }
                    catch (Exception e)
                    {
                        MonoTouch.Utilities.ShowAlert("Unable to Merge", e.Message);
                    }
                };

                if (ViewModel.PullRequest.Mergable == null)
                {
                    var el = new StyledStringElement("Merge".t(), mergeAction, Images.Fork);
                    root.Add(new Section(null, "The mergable state is unknown and merging may not be successful.")
                    {
                        el
                    });
                }
                else if (ViewModel.PullRequest.Mergable.Value)
                {
                    root.Add(new Section {
                        new StyledStringElement("Merge".t(), mergeAction, Images.Fork)
                    });
                }
                else
                {
                    root.Add(new Section {
                        new StyledStringElement("Unable to merge!".t())
                        {
                            Image = Images.Fork
                        }
                    });
                }
            }


            if (ViewModel.Comments.Items.Count > 0)
            {
                var commentsSec = new Section();
                ViewModel.Comments.OrderBy(x => (x.CreatedAt)).ToList().ForEach(x => {
                    if (!string.IsNullOrEmpty(x.Body))
                    {
                        commentsSec.Add(new CommentElement {
                            Name            = x.User.Login,
                            Time            = x.CreatedAt.ToDaysAgo(),
                            String          = x.Body,
                            Image           = Theme.CurrentTheme.AnonymousUserImage,
                            ImageUri        = new Uri(x.User.AvatarUrl),
                            BackgroundColor = UIColor.White,
                        });
                    }
                });

                //Load more if there's more comments
//                if (model.MoreComments != null)
//                {
//                    var loadMore = new PaginateElement("Load More".t(), "Loading...".t(),
//                                                       e => this.DoWorkNoHud(() => model.MoreComments(),
//                                          x => Utilities.ShowAlert("Unable to load more!".t(), 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;

            //            if (_scrollToLastComment && _comments.Elements.Count > 0)
            //            {
            //                TableView.ScrollToRow(NSIndexPath.FromRowSection(_comments.Elements.Count - 1, 2), UITableViewScrollPosition.Top, true);
            //                _scrollToLastComment = false;
            //            }
        }