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

            var followers     = new ButtonElement("Followers", AtlassianIcon.Star);
            var events        = new ButtonElement("Events", AtlassianIcon.Blogroll);
            var organizations = new ButtonElement("Groups", AtlassianIcon.Group);
            var repos         = new ButtonElement("Repositories", AtlassianIcon.Devtoolsrepository);
            var members       = new ButtonElement("Members", AtlassianIcon.User);
            var midSec        = new Section(new UIView(new CGRect(0, 0, 0, 20f)))
            {
                events, organizations, members, followers
            };

            Root.Reset(midSec, new Section {
                repos
            });

            OnActivation(disposable =>
            {
                followers.BindClick(ViewModel.GoToFollowersCommand).AddTo(disposable);
                events.BindClick(ViewModel.GoToEventsCommand).AddTo(disposable);
                organizations.BindClick(ViewModel.GoToGroupsCommand).AddTo(disposable);
                repos.BindClick(ViewModel.GoToRepositoriesCommand).AddTo(disposable);
                members.BindClick(ViewModel.GoToMembersCommand).AddTo(disposable);

                this.WhenAnyValue(x => x.ViewModel.Team)
                .Select(x => x == null ? null : new Avatar(x.Links.Avatar.Href).ToUrl(128))
                .Subscribe(x => HeaderView.SetImage(x, Images.Avatar))
                .AddTo(disposable);

                this.WhenAnyValue(x => x.ViewModel.DisplayName)
                .Subscribe(x => RefreshHeaderView(subtext: x))
                .AddTo(disposable);
            });
        }
예제 #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var followers      = new ButtonElement("Followers", AtlassianIcon.Star.ToImage());
            var events         = new ButtonElement("Events", AtlassianIcon.Blogroll.ToImage());
            var groups         = new ButtonElement("Groups", AtlassianIcon.Group.ToImage());
            var repos          = new ButtonElement("Repositories", AtlassianIcon.Devtoolsrepository.ToImage());
            var following      = new ButtonElement("Following", AtlassianIcon.View.ToImage());
            var websiteSection = new Section();
            var website        = new ButtonElement("Website", AtlassianIcon.Weblink.ToImage());
            var midSec         = new Section(new UIView(new CGRect(0, 0, 0, 20f)))
            {
                events, followers, following
            };

            Root.Reset(midSec, new Section {
                repos
            }, websiteSection);

            OnActivation(disposable =>
            {
                followers.BindClick(ViewModel.GoToFollowersCommand).AddTo(disposable);
                events.BindClick(ViewModel.GoToEventsCommand).AddTo(disposable);
                groups.BindClick(ViewModel.GoToGroupsCommand).AddTo(disposable);
                repos.BindClick(ViewModel.GoToRepositoriesCommand).AddTo(disposable);
                following.BindClick(ViewModel.GoToFollowingCommand).AddTo(disposable);
                website.BindClick(ViewModel.GoToWebsiteCommand).AddTo(disposable);

                this.WhenAnyValue(x => x.ViewModel.User)
                .Select(x => x == null ? null : new Avatar(x.Links.Avatar.Href).ToUrl(128))
                .Subscribe(x => HeaderView.SetImage(x, Images.Avatar))
                .AddTo(disposable);

                this.WhenAnyValue(x => x.ViewModel.DisplayName)
                .Subscribe(x => RefreshHeaderView(subtext: x))
                .AddTo(disposable);
            });

            this.WhenAnyValue(x => x.ViewModel.ShouldShowGroups)
            .Subscribe(x =>
            {
                if (x)
                {
                    midSec.Insert(1, UITableViewRowAnimation.Automatic, groups);
                }
                else
                {
                    midSec.Remove(groups);
                }
            });

            this.WhenAnyValue(x => x.ViewModel.IsWebsiteAvailable)
            .Subscribe(x =>
            {
                if (x)
                {
                    websiteSection.Insert(0, UITableViewRowAnimation.Automatic, website);
                }
                else
                {
                    websiteSection.Remove(website);
                }
            });
        }
예제 #3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.SetImage(null, Images.Avatar);

            var detailsSection   = new Section();
            var diffButton       = new ButtonElement(AtlassianIcon.ListAdd.ToImage());
            var removedButton    = new ButtonElement(AtlassianIcon.ListRemove.ToImage());
            var modifiedButton   = new ButtonElement(AtlassianIcon.Edit.ToImage());
            var allChangesButton = new ButtonElement("All Changes", AtlassianIcon.Devtoolssidediff.ToImage());

            detailsSection.Add(new [] { diffButton, removedButton, modifiedButton, allChangesButton });

            var additions = ViewModel.WhenAnyValue(x => x.DiffAdditions);

            diffButton.BindClick(ViewModel.GoToAddedFiles);
            diffButton.BindDisclosure(additions.Select(x => x > 0));
            diffButton.BindCaption(additions.Select(x => $"{x} Added"));

            var deletions = ViewModel.WhenAnyValue(x => x.DiffDeletions);

            removedButton.BindClick(ViewModel.GoToRemovedFiles);
            removedButton.BindDisclosure(deletions.Select(x => x > 0));
            removedButton.BindCaption(deletions.Select(x => $"{x} Removed"));

            var modifications = ViewModel.WhenAnyValue(x => x.DiffModifications);

            modifiedButton.BindClick(ViewModel.GoToModifiedFiles);
            modifiedButton.BindDisclosure(modifications.Select(x => x > 0));
            modifiedButton.BindCaption(modifications.Select(x => $"{x} Modified"));

            allChangesButton.BindClick(ViewModel.GoToAllFiles);

            var split         = new SplitButtonElement();
            var commentCount  = split.AddButton("Comments", "-");
            var participants  = split.AddButton("Participants", "-");
            var approvals     = split.AddButton("Approvals", "-");
            var headerSection = new Section {
                split
            };

            var actionButton = new UIBarButtonItem(UIBarButtonSystemItem.Action);

            NavigationItem.RightBarButtonItem = actionButton;

            var detailSection  = new Section();
            var detailsElement = new MultilinedElement();

            detailSection.Add(detailsElement);

            var approvalSection = new Section("Approvals");
            var approveElement  = new LoaderButtonElement("Approve", AtlassianIcon.Approve.ToImage());

            approveElement.Accessory = UITableViewCellAccessory.None;
            approveElement.BindLoader(ViewModel.ToggleApproveButton);
            approveElement.BindCaption(ViewModel.WhenAnyValue(x => x.Approved).Select(x => x ? "Unapprove" : "Approve"));

            var commentsSection   = new Section("Comments");
            var addCommentElement = new ButtonElement("Add Comment", AtlassianIcon.Addcomment.ToImage());

            commentsSection.Add(addCommentElement);

            if (ViewModel.ShowRepository)
            {
                var repo = new ButtonElement(ViewModel.Repository)
                {
                    TextColor = StringElement.DefaultDetailColor,
                    Image     = AtlassianIcon.Devtoolsrepository.ToImage()
                };

                detailSection.Add(repo);
                repo.Clicked.SelectUnit().BindCommand(ViewModel.GoToRepositoryCommand);
            }

            ViewModel.WhenAnyValue(x => x.Commit).Where(x => x != null).Subscribe(x => {
                participants.Text = x?.Participants?.Count.ToString() ?? "-";
                approvals.Text    = x?.Participants?.Count(y => y.Approved).ToString() ?? "-";

                var titleMsg  = (ViewModel.Commit.Message ?? string.Empty).Split(new [] { '\n' }, 2).FirstOrDefault();
                var avatarUrl = ViewModel.Commit.Author?.User?.Links?.Avatar?.Href;

                HeaderView.SubText = titleMsg ?? "Commited " + (ViewModel.Commit.Date).Humanize();
                HeaderView.SetImage(new Avatar(avatarUrl).ToUrl(128), Images.Avatar);
                RefreshHeaderView();

                var user = x.Author?.User?.DisplayName ?? x.Author?.Raw ?? "Unknown";
                detailsElement.Caption = user;
                detailsElement.Details = x.Message;
            });

            this.WhenAnyValue(x => x.ViewModel.Approvals)
            .Select(x => x.Select(y => new UserElement(y)).OfType <Element>())
            .Subscribe(x => approvalSection.Reset(x.Concat(new[] { approveElement })));

            ViewModel.Comments
            .CountChanged
            .Select(x => x.ToString())
            .StartWith("-")
            .Subscribe(x => commentCount.Text = x);

            ViewModel
            .Comments
            .ChangedObservable()
            .Subscribe(x =>
            {
                if (x.Count > 0)
                {
                    var comments     = x.Select(y => new Comment(y.Avatar.ToUrl(), y.Name, y.Content, y.CreatedOn)).ToList();
                    var commentModel = new Views.CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize);
                    var content      = new CommentsView {
                        Model = commentModel
                    }.GenerateString();
                    _commentsElement.SetValue(content);
                    commentsSection.Insert(0, UITableViewRowAnimation.None, _commentsElement);
                }
                else
                {
                    commentsSection.Remove(_commentsElement);
                }
            });

            ViewModel.WhenAnyValue(x => x.Commit)
            .Where(x => x != null)
            .Take(1)
            .Subscribe(_ => Root.Reset(headerSection, detailsSection, approvalSection, commentsSection));

            ViewModel.GoToAddedFiles.Select(_ => CommitFileType.Added).Subscribe(GoToFiles);
            ViewModel.GoToRemovedFiles.Select(_ => CommitFileType.Removed).Subscribe(GoToFiles);
            ViewModel.GoToModifiedFiles.Select(_ => CommitFileType.Modified).Subscribe(GoToFiles);
            ViewModel.GoToAllFiles.Subscribe(_ => GoToAllFiles());

            OnActivation(d =>
            {
                actionButton
                .GetClickedObservable()
                .Select(x => (object)x)
                .BindCommand(ViewModel.ShowMenuCommand)
                .AddTo(d);

                addCommentElement
                .Clicked
                .SelectUnit()
                .BindCommand(ViewModel.AddCommentCommand)
                .AddTo(d);

                this.WhenAnyObservable(x => x.ViewModel.AddCommentCommand)
                .Subscribe(_ => NewCommentViewController.Present(this, ViewModel.AddComment))
                .AddTo(d);
            });
        }