Example #1
0
        public void RemovePropertyRemovesPropertyAtIndex()
        {
            var section = new Section("Foo");

            section.Add(new Property("Bar", "Baz"));

            if (!section.Contains("Bar"))
            {
                Assert.Inconclusive("A property with name 'Bar' was not found");
            }

            section.Remove(0);

            //The property was removed. The access should throw now
            Assert.Throws <KeyNotFoundException>(() =>
            {
                var _ = section["Bar"];
            });
        }
Example #2
0
        public void RemovePropertyRemovesProperty()
        {
            var section  = new Section("Foo");
            var property = new Property("Bar", "Baz");

            section.Add(property);

            if (!section.Contains(property.Name))
            {
                Assert.Inconclusive($"The property '{property}' was not found");
            }

            section.Remove(property);

            //The property was removed. The access should throw now
            Assert.Throws <KeyNotFoundException>(() =>
            {
                var _ = section["Bar"];
            });
        }
Example #3
0
        protected BaseIssueViewController()
        {
            CommentsElement = new HtmlElement("comments");
            this.WhenAnyValue(x => x.ViewModel.GoToUrlCommand)
            .Subscribe(x => CommentsElement.UrlRequested = x.ExecuteIfCan);

            DescriptionElement = new HtmlElement("description");
            this.WhenAnyValue(x => x.ViewModel.GoToUrlCommand)
            .Subscribe(x => DescriptionElement.UrlRequested = x.ExecuteIfCan);

            this.WhenAnyValue(x => x.ViewModel.ShowMenuCommand)
            .Select(x => x.ToBarButtonItem(UIBarButtonSystemItem.Action))
            .Subscribe(x => NavigationItem.RightBarButtonItem = x);

            this.WhenAnyObservable(x => x.ViewModel.GoToAssigneesCommand)
            .Subscribe(_ => IssueAssigneeViewController.Show(this, ViewModel.CreateAssigneeViewModel()));

            this.WhenAnyObservable(x => x.ViewModel.GoToMilestonesCommand)
            .Subscribe(_ => IssueMilestonesViewController.Show(this, ViewModel.CreateMilestonesViewModel()));

            this.WhenAnyObservable(x => x.ViewModel.GoToLabelsCommand)
            .Subscribe(_ => IssueLabelsViewController.Show(this, ViewModel.CreateLabelsViewModel()));

            this.WhenAnyValue(x => x.ViewModel.GoToOwnerCommand)
            .Subscribe(x => HeaderView.ImageButtonAction = x != null ? new Action(() => ViewModel.GoToOwnerCommand.ExecuteIfCan()) : null);

            Appeared.Take(1)
            .Select(_ => Observable.Timer(TimeSpan.FromSeconds(0.2f)))
            .Switch()
            .ObserveOn(RxApp.MainThreadScheduler)
            .Select(_ => this.WhenAnyValue(x => x.ViewModel.IsClosed))
            .Switch()
            .Subscribe(x =>
            {
                HeaderView.SubImageView.TintColor = x ? UIColor.FromRGB(0xbd, 0x2c, 0) : UIColor.FromRGB(0x6c, 0xc6, 0x44);
                HeaderView.SetSubImage((x ? Octicon.IssueClosed :Octicon.IssueOpened).ToImage());
            });

            MilestoneElement = new StringElement("Milestone", string.Empty, UITableViewCellStyle.Value1)
            {
                Image = Octicon.Milestone.ToImage()
            };
            MilestoneElement.Tapped = () => ViewModel.GoToMilestonesCommand.ExecuteIfCan();
            this.WhenAnyValue(x => x.ViewModel.AssignedMilestone)
            .Select(x => x == null ? "No Milestone" : x.Title)
            .Subscribe(x => MilestoneElement.Value = x);

            AssigneeElement = new StringElement("Assigned", string.Empty, UITableViewCellStyle.Value1)
            {
                Image = Octicon.Person.ToImage()
            };
            AssigneeElement.Tapped = () => ViewModel.GoToAssigneesCommand.ExecuteIfCan();
            this.WhenAnyValue(x => x.ViewModel.AssignedUser)
            .Select(x => x == null ? "Unassigned" : x.Login)
            .Subscribe(x => AssigneeElement.Value = x);

            LabelsElement = new StringElement("Labels", string.Empty, UITableViewCellStyle.Value1)
            {
                Image = Octicon.Tag.ToImage()
            };
            LabelsElement.Tapped = () => ViewModel.GoToLabelsCommand.ExecuteIfCan();
            this.WhenAnyValue(x => x.ViewModel.AssignedLabels)
            .Select(x => (x == null || x.Count == 0) ? "None" : string.Join(",", x.Select(y => y.Name)))
            .Subscribe(x => LabelsElement.Value = x);

            this.WhenAnyValue(x => x.ViewModel.CanModify)
            .Select(x => x ? UITableViewCellAccessory.DisclosureIndicator : UITableViewCellAccessory.None)
            .Subscribe(x => MilestoneElement.Accessory = AssigneeElement.Accessory = LabelsElement.Accessory = x);

            DetailsSection.Add(MilestoneElement);
            DetailsSection.Add(AssigneeElement);
            DetailsSection.Add(LabelsElement);

            this.WhenAnyValue(x => x.ViewModel.Avatar)
            .SubscribeSafe(x => HeaderView.SetImage(x?.ToUri(128), Images.LoginUserUnknown));

            this.WhenAnyValue(x => x.ViewModel.Issue)
            .IsNotNull()
            .Subscribe(x => {
                HeaderView.Text    = x.Title;
                HeaderView.SubText = x.UpdatedAt.HasValue ?
                                     ("Updated " + x.UpdatedAt.Value.UtcDateTime.Humanize()) :
                                     ("Created " + x.CreatedAt.UtcDateTime.Humanize());
                RefreshHeaderView();
            });

            this.WhenAnyValue(x => x.ViewModel.MarkdownDescription)
            .Subscribe(x =>
            {
                if (string.IsNullOrEmpty(x))
                {
                    DetailsSection.Remove(DescriptionElement);
                }
                else
                {
                    var model    = new DescriptionModel(x, (int)UIFont.PreferredSubheadline.PointSize);
                    var markdown = new MarkdownView {
                        Model = model
                    };
                    var html = markdown.GenerateString();
                    DescriptionElement.Value = html;

                    if (!DetailsSection.Contains(DescriptionElement))
                    {
                        DetailsSection.Insert(0, UITableViewRowAnimation.Fade, DescriptionElement);
                    }
                }
            });

            CommentsSection.FooterView = new TableFooterButton("Add Comment", () => ViewModel.AddCommentCommand.ExecuteIfCan());

            this.WhenAnyValue(x => x.ViewModel.Events)
            .Select(x => x.Changed)
            .Switch()
            .Select(x => ViewModel.Events)
            .Subscribe(events =>
            {
                var comments = events.Select(x =>
                {
                    var body    = string.Empty;
                    var comment = x as IssueCommentItemViewModel;
                    var @event  = x as IssueEventItemViewModel;

                    if (comment != null)
                    {
                        body = comment.Comment;
                    }
                    else if (@event != null)
                    {
                        body = CreateEventBody(@event.EventInfo, @event.Commit);
                    }

                    return(new Comment(x.AvatarUrl.ToUri(), x.Actor, body, x.CreatedAt.Humanize()));
                })
                               .Where(x => !string.IsNullOrEmpty(x.Body))
                               .ToList();

                if (comments.Count > 0)
                {
                    var commentModel = new CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize);
                    var razorView    = new CommentsView {
                        Model = commentModel
                    };
                    var html = razorView.GenerateString();
                    CommentsElement.Value = html;

                    if (!CommentsSection.Contains(CommentsElement))
                    {
                        CommentsSection.Insert(0, UITableViewRowAnimation.Fade, CommentsElement);
                    }
                }
                else
                {
                    CommentsSection.Remove(CommentsElement);
                }
            });

            var commentsButton     = SplitButton.AddButton("Comments", "-");
            var participantsButton = SplitButton.AddButton("Participants", "-");

            this.WhenAnyValue(x => x.ViewModel.CommentCount)
            .Subscribe(x => commentsButton.Text = x.ToString());

            this.WhenAnyValue(x => x.ViewModel.Participants)
            .Subscribe(x => participantsButton.Text = x.ToString());
        }
Example #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var headerSection = new Section();
            var filesSection  = new Section("Files");

            var split    = new SplitButtonElement();
            var files    = split.AddButton("Files", "-");
            var comments = split.AddButton("Comments", "-");
            var forks    = split.AddButton("Forks", "-");

            headerSection.Add(split);

            var commentsSection = new Section("Comments")
            {
                FooterView = new TableFooterButton("Add Comment", ViewModel.AddCommentCommand.ExecuteIfCan)
            };
            var commentsElement = new HtmlElement("comments");

            commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan;
            commentsSection.Add(commentsElement);

            var detailsSection = new Section {
                _splitRow1, _splitRow2
            };

            Root.Reset(headerSection, detailsSection, filesSection, commentsSection);

            var updatedGistObservable = ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null);

            ViewModel.WhenAnyValue(x => x.Gist)
            .IsNotNull()
            .Select(x => x.Owner)
            .Subscribe(x =>
            {
                if (x == null)
                {
                    detailsSection.Remove(_ownerElement);
                }
                else if (x != null && !detailsSection.Contains(_ownerElement))
                {
                    detailsSection.Add(_ownerElement);
                }
            });

            updatedGistObservable.SubscribeSafe(x =>
            {
                if (x.Owner == null)
                {
                    _ownerElement.Value     = "Anonymous";
                    _ownerElement.Accessory = UITableViewCellAccessory.None;
                }
                else
                {
                    _ownerElement.Value     = x.Owner.Login;
                    _ownerElement.Accessory = UITableViewCellAccessory.DisclosureIndicator;
                }

                Root.Reload(_ownerElement);
            });

            updatedGistObservable.SubscribeSafe(x =>
            {
                HeaderView.SubText = x.Description;
                if (x.Owner != null)
                {
                    HeaderView.ImageUri = x.Owner.AvatarUrl;
                }
                else
                {
                    HeaderView.Image = Images.LoginUserUnknown;
                }
                TableView.ReloadData();
            });

            updatedGistObservable.Select(x => x.Files == null ? 0 : x.Files.Count()).SubscribeSafe(x => files.Text = x.ToString());
            updatedGistObservable.SubscribeSafe(x => comments.Text = x.Comments.ToString());
            updatedGistObservable.Select(x => x.Forks == null ? 0 : x.Forks.Count()).SubscribeSafe(x => forks.Text = x.ToString());

            updatedGistObservable.Subscribe(x =>
            {
                var elements = new List <Element>();
                foreach (var file in x.Files.Keys)
                {
                    var sse = new StyledStringElement(file, x.Files[file].Size + " bytes", UITableViewCellStyle.Subtitle)
                    {
                        Accessory     = UITableViewCellAccessory.DisclosureIndicator,
                        LineBreakMode = UILineBreakMode.TailTruncation,
                        Lines         = 1
                    };

                    sse.Tapped += () => ViewModel.GoToFileSourceCommand.Execute(x.Files[file]);
                    elements.Add(sse);
                }

                filesSection.Reset(elements);
            });


            ViewModel.Comments.Changed.Subscribe(_ =>
            {
                var commentModels = ViewModel.Comments
                                    .Select(x => new Comment(x.User.AvatarUrl, x.User.Login, x.BodyHtml, x.CreatedAt.UtcDateTime.Humanize()))
                                    .ToList();

                if (commentModels.Count > 0)
                {
                    var razorView = new CommentsView {
                        Model = commentModels
                    };
                    var html = razorView.GenerateString();
                    commentsElement.Value = html;

                    if (!commentsSection.Contains(commentsElement))
                    {
                        commentsSection.Insert(0, UITableViewRowAnimation.Fade, commentsElement);
                    }
                }
                else
                {
                    commentsSection.Remove(commentsElement);
                }
            });
        }
Example #5
0
        private Section VerifyScreen(Section section)
        {
            if (!section.Contains("Height"))
                section.Add(new Setting("Height", "0"));

            if (!section.Contains("Width"))
                section.Add(new Setting("Width", "0"));

            if (!section.Contains("Top"))
                section.Add(new Setting("Top", "0"));

            if (!section.Contains("Left"))
                section.Add(new Setting("Left", "0"));

            if (section["Height"].DoubleValue != 0 && section["Height"].DoubleValue > SystemParameters.VirtualScreenHeight)
                section["Height"].DoubleValue = SystemParameters.VirtualScreenHeight;

            if (section["Width"].DoubleValue != 0 && section["Width"].DoubleValue > SystemParameters.VirtualScreenWidth)
                section["Width"].DoubleValue = SystemParameters.VirtualScreenWidth;

            if (section["Top"].DoubleValue != 0 && ((section["Top"].DoubleValue + section["Height"].DoubleValue) / 2) > (SystemParameters.VirtualScreenHeight - section["Height"].DoubleValue))
                section["Top"].DoubleValue = (SystemParameters.VirtualScreenHeight - section["Height"].DoubleValue);

            if (section["Left"].DoubleValue != 0 && ((section["Left"].DoubleValue + section["Width"].DoubleValue) / 2) > (SystemParameters.VirtualScreenWidth - section["Width"].DoubleValue))
                section["Left"].DoubleValue = (SystemParameters.VirtualScreenWidth - section["Width"].DoubleValue);

            if (section["Top"].DoubleValue < 0)
                section["Top"].DoubleValue = 1;

            if (section["Left"].DoubleValue < 0)
                section["Left"].DoubleValue = 1;

            return section;
        }
Example #6
0
        private Section VerifyGenericButton(Section section)
        {
            if (!section.Contains("Background"))
                section.Add(new Setting("Background", "#D3D3D3"));

            if (!section.Contains("Foreground"))
                section.Add(new Setting("Foreground", "#000000"));

            if (!section.Contains("Text"))
                section.Add(new Setting("Text", "DefaultText"));

            if (!section.Contains("File"))
                section.Add(new Setting("File", ""));

            return section;
        }
Example #7
0
        private Section VerifyGeneral(Section section)
        {
            if (!section.Contains("Rows"))
                section.Add(new Setting("Rows", "3"));

            if (!section.Contains("Columns"))
                section.Add(new Setting("Columns", "3"));

            return section;
        }
Example #8
0
 public bool Contains(KeyValuePair <string, string> item)
 {
     return(Section?.Contains(item) ?? false);
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.Image = Images.LoginUserUnknown;
            HeaderView.SubImageView.TintColor = UIColor.FromRGB(243, 156, 18);

            var headerSection = new Section();
            var filesSection  = new Section();

            var split    = new SplitButtonElement();
            var files    = split.AddButton("Files", "-");
            var comments = split.AddButton("Comments", "-");
            var forks    = split.AddButton("Forks", "-");

            headerSection.Add(split);

            var footerButton    = new TableFooterButton("Add Comment");
            var commentsSection = new Section(null, footerButton);
            var commentsElement = new HtmlElement("comments");

            commentsSection.Add(commentsElement);

            var splitRow1      = new SplitViewElement(Octicon.Lock.ToImage(), Octicon.Package.ToImage());
            var splitRow2      = new SplitViewElement(Octicon.Pencil.ToImage(), Octicon.Star.ToImage());
            var ownerElement   = new ButtonElement("Owner", Octicon.Person.ToImage());
            var detailsSection = new Section {
                splitRow1, splitRow2, ownerElement
            };

            Root.Reset(headerSection, detailsSection, filesSection, commentsSection);

            Appeared.Take(1).Delay(TimeSpan.FromSeconds(0.35f))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Select(_ => this.WhenAnyValue(x => x.ViewModel.IsStarred).Where(x => x.HasValue))
            .Switch()
            .Select(x => x.Value ? Octicon.Star.ToImage() : null)
            .Subscribe(HeaderView.SetSubImage);

            ViewModel.Comments.Changed.Subscribe(_ => {
                var commentModels = ViewModel.Comments
                                    .Select(x => {
                    var avatarUrl = x?.User?.AvatarUrl;
                    var avatar    = new GitHubAvatar(avatarUrl);
                    return(new Comment(avatar.ToUri(), x.User.Login, x.BodyHtml, x.CreatedAt.UtcDateTime.Humanize()));
                }).ToList();

                if (commentModels.Count > 0)
                {
                    var model     = new CommentModel(commentModels, (int)UIFont.PreferredSubheadline.PointSize);
                    var razorView = new CommentsView {
                        Model = model
                    };
                    var html = razorView.GenerateString();
                    commentsElement.Value = html;

                    if (!commentsSection.Contains(commentsElement))
                    {
                        commentsSection.Insert(0, UITableViewRowAnimation.Fade, commentsElement);
                    }
                }
                else
                {
                    commentsSection.Remove(commentsElement);
                }
            });

            OnActivation(d => {
                d(footerButton.Clicked.InvokeCommand(ViewModel.AddCommentCommand));
                d(HeaderView.Clicked.InvokeCommand(ViewModel.GoToOwnerCommand));
                d(commentsElement.UrlRequested.InvokeCommand(ViewModel.GoToUrlCommand));
                d(splitRow2.Button2.Clicked.InvokeCommand(ViewModel.ToggleStarCommand));
                d(ownerElement.Clicked.InvokeCommand(ViewModel.GoToOwnerCommand));
                d(DialogSource.SelectedObservable.OfType <FileElement>().Select(x => x.File).InvokeCommand(ViewModel.GoToFileSourceCommand));

                var updatedGistObservable = ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null);
                d(updatedGistObservable.SubscribeSafe(x => RefreshHeaderView(subtext: x.Description)));
                d(updatedGistObservable.Subscribe(x => filesSection.Reset(x.Files.Select(y => new FileElement(y.Value)))));
                d(ownerElement.BindValue(updatedGistObservable.Select(x => x.Owner?.Login ?? "Anonymous")));
                d(files.BindText(updatedGistObservable.Select(x => x.Files?.Count() ?? 0)));
                d(forks.BindText(updatedGistObservable.Select(x => x.Forks?.Count() ?? 0)));
                d(comments.BindText(updatedGistObservable.Select(x => x.Comments.ToString())));
                d(splitRow1.Button1.BindText(updatedGistObservable.Select(x => x.Public ? "Public" : "Private")));
                d(splitRow1.Button2.BindText(updatedGistObservable.Select(x => "Revisions".ToQuantity(x.History?.Count ?? 0))));

                d(this.WhenAnyValue(x => x.ViewModel.Gist.Owner).Select(x => x == null)
                  .Subscribe(x => ownerElement.Hidden = x));

                d(this.WhenAnyValue(x => x.ViewModel.Avatar)
                  .Subscribe(x => HeaderView.SetImage(x?.ToUri(64), Images.LoginUserUnknown)));

                d(this.WhenAnyValue(x => x.ViewModel.ShowMenuCommand)
                  .ToBarButtonItem(UIBarButtonSystemItem.Action, x => NavigationItem.RightBarButtonItem = x));

                d(this.WhenAnyValue(x => x.ViewModel.IsStarred)
                  .Where(x => x.HasValue)
                  .Select(x => x.Value ? "Starred!" : "Unstarred")
                  .Subscribe(x => splitRow2.Button2.Text = x));

                d(splitRow2.Button1.BindText(this.WhenAnyValue(x => x.ViewModel.Gist).Select(x => {
                    var delta = DateTimeOffset.UtcNow.UtcDateTime - x.UpdatedAt.UtcDateTime;
                    return((delta.Days <= 0) ? "Created Today" : string.Format("{0} Days Old", delta.Days));
                })));
            });
        }
Example #10
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.Image = Images.LoginUserUnknown;
            HeaderView.SubImageView.TintColor = UIColor.FromRGB(243, 156, 18);

            var headerSection = new Section();
            var filesSection  = new Section();

            var split    = new SplitButtonElement();
            var files    = split.AddButton("Files", "-");
            var comments = split.AddButton("Comments", "-");
            var forks    = split.AddButton("Forks", "-");

            headerSection.Add(split);

            var commentsSection = new Section()
            {
                FooterView = new TableFooterButton("Add Comment", ViewModel.AddCommentCommand.ExecuteIfCan)
            };
            var commentsElement = new HtmlElement("comments");

            commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan;
            commentsSection.Add(commentsElement);

            var detailsSection = new Section {
                _splitRow1, _splitRow2
            };

            Root.Reset(headerSection, detailsSection, filesSection, commentsSection);

            var updatedGistObservable = ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null);

            ViewModel.WhenAnyValue(x => x.Gist)
            .IsNotNull()
            .Select(x => x.Owner)
            .Subscribe(x =>
            {
                if (x == null)
                {
                    detailsSection.Remove(_ownerElement);
                }
                else if (x != null && !detailsSection.Contains(_ownerElement))
                {
                    detailsSection.Add(_ownerElement);
                }
            });


            updatedGistObservable
            .Select(x => x?.Owner?.Login ?? "Anonymous")
            .Subscribe(x => _ownerElement.Value = x);

            updatedGistObservable
            .Select(x => x.Owner != null ? () => ViewModel.GoToOwnerCommand.ExecuteIfCan() : (Action)null)
            .SubscribeSafe(x => _ownerElement.Tapped = x);

            this.WhenAnyValue(x => x.ViewModel.Avatar)
            .Subscribe(x => HeaderView.SetImage(x?.ToUri(64), Images.LoginUserUnknown));

            updatedGistObservable.SubscribeSafe(x => {
                HeaderView.SubText = x.Description;
                RefreshHeaderView();
            });

            updatedGistObservable.Select(x => x.Files == null ? 0 : x.Files.Count()).SubscribeSafe(x => files.Text = x.ToString());
            updatedGistObservable.SubscribeSafe(x => comments.Text = x.Comments.ToString());
            updatedGistObservable.Select(x => x.Forks == null ? 0 : x.Forks.Count()).SubscribeSafe(x => forks.Text = x.ToString());

            updatedGistObservable.Subscribe(x =>
            {
                var elements = new List <Element>();
                foreach (var file in x.Files.Keys)
                {
                    var sse     = new StringElement(file);
                    sse.Image   = Octicon.FileCode.ToImage();
                    sse.Tapped += () => ViewModel.GoToFileSourceCommand.Execute(x.Files[file]);
                    elements.Add(sse);
                }

                filesSection.Reset(elements);
            });


            ViewModel.Comments.Changed.Subscribe(_ => {
                var commentModels = ViewModel.Comments
                                    .Select(x => {
                    var avatarUrl = x?.User?.AvatarUrl;
                    var avatar    = new GitHubAvatar(avatarUrl);
                    return(new Comment(avatar.ToUri(), x.User.Login, x.BodyHtml, x.CreatedAt.UtcDateTime.Humanize()));
                }).ToList();

                if (commentModels.Count > 0)
                {
                    var model     = new CommentModel(commentModels, (int)UIFont.PreferredSubheadline.PointSize);
                    var razorView = new CommentsView {
                        Model = model
                    };
                    var html = razorView.GenerateString();
                    commentsElement.Value = html;

                    if (!commentsSection.Contains(commentsElement))
                    {
                        commentsSection.Insert(0, UITableViewRowAnimation.Fade, commentsElement);
                    }
                }
                else
                {
                    commentsSection.Remove(commentsElement);
                }
            });
        }
Example #11
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var headerSection = new Section(HeaderView);
            var filesSection  = new Section("Files");

            var split    = new SplitButtonElement();
            var files    = split.AddButton("Files", "-");
            var comments = split.AddButton("Comments", "-");
            var forks    = split.AddButton("Forks", "-");

            headerSection.Add(split);

            var commentsSection = new Section("Comments");
            var commentsElement = new WebElement("comments");

            commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan;
            commentsSection.Add(commentsElement);

            var detailsSection = new Section();
            var splitElement1  = new SplitElement();

            splitElement1.Button1 = new SplitElement.SplitButton(Images.Locked, string.Empty);
            splitElement1.Button2 = new SplitElement.SplitButton(Images.Language, string.Empty);
            detailsSection.Add(splitElement1);

            var splitElement2 = new SplitElement();

            splitElement2.Button1 = new SplitElement.SplitButton(Images.Update, string.Empty);
            splitElement2.Button2 = new SplitElement.SplitButton(Images.Star2, string.Empty, ViewModel.ToggleStarCommand.ExecuteIfCan);
            detailsSection.Add(splitElement2);

            var owner = new StyledStringElement("Owner", string.Empty)
            {
                Image = Images.Person
            };

            owner.Tapped += () => ViewModel.GoToUserCommand.ExecuteIfCan();

            var addComment = new StyledStringElement("Add Comment", ViewModel.AddCommentCommand.ExecuteIfCan, Images.Pencil);

            commentsSection.Add(addComment);

            Root.Reset(headerSection, detailsSection, filesSection, commentsSection);

            var updatedGistObservable = ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null);

            ViewModel.WhenAnyValue(x => x.Gist).IsNotNull().Select(x => x.Owner).Subscribe(x =>
            {
                if (x == null)
                {
                    detailsSection.Remove(owner);
                }
                else if (x != null && !detailsSection.Contains(owner))
                {
                    detailsSection.Add(owner);
                }
            });

            updatedGistObservable.SubscribeSafe(x =>
            {
                var publicGist    = x.Public.HasValue && x.Public.Value;
                var revisionCount = x.History == null ? 0 : x.History.Count;

                splitElement1.Button1.Text  = publicGist ? "Public" : "Private";
                splitElement1.Button1.Image = publicGist ? Images.Unlocked : Images.Locked;
                splitElement1.Button2.Text  = revisionCount + " Revisions";
                splitElement2.Button1.Text  = x.UpdatedAt.ToLocalTime().ToString("MM/dd/yy");
            });

            updatedGistObservable.SubscribeSafe(x =>
            {
                if (x.Owner == null)
                {
                    owner.Value     = "Anonymous";
                    owner.Accessory = UITableViewCellAccessory.None;
                }
                else
                {
                    owner.Value     = x.Owner.Login;
                    owner.Accessory = UITableViewCellAccessory.DisclosureIndicator;
                }

                Root.Reload(owner);
            });

            ViewModel.WhenAnyValue(x => x.IsStarred).Where(x => x.HasValue).Subscribe(x =>
            {
                splitElement2.Button2.Text  = x.Value ? "Starred!" : "Unstarred";
                splitElement2.Button2.Image = x.Value ? Images.Star : Images.Star2;
            });

            updatedGistObservable.SubscribeSafe(x =>
            {
                HeaderView.SubText = x.Description;
                if (x.Owner != null)
                {
                    HeaderView.ImageUri = x.Owner.AvatarUrl;
                }
                else
                {
                    HeaderView.Image = Images.LoginUserUnknown;
                }
                ReloadData();
            });

            updatedGistObservable.Select(x => x.Files == null ? 0 : x.Files.Count()).SubscribeSafe(x => files.Text = x.ToString());
            updatedGistObservable.SubscribeSafe(x => comments.Text = x.Comments.ToString());
            updatedGistObservable.Select(x => x.Forks == null ? 0 : x.Forks.Count()).SubscribeSafe(x => forks.Text = x.ToString());

            updatedGistObservable.Subscribe(x =>
            {
                var elements = new List <Element>();
                foreach (var file in x.Files.Keys)
                {
                    var sse = new StyledStringElement(file, x.Files[file].Size + " bytes", UITableViewCellStyle.Subtitle)
                    {
                        Accessory     = UITableViewCellAccessory.DisclosureIndicator,
                        LineBreakMode = UILineBreakMode.TailTruncation,
                        Lines         = 1
                    };

                    sse.Tapped += () => ViewModel.GoToFileSourceCommand.Execute(x.Files[file]);
                    elements.Add(sse);
                }

                filesSection.Reset(elements);
            });


            ViewModel.Comments.Changed.Subscribe(_ =>
            {
                var commentModels = ViewModel.Comments
                                    .Select(x => new Comment(x.User.AvatarUrl, x.User.Login, x.BodyHtml, x.CreatedAt.ToDaysAgo()))
                                    .ToList();

                if (commentModels.Count > 0)
                {
                    var razorView = new CommentsView {
                        Model = commentModels
                    };
                    var html = razorView.GenerateString();
                    commentsElement.Value = html;

                    if (!commentsSection.Contains(commentsElement))
                    {
                        commentsSection.Insert(0, UITableViewRowAnimation.Fade, commentsElement);
                    }
                }
                else
                {
                    commentsSection.Remove(commentsElement);
                }
            });
        }
Example #12
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var secDetails      = new Section();
            var commentsSection = new Section(null, new TableFooterButton("Add Comment", () => ViewModel.AddCommentCommand.ExecuteIfCan()));
            var commentsElement = new HtmlElement("comments");

            commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan;

            var descriptionElement = new HtmlElement("description");

            descriptionElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan;

            secDetails.Add(_milestoneElement);
            secDetails.Add(_assigneeElement);
            secDetails.Add(_labelsElement);

            var addCommentElement = new StyledStringElement("Add Comment")
            {
                Image = Images.Pencil
            };

            this.WhenViewModel(x => x.MarkdownDescription).Subscribe(x =>
            {
                if (string.IsNullOrEmpty(x))
                {
                    secDetails.Remove(descriptionElement);
                }
                else
                {
                    var markdown = new DescriptionView {
                        Model = x
                    };
                    var html = markdown.GenerateString();
                    descriptionElement.Value = html;

                    if (!secDetails.Contains(descriptionElement))
                    {
                        secDetails.Insert(0, UITableViewRowAnimation.Fade, descriptionElement);
                    }
                }
            });

            ViewModel.Events.Changed.Subscribe(_ =>
            {
                var commentModels = ViewModel.Events
                                    .Select(x =>
                {
                    var body    = string.Empty;
                    var comment = x as IssueCommentItemViewModel;
                    var @event  = x as IssueEventItemViewModel;

                    if (comment != null)
                    {
                        body = comment.Comment;
                    }
                    else if (@event != null)
                    {
                        body = CreateEventBody(@event.EventInfo, @event.Commit);
                    }

                    return(new Comment(x.AvatarUrl, x.Actor, body, x.CreatedAt.LocalDateTime.Humanize()));
                })
                                    .Where(x => !string.IsNullOrEmpty(x.Body))
                                    .ToList();

                if (commentModels.Count > 0)
                {
                    var razorView = new CommentsView {
                        Model = commentModels
                    };
                    var html = razorView.GenerateString();
                    commentsElement.Value = html;

                    if (!commentsSection.Contains(commentsElement))
                    {
                        commentsSection.Insert(0, UITableViewRowAnimation.Fade, commentsElement);
                    }
                }
                else
                {
                    commentsSection.Remove(commentsElement);
                }
            });

            Root.Reset(new Section(), secDetails, commentsSection);
        }