Exemplo n.º 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.SetImage(null, Images.RepoPlaceholder);

            NavigationItem.RightBarButtonItem         = new UIBarButtonItem(UIBarButtonSystemItem.Action);
            NavigationItem.RightBarButtonItem.Enabled = false;

            var watchers = _split.AddButton("Watchers", "-");
            var forks    = _split.AddButton("Forks", "-");
            var branches = _split.AddButton("Branches", "-");

            ViewModel.Bind(x => x.Branches).Subscribe(_ => Render(ViewModel.Repository));
            ViewModel.Bind(x => x.Issues).Subscribe(_ => Render(ViewModel.Repository));
            ViewModel.Bind(x => x.HasReadme).Subscribe(_ => Render(ViewModel.Repository));

            OnActivation(d =>
            {
                d(watchers.Clicked.BindCommand(ViewModel.GoToStargazersCommand));
                d(ViewModel.Bind(x => x.Branches, true).Subscribe(x => branches.Text = x?.Count.ToString() ?? "-"));
                d(ViewModel.Bind(x => x.Repository, true).Subscribe(x =>
                {
                    watchers.Text = x?.FollowersCount.ToString();
                    forks.Text    = x?.ForkCount.ToString();
                    NavigationItem.RightBarButtonItem.Enabled = true;
                    Render(x);
                }));
            });
        }
Exemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

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

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

            var split         = new SplitButtonElement();
            var followers     = split.AddButton("Followers", "-");
            var following     = split.AddButton("Following", "-");
            var events        = new StringElement("Events", Octicon.Rss.ToImage());
            var organizations = new StringElement("Organizations", Octicon.Organization.ToImage());
            var repos         = new StringElement("Repositories", Octicon.Repo.ToImage());
            var gists         = new StringElement("Gists", Octicon.Gist.ToImage());
            var website       = new StringElement("Website", Octicon.Globe.ToImage())
            {
                Hidden = true
            };

            Root.Reset(new [] { new Section {
                                    split
                                }, new Section {
                                    events, organizations, repos, gists
                                }, new Section {
                                    website
                                } });

            OnActivation(d => {
                d(followers.Clicked.InvokeCommand(ViewModel.GoToFollowersCommand));
                d(following.Clicked.InvokeCommand(ViewModel.GoToFollowingCommand));
                d(website.Clicked.InvokeCommand(ViewModel.GoToWebsiteCommand));
                d(events.Clicked.InvokeCommand(ViewModel.GoToEventsCommand));
                d(organizations.Clicked.InvokeCommand(ViewModel.GoToOrganizationsCommand));
                d(repos.Clicked.InvokeCommand(ViewModel.GoToRepositoriesCommand));
                d(gists.Clicked.InvokeCommand(ViewModel.GoToGistsCommand));

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

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

                d(this.WhenAnyValue(x => x.ViewModel.User.Name).Select(x => string.IsNullOrEmpty(x) ? null : x)
                  .Subscribe(x => RefreshHeaderView(subtext: x)));

                d(followers.BindText(this.WhenAnyValue(x => x.ViewModel.User.Followers)));
                d(following.BindText(this.WhenAnyValue(x => x.ViewModel.User.Following)));
                d(this.WhenAnyValue(x => x.ViewModel.HasBlog).Subscribe(x => website.Hidden = !x));
            });
        }
Exemplo n.º 3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            TableView.RowHeight          = UITableView.AutomaticDimension;
            TableView.EstimatedRowHeight = 44f;

            var actionButton = new UIBarButtonItem(UIBarButtonSystemItem.Action);

            HeaderView.SetImage(null, Images.Avatar);
            HeaderView.Text              = Title;
            TableView.RowHeight          = UITableView.AutomaticDimension;
            TableView.EstimatedRowHeight = 44f;

            ViewModel.Bind(x => x.Changeset).Subscribe(x => {
                var msg            = x.Commit.Message ?? string.Empty;
                msg                = msg.Split('\n')[0];
                HeaderView.Text    = msg.Split('\n')[0];
                HeaderView.SubText = "Commited " + (ViewModel.Changeset?.Commit?.Committer?.Date ?? DateTimeOffset.Now).Humanize();
                HeaderView.SetImage(x.Author?.AvatarUrl, Images.Avatar);
                RefreshHeaderView();
            });

            ViewModel.Bind(x => x.Changeset).Subscribe(_ => Render());
            ViewModel.BindCollection(x => x.Comments).Subscribe(_ => Render());
            ViewModel.Bind(x => x.ShouldShowPro).Where(x => x).Subscribe(_ => this.ShowPrivateView());

            OnActivation(d =>
            {
                d(HeaderView.Clicked.BindCommand(ViewModel.GoToOwner));
                d(ViewModel.Bind(x => x.Title).Subscribe(x => Title = x));
                d(actionButton.GetClickedObservable().Subscribe(_ => ShowExtraMenu()));
            });
        }
Exemplo n.º 4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.SetImage(null, Images.Avatar);
            Title = ViewModel.Name;

            ViewModel.Bind(x => x.User, x =>
            {
                var name           = x.FirstName + " " + x.LastName;
                HeaderView.SubText = string.IsNullOrWhiteSpace(name) ? x.Username : name;
                HeaderView.SetImage(new Avatar(x.Avatar).ToUrl(128), Images.Avatar);
                RefreshHeaderView();

                var followers     = new StyledStringElement("Followers", () => ViewModel.GoToFollowersCommand.Execute(null), AtlassianIcon.Star.ToImage());
                var events        = new StyledStringElement("Events", () => ViewModel.GoToEventsCommand.Execute(null), AtlassianIcon.Blogroll.ToImage());
                var organizations = new StyledStringElement("Groups", () => ViewModel.GoToGroupsCommand.Execute(null), AtlassianIcon.Group.ToImage());
                var repos         = new StyledStringElement("Repositories", () => ViewModel.GoToRepositoriesCommand.Execute(null), AtlassianIcon.Devtoolsrepository.ToImage());
                var members       = new StyledStringElement("Members", () => ViewModel.GoToMembersCommand.Execute(null), AtlassianIcon.User.ToImage());
                var midSec        = new Section(new UIView(new CGRect(0, 0, 0, 20f)))
                {
                    events, organizations, members, followers
                };
                Root = new RootElement(Title)
                {
                    midSec, new Section {
                        repos
                    }
                };
            });
//          if (!ViewModel.IsLoggedInUser)
//              NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, (s, e) => ShowExtraMenu());
        }
Exemplo n.º 5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

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

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

            var websiteElement = new StringElement("Website", () => ViewModel.GoToWebsiteCommand.ExecuteIfCan(), Octicon.Globe.ToImage());
            var extraSection   = new Section();

            var split         = new SplitButtonElement();
            var followers     = split.AddButton("Followers", "-", () => ViewModel.GoToFollowersCommand.ExecuteIfCan());
            var following     = split.AddButton("Following", "-", () => ViewModel.GoToFollowingCommand.ExecuteIfCan());
            var events        = new StringElement("Events", () => ViewModel.GoToEventsCommand.ExecuteIfCan(), Octicon.Rss.ToImage());
            var organizations = new StringElement("Organizations", () => ViewModel.GoToOrganizationsCommand.ExecuteIfCan(), Octicon.Organization.ToImage());
            var repos         = new StringElement("Repositories", () => ViewModel.GoToRepositoriesCommand.ExecuteIfCan(), Octicon.Repo.ToImage());
            var gists         = new StringElement("Gists", () => ViewModel.GoToGistsCommand.ExecuteIfCan(), Octicon.Gist.ToImage());

            Root.Reset(new [] { new Section {
                                    split
                                }, new Section {
                                    events, organizations, repos, gists
                                }, extraSection });

            this.WhenAnyValue(x => x.ViewModel.IsLoggedInUser)
            .Subscribe(x => NavigationItem.RightBarButtonItem = x ?
                                                                null : ViewModel.ShowMenuCommand.ToBarButtonItem(UIBarButtonSystemItem.Action));

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

            this.WhenAnyValue(x => x.ViewModel.User).IsNotNull().Subscribe(x => {
                followers.Text     = x.Followers.ToString();
                following.Text     = x.Following.ToString();
                HeaderView.SubText = string.IsNullOrEmpty(x.Name) ? null : x.Name;
                RefreshHeaderView();
            });

            this.WhenAnyValue(x => x.ViewModel.HasBlog).Subscribe(x => {
                if (x && websiteElement.Section == null)
                {
                    extraSection.Add(websiteElement);
                }
                else if (!x && websiteElement.Section != null)
                {
                    extraSection.Remove(websiteElement);
                }
            });
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var vm = (OrganizationViewModel)ViewModel;

            HeaderView.SetImage(null, Images.Avatar);
            Title           = vm.Name;
            HeaderView.Text = vm.Name;

            var members   = new StringElement("Members", Octicon.Person.ToImage());
            var teams     = new StringElement("Teams", Octicon.Organization.ToImage());
            var followers = new StringElement("Followers", Octicon.Heart.ToImage());
            var events    = new StringElement("Events", Octicon.Rss.ToImage());
            var repos     = new StringElement("Repositories", Octicon.Repo.ToImage());
            var gists     = new StringElement("Gists", Octicon.Gist.ToImage());

            Root.Reset(new Section(new UIView(new CGRect(0, 0, 0, 20f)))
            {
                members, teams
            }, new Section {
                events, followers
            }, new Section {
                repos, gists
            });

            OnActivation(d =>
            {
                d(teams.Clicked.BindCommand(vm.GoToTeamsCommand));
                d(events.Clicked.BindCommand(vm.GoToEventsCommand));

                d(members.Clicked
                  .Select(_ => UsersViewController.CreateOrganizationMembersViewController(vm.Name))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));

                d(followers.Clicked
                  .Select(_ => UsersViewController.CreateFollowersViewController(vm.Name))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));

                d(repos.Clicked.Subscribe(_ => {
                    var vc = Repositories.RepositoriesViewController.CreateOrganizationViewController(vm.Name);
                    NavigationController?.PushViewController(vc, true);
                }));

                d(gists.Clicked
                  .Select(x => GistsViewController.CreateUserGistsViewController(vm.Name))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));

                d(vm.Bind(x => x.Organization, true).Where(x => x != null).Subscribe(x =>
                {
                    HeaderView.SubText = string.IsNullOrWhiteSpace(x.Name) ? x.Login : x.Name;
                    HeaderView.SetImage(x.AvatarUrl, Images.Avatar);
                    RefreshHeaderView();
                }));
            });
        }
Exemplo n.º 7
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.SetImage(null, Images.Avatar);
            HeaderView.Text = ViewModel.Username;

            var split     = new SplitButtonElement();
            var followers = split.AddButton("Followers", "-");
            var following = split.AddButton("Following", "-");

            var events        = new StringElement("Events", Octicon.Rss.ToImage());
            var organizations = new StringElement("Organizations", Octicon.Organization.ToImage());
            var repos         = new StringElement("Repositories", Octicon.Repo.ToImage());
            var gists         = new StringElement("Gists", Octicon.Gist.ToImage());

            Root.Add(new [] { new Section {
                                  split
                              }, new Section {
                                  events, organizations, repos, gists
                              } });

            ViewModel.Bind(x => x.User).Subscribe(x => {
                followers.Text     = x?.Followers.ToString() ?? "-";
                following.Text     = x?.Following.ToString() ?? "-";
                HeaderView.SubText = string.IsNullOrWhiteSpace(x?.Name) ? null : x.Name;
                HeaderView.SetImage(x?.AvatarUrl, Images.Avatar);
                RefreshHeaderView();
            });

            OnActivation(d =>
            {
                d(followers.Clicked
                  .Select(x => UsersViewController.CreateFollowersViewController(ViewModel.Username))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));

                d(following.Clicked
                  .Select(x => UsersViewController.CreateFollowingViewController(ViewModel.Username))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));

                d(events.Clicked.BindCommand(ViewModel.GoToEventsCommand));
                d(organizations.Clicked.BindCommand(ViewModel.GoToOrganizationsCommand));

                d(gists.Clicked
                  .Select(x => GistsViewController.CreateUserGistsViewController(ViewModel.Username))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));

                d(ViewModel.Bind(x => x.Title, true).Subscribe(x => Title = x));

                d(repos.Clicked.Subscribe(_ =>
                {
                    var vc = Repositories.RepositoriesViewController.CreateUserViewController(ViewModel.Username);
                    NavigationController?.PushViewController(vc, true);
                }));
            });
        }
Exemplo n.º 8
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Pull Request #" + ViewModel.PullRequestId;

            HeaderView.SetImage(null, Images.Avatar);

            ViewModel.Bind(x => x.PullRequest).Subscribe(_ => Render());
            ViewModel.BindCollection(x => x.Comments).Subscribe(_ => Render());
        }
Exemplo n.º 9
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.SubText = "Organization";
            HeaderView.Image   = Images.LoginUserUnknown;

            var split           = new SplitButtonElement();
            var followers       = split.AddButton("Followers", "-");
            var following       = split.AddButton("Following", "-");
            var members         = new StringElement("Members", Octicon.Person.ToImage());
            var teams           = new StringElement("Teams", Octicon.Organization.ToImage());
            var events          = new StringElement("Events", Octicon.Rss.ToImage());
            var repos           = new StringElement("Repositories", Octicon.Repo.ToImage());
            var gists           = new StringElement("Gists", Octicon.Gist.ToImage());
            var membersAndTeams = new Section {
                members
            };

            Root.Reset(new Section {
                split
            }, membersAndTeams, new Section {
                events
            }, new Section {
                repos, gists
            });

            OnActivation(d => {
                d(followers.Clicked.InvokeCommand(ViewModel.GoToFollowersCommand));
                d(following.Clicked.InvokeCommand(ViewModel.GoToFollowingCommand));

                d(members.Clicked.InvokeCommand(ViewModel.GoToMembersCommand));
                d(teams.Clicked.InvokeCommand(ViewModel.GoToTeamsCommand));
                d(events.Clicked.InvokeCommand(ViewModel.GoToEventsCommand));
                d(repos.Clicked.InvokeCommand(ViewModel.GoToRepositoriesCommand));
                d(gists.Clicked.InvokeCommand(ViewModel.GoToGistsCommand));

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

                var orgObs = this.WhenAnyValue(x => x.ViewModel.Organization);
                d(followers.BindText(orgObs.Select(x => x != null ? x.Followers.ToString() : "-")));
                d(following.BindText(orgObs.Select(x => x != null ? x.Following.ToString() : "-")));

                d(this.WhenAnyValue(x => x.ViewModel.CanViewTeams)
                  .Where(x => x && teams.Section == null)
                  .Subscribe(x => membersAndTeams.Add(teams)));

                d(this.WhenAnyValue(x => x.ViewModel.CanViewTeams)
                  .Where(x => !x)
                  .Subscribe(x => membersAndTeams.Remove(teams)));
            });
        }
Exemplo n.º 10
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            var application = Mvx.Resolve <IApplicationService>();

            HeaderView.Text    = application.Account.Username;
            HeaderView.SubText = Title;
            HeaderView.SetImage(null, Images.Avatar);
            RefreshHeaderView();

            CreateTable();
        }
Exemplo n.º 11
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.Text = ViewModel.Username;
            Title           = ViewModel.Username;

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

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

            OnActivation(d =>
            {
                d(followers.Clicked.BindCommand(ViewModel.GoToFollowersCommand));
                d(events.Clicked.BindCommand(ViewModel.GoToEventsCommand));
                d(organizations.Clicked.BindCommand(ViewModel.GoToGroupsCommand));
                d(repos.Clicked.BindCommand(ViewModel.GoToRepositoriesCommand));
                d(following.Clicked.BindCommand(ViewModel.GoToFollowingCommand));

                d(ViewModel.Bind(x => x.User, true).IsNotNull().Subscribe(x =>
                {
                    if (x == null)
                    {
                        HeaderView.SetImage(null, Images.Avatar);
                    }
                    else
                    {
                        var name           = x.FirstName + " " + x.LastName;
                        HeaderView.SubText = string.IsNullOrWhiteSpace(name) ? x.Username : name;
                        HeaderView.SetImage(new Avatar(x.Avatar).ToUrl(128), Images.Avatar);
                        RefreshHeaderView();
                    }
                }));
            });

//			if (!ViewModel.IsLoggedInUser)
//				NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, (s, e) => ShowExtraMenu());
        }
Exemplo n.º 12
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            TableView.RowHeight          = UITableView.AutomaticDimension;
            TableView.EstimatedRowHeight = 80f;

            Title = "Commit";

            HeaderView.SetImage(null, Images.Avatar);

            ViewModel.Bind(x => x.Commits).Subscribe(_ => Render());
            ViewModel.Bind(x => x.Commit).Subscribe(_ => Render());
            ViewModel.BindCollection(x => x.Comments).Subscribe(_ => Render());
            _segmentBarButton.Width = View.Frame.Width - 10f;
        }
Exemplo n.º 13
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

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

            ViewModel.Bind(x => x.Issue).Subscribe(_ => RenderIssue());
            ViewModel.BindCollection(x => x.Comments).Subscribe(_ => RenderComments());

            var compose = NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Compose)
            {
                Enabled = false
            };

            OnActivation(d => d(compose.GetClickedObservable().BindCommand(ViewModel.GoToEditCommand)));
        }
Exemplo n.º 14
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.SubText = "Organization";
            HeaderView.Image   = Images.LoginUserUnknown;

            var split           = new SplitButtonElement();
            var followers       = split.AddButton("Followers", "-", () => ViewModel.GoToFollowersCommand.ExecuteIfCan());
            var following       = split.AddButton("Following", "-", () => ViewModel.GoToFollowingCommand.ExecuteIfCan());
            var members         = new StringElement("Members", () => ViewModel.GoToMembersCommand.ExecuteIfCan(), Octicon.Person.ToImage());
            var teams           = new StringElement("Teams", () => ViewModel.GoToTeamsCommand.ExecuteIfCan(), Octicon.Organization.ToImage());
            var events          = new StringElement("Events", () => ViewModel.GoToEventsCommand.ExecuteIfCan(), Octicon.Rss.ToImage());
            var repos           = new StringElement("Repositories", () => ViewModel.GoToRepositoriesCommand.ExecuteIfCan(), Octicon.Repo.ToImage());
            var gists           = new StringElement("Gists", () => ViewModel.GoToGistsCommand.ExecuteIfCan(), Octicon.Gist.ToImage());
            var membersAndTeams = new Section {
                members
            };

            Root.Reset(new Section {
                split
            }, membersAndTeams, new Section {
                events
            }, new Section {
                repos, gists
            });

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

            this.WhenAnyValue(x => x.ViewModel.Organization)
            .IsNotNull()
            .Subscribe(x => {
                followers.Text = x != null ? x.Followers.ToString() : "-";
                following.Text = x != null ? x.Following.ToString() : "-";
            });

            this.WhenAnyValue(x => x.ViewModel.CanViewTeams)
            .Where(x => x && teams.Section == null)
            .Subscribe(x => membersAndTeams.Add(teams));

            this.WhenAnyValue(x => x.ViewModel.CanViewTeams)
            .Where(x => !x)
            .Subscribe(x => membersAndTeams.Remove(teams));
        }
Exemplo n.º 15
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());
        }
Exemplo n.º 16
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = ViewModel.Name;

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

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

            OnActivation(d =>
            {
                d(followers.Clicked.BindCommand(ViewModel.GoToFollowersCommand));
                d(events.Clicked.BindCommand(ViewModel.GoToEventsCommand));
                d(organizations.Clicked.BindCommand(ViewModel.GoToGroupsCommand));
                d(repos.Clicked.BindCommand(ViewModel.GoToRepositoriesCommand));
                d(members.Clicked.BindCommand(ViewModel.GoToMembersCommand));

                d(ViewModel.Bind(x => x.User, true).Subscribe(x =>
                {
                    if (x == null)
                    {
                        HeaderView.SetImage(null, Images.Avatar);
                    }
                    else
                    {
                        var name           = x.FirstName + " " + x.LastName;
                        HeaderView.SubText = string.IsNullOrWhiteSpace(name) ? x.Username : name;
                        HeaderView.SetImage(new Avatar(x.Avatar).ToUrl(128), Images.Avatar);
                        RefreshHeaderView();
                    }
                }));
            });
        }
Exemplo n.º 17
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.SetImage(null, Images.RepoPlaceholder);

            NavigationItem.RightBarButtonItem         = new UIBarButtonItem(UIBarButtonSystemItem.Action);
            NavigationItem.RightBarButtonItem.Enabled = false;

            ViewModel.Bind(x => x.Repository, x =>
            {
                NavigationItem.RightBarButtonItem.Enabled = true;
                Render(x);
            });

            ViewModel.Bind(x => x.Branches, () => Render(ViewModel.Repository));
            ViewModel.Bind(x => x.Issues, () => Render(ViewModel.Repository));
            ViewModel.Bind(x => x.HasReadme, () => Render(ViewModel.Repository));
        }
Exemplo n.º 18
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);
            });
        }
Exemplo n.º 19
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = ViewModel.Username;
            HeaderView.SetImage(null, Images.Avatar);
            HeaderView.Text = ViewModel.RepositoryName;
            HeaderView.SubImageView.TintColor = UIColor.FromRGB(243, 156, 18);

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

            var actionButton = NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action)
            {
                Enabled = false
            };

            _split      = new SplitButtonElement();
            _stargazers = _split.AddButton("Stargazers", "-");
            _watchers   = _split.AddButton("Watchers", "-");
            _forks      = _split.AddButton("Forks", "-");

            OnActivation(d =>
            {
                d(_watchers.Clicked
                  .Select(_ => ViewModel)
                  .Select(x => UsersViewController.CreateWatchersViewController(x.Username, x.RepositoryName))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));

                d(_stargazers.Clicked
                  .Select(_ => ViewModel)
                  .Select(x => UsersViewController.CreateStargazersViewController(x.Username, x.RepositoryName))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));

                d(actionButton.GetClickedObservable().Subscribe(_ => ShowExtraMenu()));

                d(_forks.Clicked.Subscribe(_ =>
                {
                    var vc = RepositoriesViewController.CreateForkedViewController(ViewModel.Username, ViewModel.RepositoryName);
                    NavigationController?.PushViewController(vc, true);
                }));

                d(_eventsElement.Clicked.BindCommand(ViewModel.GoToEventsCommand));
                d(_ownerElement.Clicked.BindCommand(ViewModel.GoToOwnerCommand));

                d(_commitsElement.Clicked.BindCommand(ViewModel.GoToCommitsCommand));
                d(_pullRequestsElement.Clicked.BindCommand(ViewModel.GoToPullRequestsCommand));
                d(_sourceElement.Clicked.BindCommand(ViewModel.GoToSourceCommand));

                d(ViewModel.Bind(x => x.Branches, true).Subscribe(_ => Render()));
                d(ViewModel.Bind(x => x.Readme, true).Subscribe(_ => Render()));

                d(_forkElement.Value.Clicked.Select(x => ViewModel.Repository.Parent).BindCommand(ViewModel.GoToForkParentCommand));
                d(_issuesElement.Value.Clicked.BindCommand(ViewModel.GoToIssuesCommand));
                d(_readmeElement.Value.Clicked.BindCommand(ViewModel.GoToReadmeCommand));
                d(_websiteElement.Value.Clicked.Select(x => ViewModel.Repository.Homepage).BindCommand(ViewModel.GoToUrlCommand));

                d(HeaderView.Clicked.BindCommand(ViewModel.GoToOwnerCommand));

                d(ViewModel.Bind(x => x.Repository, true).Where(x => x != null).Subscribe(x =>
                {
                    if (x.Private && !_featuresService.IsProEnabled)
                    {
                        if (_privateView == null)
                        {
                            _privateView = this.ShowPrivateView();
                        }
                        actionButton.Enabled = false;
                    }
                    else
                    {
                        actionButton.Enabled = true;
                        _privateView?.Dispose();
                    }

                    ViewModel.ImageUrl = x.Owner?.AvatarUrl;
                    HeaderView.SubText = Emojis.FindAndReplace(x.Description);
                    HeaderView.SetImage(x.Owner?.AvatarUrl, Images.Avatar);
                    Render();
                    RefreshHeaderView();
                }));
            });
        }
Exemplo n.º 20
0
        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;
            var root        = new RootElement(Title)
            {
                UnevenRows = Root.UnevenRows
            };

            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)
            {
                CaptionColor    = Theme.CurrentTheme.MainTextColor,
                ValueColor      = Theme.CurrentTheme.MainTextColor,
                BackgroundColor = UIColor.White
            });

            if (ViewModel.ShowRepository)
            {
                var repo = new StyledStringElement(ViewModel.Repository)
                {
                    Accessory = UIKit.UITableViewCellAccessory.DisclosureIndicator,
                    Lines     = 1,
                    Font      = StyledStringElement.DefaultDetailFont,
                    TextColor = StyledStringElement.DefaultDetailColor,
                    Image     = AtlassianIcon.Devtoolsrepository.ToImage()
                };
                repo.Tapped += () => ViewModel.GoToRepositoryCommand.Execute(null);
                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.Tapped += () => ViewModel.GoToFileCommand.Execute(y);
                        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 imgUri = new Avatar(comment.User.Links?.Avatar?.Href);
                    commentSection.Add(new NameTimeStringElement(name, comment.Content.Raw, comment.CreatedOn, imgUri.ToUrl(), Images.Avatar));
                }

                if (commentSection.Elements.Count > 0)
                {
                    root.Add(commentSection);
                }

                var addComment = new StyledStringElement("Add Comment")
                {
                    Image = AtlassianIcon.Addcomment.ToImage()
                };
                addComment.Tapped += 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 el     = new UserElement(l.User.DisplayName, string.Empty, string.Empty, l.User.Links.Avatar.Href);
                    el.Tapped += () => ViewModel.GoToUserCommand.Execute(l.User.Username);
                    return(el);
                }));

                if (likeSection.Elements.Count > 0)
                {
                    root.Add(likeSection);
                }

                StyledStringElement approveButton;
                if (ViewModel.Commit.Participants.Any(x => x.User.Username.Equals(ViewModel.GetApplication().Account.Username) && x.Approved))
                {
                    approveButton = new StyledStringElement("Unapprove")
                    {
                        Image = AtlassianIcon.Approve.ToImage()
                    };
                    approveButton.Tapped += () => this.DoWorkAsync("Unapproving...", ViewModel.Unapprove);
                }
                else
                {
                    approveButton = new StyledStringElement("Approve")
                    {
                        Image = AtlassianIcon.Approve.ToImage()
                    };
                    approveButton.Tapped += () => this.DoWorkAsync("Approving...", ViewModel.Approve);
                }
                root.Add(new Section {
                    approveButton
                });
            }

            Root = root;
        }
Exemplo n.º 21
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);
                }
            });
        }
Exemplo n.º 22
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.Image = Images.LoginUserUnknown;

            _sourceSection = new Section
            {
                new StringElement("Commits", () => ViewModel.GoToCommitsCommand.ExecuteIfCan(), Octicon.GitCommit.ToImage()),
                new StringElement("Pull Requests", () => ViewModel.GoToPullRequestsCommand.ExecuteIfCan(), Octicon.GitPullRequest.ToImage()),
                new StringElement("Source", () => ViewModel.GoToSourceCommand.ExecuteIfCan(), Octicon.Code.ToImage()),
            };

            _ownerElement = new StringElement("Owner", string.Empty)
            {
                Image = Octicon.Person.ToImage()
            };
            _ownerElement.Tapped += () => ViewModel.GoToOwnerCommand.ExecuteIfCan();
            this.WhenAnyValue(x => x.ViewModel.Repository)
            .Subscribe(x => _ownerElement.Value = x == null ? string.Empty : x.Owner.Login);

            HeaderView.SubImageView.TintColor = UIColor.FromRGB(243, 156, 18);
            this.WhenAnyValue(x => x.ViewModel.GoToOwnerCommand).Subscribe(x =>
                                                                           HeaderView.ImageButtonAction = x != null ? new Action(() => ViewModel.GoToOwnerCommand.ExecuteIfCan()) : null);

            _splitElements[0]         = new SplitViewElement();
            _splitElements[0].Button1 = new SplitViewElement.SplitButton(Octicon.Lock.ToImage(), string.Empty);
            _splitElements[0].Button2 = new SplitViewElement.SplitButton(Octicon.Package.ToImage(), string.Empty);

            _splitElements[1]         = new SplitViewElement();
            _splitElements[1].Button1 = new SplitViewElement.SplitButton(Octicon.IssueOpened.ToImage(), string.Empty, () => ViewModel.GoToIssuesCommand.ExecuteIfCan());
            _splitElements[1].Button2 = new SplitViewElement.SplitButton(Octicon.Organization.ToImage(), string.Empty, () => ViewModel.GoToContributors.ExecuteIfCan());

            _splitElements[2]         = new SplitViewElement();
            _splitElements[2].Button1 = new SplitViewElement.SplitButton(Octicon.Tag.ToImage(), string.Empty, () => ViewModel.GoToReleasesCommand.ExecuteIfCan());
            _splitElements[2].Button2 = new SplitViewElement.SplitButton(Octicon.GitBranch.ToImage(), string.Empty, () => ViewModel.GoToBranchesCommand.ExecuteIfCan());

            var stargazers = _split.AddButton("Stargazers", "-", () => ViewModel.GoToStargazersCommand.ExecuteIfCan());
            var watchers   = _split.AddButton("Watchers", "-", () => ViewModel.GoToWatchersCommand.ExecuteIfCan());
            var forks      = _split.AddButton("Forks", "-", () => ViewModel.GoToForksCommand.ExecuteIfCan());

            this.WhenAnyValue(x => x.ViewModel.Stargazers)
            .Select(x => x != null ? x.ToString() : "-")
            .Subscribe(x => stargazers.Text = x);

            this.WhenAnyValue(x => x.ViewModel.Watchers)
            .Select(x => x != null ? x.ToString() : "-")
            .Subscribe(x => watchers.Text = x);

            this.WhenAnyValue(x => x.ViewModel.Repository.ForksCount)
            .Subscribe(x => forks.Text = x.ToString());

            this.WhenAnyValue(x => x.ViewModel.Repository)
            .IsNotNull()
            .Subscribe(x =>
            {
                _splitElements[0].Button1.Text = x.Private ? "Private" : "Public";
                _splitElements[0].Button2.Text = x.Language ?? "N/A";
                _splitElements[1].Button1.Text = x.OpenIssuesCount + (x.OpenIssuesCount == 1 ? " Issue" : " Issues");
            });

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

            this.WhenAnyValue(x => x.ViewModel.RepositoryName)
            .Subscribe(x => HeaderView.Text = x);

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

            this.WhenAnyValue(x => x.ViewModel.Branches)
            .Select(x => x == null ? "- Branches" : (x.Count >= 100 ? "100+" : x.Count.ToString()) + (x.Count == 1 ? " Branch" : " Branches"))
            .SubscribeSafe(x => _splitElements[2].Button2.Text = x);

            this.WhenAnyValue(x => x.ViewModel.Contributors)
            .Select(x => x == null ? "- Contributors" : (x >= 100 ? "100+" : x.ToString()) + (x == 1 ? " Contributor" : " Contributors"))
            .SubscribeSafe(x => _splitElements[1].Button2.Text = x);

            this.WhenAnyValue(x => x.ViewModel.Releases)
            .Select(x => x == null ? "- Releases" : (x >= 100 ? "100+" : x.ToString()) + (x == 1 ? " Release" : " Releases"))
            .SubscribeSafe(x => _splitElements[2].Button1.Text = x);

            this.WhenAnyValue(x => x.ViewModel.Description)
            .Subscribe(x => {
                HeaderView.SubText = x;
                RefreshHeaderView();
            });

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

            this.WhenAnyValue(x => x.ViewModel.Repository)
            .IsNotNull()
            .Subscribe(_ => Render());

            this.WhenAnyValue(x => x.ViewModel.Readme)
            .Where(x => x != null && ViewModel.Repository != null)
            .Subscribe(_ => Render());
        }
Exemplo n.º 23
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());
        }
Exemplo n.º 24
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _splitButton1 = _split.AddButton("Comments", "-");
            _splitButton2 = _split.AddButton("Participants", "-");

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

            Appeared.Take(1)
            .Select(_ => Observable.Timer(TimeSpan.FromSeconds(0.2f)))
            .Switch()
            .ObserveOn(RxApp.MainThreadScheduler)
            .Select(_ => ViewModel.Bind(x => x.IsClosed, true).Where(x => x.HasValue).Select(x => x.Value))
            .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", "No Milestone", UITableViewCellStyle.Value1)
            {
                Image = Octicon.Milestone.ToImage()
            };
            _assigneeElement = new StringElement("Assigned", "Unassigned", UITableViewCellStyle.Value1)
            {
                Image = Octicon.Person.ToImage()
            };
            _labelsElement = new StringElement("Labels", "None", UITableViewCellStyle.Value1)
            {
                Image = Octicon.Tag.ToImage()
            };
            _addCommentElement = new StringElement("Add Comment")
            {
                Image = Octicon.Pencil.ToImage()
            };

            var actionButton = new UIBarButtonItem(UIBarButtonSystemItem.Action)
            {
                Enabled = false
            };

            NavigationItem.RightBarButtonItem = actionButton;

            ViewModel.Bind(x => x.IsModifying).SubscribeStatus("Loading...");

            ViewModel.Bind(x => x.Issue).Subscribe(x =>
            {
                _assigneeElement.Value  = x.Assignee != null ? x.Assignee.Login : "******";
                _milestoneElement.Value = x.Milestone != null ? x.Milestone.Title : "No Milestone";
                _labelsElement.Value    = x.Labels.Count == 0 ? "None" : string.Join(", ", x.Labels.Select(i => i.Name));

                var model    = new MarkdownModel(ViewModel.MarkdownDescription, (int)UIFont.PreferredSubheadline.PointSize, true);
                var markdown = new MarkdownWebView {
                    Model = model
                };
                var html = markdown.GenerateString();
                _descriptionElement.SetValue(string.IsNullOrEmpty(ViewModel.MarkdownDescription) ? null : html);

                HeaderView.Text    = x.Title;
                HeaderView.SubText = "Updated " + x.UpdatedAt.Humanize();
                HeaderView.SetImage(x.User?.AvatarUrl, Images.Avatar);
                RefreshHeaderView();

                Render();
            });

            ViewModel.BindCollection(x => x.Comments).Subscribe(_ => RenderComments());
            ViewModel.BindCollection(x => x.Events).Subscribe(_ => RenderComments());
            ViewModel.Bind(x => x.ShouldShowPro).Subscribe(x => {
                if (x)
                {
                    this.ShowPrivateView();
                }
            });

            OnActivation(d =>
            {
                d(_milestoneElement.Clicked.BindCommand(ViewModel.GoToMilestoneCommand));
                d(_assigneeElement.Clicked.BindCommand(ViewModel.GoToAssigneeCommand));
                d(_labelsElement.Clicked.BindCommand(ViewModel.GoToLabelsCommand));
                d(_addCommentElement.Clicked.Subscribe(_ => AddCommentTapped()));
                d(_descriptionElement.UrlRequested.BindCommand(ViewModel.GoToUrlCommand));
                d(_commentsElement.UrlRequested.BindCommand(ViewModel.GoToUrlCommand));
                d(actionButton.GetClickedObservable().Subscribe(ShowExtraMenu));
                d(HeaderView.Clicked.BindCommand(ViewModel.GoToOwner));

                d(ViewModel.Bind(x => x.IsCollaborator, true).Subscribe(x => {
                    foreach (var i in new [] { _assigneeElement, _milestoneElement, _labelsElement })
                    {
                        i.Accessory = x ? UITableViewCellAccessory.DisclosureIndicator : UITableViewCellAccessory.None;
                    }
                }));

                d(ViewModel.Bind(x => x.IsLoading).Subscribe(x => actionButton.Enabled = !x));
            });
        }
Exemplo n.º 25
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.Image = Images.LoginUserUnknown;

            var split         = new SplitButtonElement();
            var headerSection = new Section {
                split
            };
            var descriptionElement = new MultilinedElement();
            var detailsSection     = new Section();
            var footerButton       = new TableFooterButton("Add Comment");
            var commentsSection    = new Section(null, footerButton);

            var diffButton       = new StringElement(Octicon.DiffAdded.ToImage());
            var removedButton    = new StringElement(Octicon.DiffRemoved.ToImage());
            var modifiedButton   = new StringElement(Octicon.DiffModified.ToImage());
            var allChangesButton = new StringElement("All Changes", Octicon.Diff.ToImage());

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

            var additions       = split.AddButton("Additions");
            var deletions       = split.AddButton("Deletions");
            var parents         = split.AddButton("Parents");
            var commentsElement = new HtmlElement("comments");

            ViewModel.Comments.Changed
            .Select(_ => new Unit())
            .StartWith(new Unit())
            .Subscribe(x =>
            {
                var comments     = ViewModel.Comments.Select(c => new Comment(c.Avatar.ToUri(), c.Actor, c.Body, c.UtcCreatedAt.Humanize())).ToList();
                var commentModel = new CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize);
                var razorView    = new CommentsView {
                    Model = commentModel
                };
                var html = razorView.GenerateString();
                commentsElement.Value = html;

                if (commentsElement.GetRootElement() == null && ViewModel.Comments.Count > 0)
                {
                    commentsSection.Add(commentsElement);
                }
                TableView.ReloadData();
            });

            this.WhenAnyValue(x => x.ViewModel.Commit)
            .IsNotNull()
            .Take(1)
            .Subscribe(_ => Root.Reset(headerSection, detailsSection, commentsSection));

            Appeared
            .Take(1)
            .Select(_ => this.WhenAnyValue(x => x.ViewModel.CommitMessage, y => y.ViewModel.CommiterName))
            .Switch()
            .Where(x => x.Item1 != null && x.Item2 != null)
            .Take(1)
            .Subscribe(_ => detailsSection.Insert(0, UITableViewRowAnimation.Automatic, descriptionElement));

            OnActivation(d => {
                d(allChangesButton.BindCommand(ViewModel.GoToAllFiles));
                d(footerButton.Clicked.InvokeCommand(ViewModel.AddCommentCommand));

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

                d(this.WhenAnyValue(x => x.ViewModel.CommitMessage)
                  .Subscribe(x => descriptionElement.Details = x ?? string.Empty));

                d(descriptionElement.BindCaption(this.WhenAnyValue(x => x.ViewModel.CommiterName)));

                d(diffButton.BindCommand(ViewModel.GoToAddedFiles));
                d(diffButton.BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffAdditions).Select(x => x > 0)));
                d(diffButton.BindCaption(this.WhenAnyValue(x => x.ViewModel.DiffAdditions).StartWith(0).Select(x => string.Format("{0} added", x))));

                d(removedButton.BindCommand(ViewModel.GoToRemovedFiles));
                d(removedButton.BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffDeletions).Select(x => x > 0)));
                d(removedButton.BindCaption(this.WhenAnyValue(x => x.ViewModel.DiffDeletions).StartWith(0).Select(x => string.Format("{0} removed", x))));

                d(modifiedButton.BindCommand(ViewModel.GoToModifiedFiles));
                d(modifiedButton.BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffModifications).Select(x => x > 0)));
                d(modifiedButton.BindCaption(this.WhenAnyValue(x => x.ViewModel.DiffModifications).StartWith(0).Select(x => string.Format("{0} modified", x))));

                d(allChangesButton.BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffAdditions, x => x.ViewModel.DiffDeletions, x => x.ViewModel.DiffModifications)
                                                  .Select(x => x.Item1 + x.Item2 + x.Item3 > 0)));

                d(commentsElement.UrlRequested.InvokeCommand(ViewModel.GoToUrlCommand));

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

                d(this.WhenAnyValue(x => x.ViewModel.CommitMessageSummary).Subscribe(x => RefreshHeaderView(x)));

                d(this.WhenAnyValue(x => x.ViewModel.Commit).IsNotNull()
                  .Select(x => "Commited " + x.Commit.Committer.Date.LocalDateTime.Humanize())
                  .Subscribe(x => RefreshHeaderView(subtext: x)));

                var statsObs = this.WhenAnyValue(x => x.ViewModel.Commit.Stats);
                d(additions.BindText(statsObs.Select(x => x != null ? x.Additions.ToString() : "-")));
                d(deletions.BindText(statsObs.Select(x => x != null ? x.Deletions.ToString() : "-")));

                d(this.WhenAnyValue(x => x.ViewModel.Commit.Parents)
                  .Subscribe(x => parents.Text = x != null ? x.Count.ToString() : "-"));
            });
        }
Exemplo n.º 26
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Gist";

            var editButton = NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action);

            HeaderView.SetImage(null, Images.Avatar);
            HeaderView.Text = "Gist #" + ViewModel.Id;
            HeaderView.SubImageView.TintColor = UIColor.FromRGB(243, 156, 18);

            Appeared.Take(1)
            .Select(_ => Observable.Timer(TimeSpan.FromSeconds(0.35f)).Take(1))
            .Switch()
            .Select(_ => ViewModel.Bind(x => x.IsStarred, true))
            .Switch()
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x => HeaderView.SetSubImage(x ? Octicon.Star.ToImage() : null));

            TableView.RowHeight          = UITableView.AutomaticDimension;
            TableView.EstimatedRowHeight = 44f;

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

            _splitRow1    = new SplitViewElement(Octicon.Lock.ToImage(), Octicon.Package.ToImage());
            _splitRow2    = new SplitViewElement(Octicon.Calendar.ToImage(), Octicon.Star.ToImage());
            _ownerElement = new StringElement("Owner", string.Empty, UITableViewCellStyle.Value1)
            {
                Image     = Octicon.Person.ToImage(),
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };

            OnActivation(d =>
            {
                d(editButton.GetClickedObservable().Subscribe(_ => ShareButtonTap(editButton)));
                d(_ownerElement.Clicked.BindCommand(ViewModel.GoToUserCommand));

                d(ViewModel.Bind(x => x.IsStarred, true).Subscribe(isStarred => _splitRow2.Button2.Text = isStarred ? "Starred" : "Not Starred"));

                d(ViewModel.BindCollection(x => x.Comments, true).Subscribe(_ => RenderGist()));
                d(HeaderView.Clicked.BindCommand(ViewModel.GoToUserCommand));

                d(ViewModel.Bind(x => x.Gist, true).Where(x => x != null).Subscribe(gist =>
                {
                    var daysOld = gist.CreatedAt.TotalDaysAgo();

                    _splitRow1.Button1.Text = gist.Public ? "Public" : "Private";
                    _splitRow1.Button2.Text = (gist.History?.Count ?? 0) + " Revisions";
                    _splitRow2.Button1.Text = daysOld == 0 ? "Created today" : "day".ToQuantity(daysOld) + " old";
                    _ownerElement.Value     = gist.Owner?.Login ?? "Unknown";
                    files.Text         = gist.Files?.Count.ToString() ?? "-";
                    comments.Text      = gist.Comments.ToString();
                    forks.Text         = gist.Forks?.Count.ToString() ?? "-";
                    HeaderView.SubText = gist.Description;
                    HeaderView.Text    = gist.Files?.Select(x => x.Key).FirstOrDefault() ?? HeaderView.Text;
                    HeaderView.SetImage(gist.Owner?.AvatarUrl, Images.Avatar);
                    RenderGist();
                    RefreshHeaderView();
                }));
            });
        }
Exemplo n.º 27
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.Image = Images.LoginUserUnknown;

            var split         = new SplitButtonElement();
            var headerSection = new Section {
                split
            };
            var descriptionElement = new MultilinedElement();
            var detailsSection     = new Section();
            var commentsSection    = new Section(null, new TableFooterButton("Add Comment", () => ViewModel.AddCommentCommand.ExecuteIfCan()));

            var additions = split.AddButton("Additions");
            var deletions = split.AddButton("Deletions");
            var parents   = split.AddButton("Parents");

            var gotoRepositoryElement = new StringElement(string.Empty)
            {
                Font      = StringElement.DefaultDetailFont,
                TextColor = StringElement.DefaultDetailColor,
                Image     = Octicon.Repo.ToImage()
            };

            gotoRepositoryElement.Tapped += () => ViewModel.GoToRepositoryCommand.ExecuteIfCan();

            detailsSection.Add(
                new StringElement(Octicon.DiffAdded.ToImage())
                .BindCommand(() => ViewModel.GoToAddedFiles)
                .BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffAdditions).Select(x => x > 0))
                .BindCaption(this.WhenAnyValue(x => x.ViewModel.DiffAdditions).StartWith(0).Select(x => string.Format("{0} added", x))));

            detailsSection.Add(
                new StringElement(Octicon.DiffRemoved.ToImage())
                .BindCommand(() => ViewModel.GoToRemovedFiles)
                .BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffDeletions).Select(x => x > 0))
                .BindCaption(this.WhenAnyValue(x => x.ViewModel.DiffDeletions).StartWith(0).Select(x => string.Format("{0} removed", x))));

            detailsSection.Add(
                new StringElement(Octicon.DiffModified.ToImage())
                .BindCommand(() => ViewModel.GoToModifiedFiles)
                .BindDisclosure(this.WhenAnyValue(x => x.ViewModel.DiffModifications).Select(x => x > 0))
                .BindCaption(this.WhenAnyValue(x => x.ViewModel.DiffModifications).StartWith(0).Select(x => string.Format("{0} modified", x))));

            detailsSection.Add(new StringElement("All Changes", () => ViewModel.GoToAllFiles.ExecuteIfCan(), Octicon.Diff.ToImage()));

            var commentsElement = new HtmlElement("comments");

            commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan;

            ViewModel.Comments.Changed
            .Select(_ => new Unit())
            .StartWith(new Unit())
            .Subscribe(x =>
            {
                var comments     = ViewModel.Comments.Select(c => new Comment(c.Avatar.ToUri(), c.Actor, c.Body, c.UtcCreatedAt.Humanize())).ToList();
                var commentModel = new CodeHub.WebViews.CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize);
                var razorView    = new CommentsView {
                    Model = commentModel
                };
                var html = razorView.GenerateString();
                commentsElement.Value = html;

                if (commentsElement.GetRootElement() == null && ViewModel.Comments.Count > 0)
                {
                    commentsSection.Add(commentsElement);
                }
                TableView.ReloadData();
            });

            this.WhenAnyValue(x => x.ViewModel.Commit)
            .IsNotNull()
            .Take(1)
            .Subscribe(_ => Root.Reset(headerSection, detailsSection, commentsSection));

            Appeared
            .Take(1)
            .Select(_ => this.WhenAnyValue(x => x.ViewModel.CommitMessage, y => y.ViewModel.CommiterName))
            .Switch()
            .Where(x => x.Item1 != null && x.Item2 != null)
            .Take(1)
            .Subscribe(_ => detailsSection.Insert(0, UITableViewRowAnimation.Automatic, descriptionElement));

            this.WhenAnyValue(x => x.ViewModel.CommiterName)
            .Subscribe(x => descriptionElement.Caption = x ?? string.Empty);

            this.WhenAnyValue(x => x.ViewModel.CommitMessage)
            .Subscribe(x => descriptionElement.Details = x ?? string.Empty);


            this.WhenAnyValue(x => x.ViewModel.RepositoryName)
            .Subscribe(x => gotoRepositoryElement.Caption = x);

            this.WhenAnyValue(x => x.ViewModel.ShowRepository)
            .StartWith(false)
            .Where(x => x)
            .Take(1)
            .Subscribe(x => detailsSection.Add(gotoRepositoryElement));

            this.WhenAnyValue(x => x.ViewModel.Commit)
            .SubscribeSafe(x =>
            {
                additions.Text = x != null ? x.Stats.Additions.ToString() : "-";
                deletions.Text = x != null ? x.Stats.Deletions.ToString() : "-";
                parents.Text   = x != null ? x.Parents.Count.ToString() : "-";
            });

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

            this.WhenAnyValue(x => x.ViewModel.CommitMessageSummary)
            .Subscribe(x => {
                HeaderView.Text = x;
                RefreshHeaderView();
            });

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

            this.WhenAnyValue(x => x.ViewModel.Commit)
            .IsNotNull()
            .Subscribe(x => {
                HeaderView.SubText = "Commited " + x.Commit.Committer.Date.LocalDateTime.Humanize();
                RefreshHeaderView();
            });
        }
Exemplo n.º 28
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.Image   = Images.LoginUserUnknown;
            HeaderView.SubText = "Settings apply to this account only.";

            var showOrganizationsInEvents = new BooleanElement("Show Organizations in Events", ViewModel.ShowOrganizationsInEvents);
            var showOrganizations         = new BooleanElement("List Organizations in Menu", ViewModel.ExpandOrganizations);
            var repoDescriptions          = new BooleanElement("Show Repo Descriptions", ViewModel.ShowRepositoryDescriptionInList);
            var startupView        = new ButtonElement("Startup View", ViewModel.DefaultStartupViewName);
            var syntaxHighlighter  = new ButtonElement("Syntax Highlighter", ViewModel.SyntaxHighlighter);
            var followElement      = new ButtonElement("Follow On Twitter");
            var rateElement        = new ButtonElement("Rate This App");
            var sourceElement      = new ButtonElement("Source Code");
            var applicationSection = new Section("Application", "Looking for application settings? They're located in the iOS settings application.");
            var version            = UIDevice.CurrentDevice.SystemVersion.Split('.');
            var major           = Int32.Parse(version[0]);
            var settingsElement = new ButtonElement("Go To Application Settings");

            if (major >= 8)
            {
                applicationSection.Add(settingsElement);
            }

            var appearanceSection = new Section("Appearance")
            {
                showOrganizationsInEvents,
                showOrganizations,
                repoDescriptions,
                startupView,
                syntaxHighlighter
            };

            var aboutSection = new Section("About", "Thank you for downloading. Enjoy!")
            {
                followElement,
                rateElement,
                sourceElement,
                new StringElement("App Version", GetApplicationVersion())
            };

            Root.Reset(appearanceSection, applicationSection, aboutSection);

            OnActivation(d => {
                d(this.WhenAnyValue(x => x.ViewModel.AccountImageUrl).SubscribeSafe(x => HeaderView.SetImage(new Uri(x), Images.LoginUserUnknown)));
                d(this.WhenAnyValue(x => x.ViewModel.ShowOrganizationsInEvents).Subscribe(x => showOrganizationsInEvents.Value = x));

                d(this.WhenAnyValue(x => x.ViewModel.DefaultStartupViewName).Subscribe(x => {
                    startupView.Value = x;
                    Root.Reload(startupView);
                }));

                d(this.WhenAnyValue(x => x.ViewModel.SyntaxHighlighter).Subscribe(x => {
                    syntaxHighlighter.Value = x;
                    Root.Reload(syntaxHighlighter);
                }));

                d(showOrganizationsInEvents.Changed.Subscribe(x => ViewModel.ShowOrganizationsInEvents = x));

                d(this.WhenAnyValue(x => x.ViewModel.ExpandOrganizations).Subscribe(x => showOrganizations.Value = x));
                d(showOrganizations.Changed.Subscribe(x => ViewModel.ExpandOrganizations = x));
                d(this.WhenAnyValue(x => x.ViewModel.ShowRepositoryDescriptionInList).Subscribe(x => repoDescriptions.Value = x));
                d(repoDescriptions.Changed.Subscribe(x => ViewModel.ShowRepositoryDescriptionInList = x));

                d(followElement.Clicked.Subscribe(_ => UIApplication.SharedApplication.OpenUrl(new NSUrl("https://twitter.com/CodeHubapp"))));
                d(rateElement.Clicked.Subscribe(_ => UIApplication.SharedApplication.OpenUrl(new NSUrl("https://itunes.apple.com/us/app/codehub-github-for-ios/id707173885?mt=8"))));
                d(sourceElement.Clicked.InvokeCommand(ViewModel.GoToSourceCodeCommand));

                d(startupView.Clicked.InvokeCommand(ViewModel.GoToDefaultStartupViewCommand));
                d(syntaxHighlighter.Clicked.InvokeCommand(ViewModel.GoToSyntaxHighlighterCommand));
                d(settingsElement.Clicked.Subscribe(_ => UIApplication.SharedApplication.OpenUrl(new NSUrl(UIApplication.OpenSettingsUrlString))));
            });
        }
Exemplo n.º 29
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

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

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

            var events = new StringElement("Events", Octicon.Rss.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var issuesElement = new StringElement("Issues", Octicon.IssueOpened.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var commitsElement = new StringElement("Commits", Octicon.GitCommit.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var pullRequestsElement = new StringElement("Pull Requests", Octicon.GitPullRequest.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var sourceElement = new StringElement("Source", Octicon.Code.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var websiteElement = new StringElement("Website", Octicon.Globe.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var readmeElement = new StringElement("Readme", Octicon.Book.ToImage())
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };
            var forkedElement = new StringElement("Fork", string.Empty)
            {
                Image     = Octicon.RepoForked.ToImage(),
                Font      = StringElement.DefaultDetailFont,
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };

            _splitElements[0] = new SplitViewElement(Octicon.Lock.ToImage(), Octicon.Package.ToImage());
            _splitElements[1] = new SplitViewElement(Octicon.IssueOpened.ToImage(), Octicon.Organization.ToImage());
            _splitElements[2] = new SplitViewElement(Octicon.Tag.ToImage(), Octicon.GitBranch.ToImage());

            var stargazers = _split.AddButton("Stargazers", "-");
            var watchers   = _split.AddButton("Watchers", "-");
            var forks      = _split.AddButton("Forks", "-");

            var renderFunc = new Action(() => {
                var model = ViewModel.Repository;
                var sec1  = new Section();
                sec1.Add(_splitElements);

                if (model.Parent != null)
                {
                    forkedElement.Value = model.Parent.FullName;
                    sec1.Add(forkedElement);
                }

                var sec2 = new Section {
                    events
                };

                if (model.HasIssues)
                {
                    sec2.Add(issuesElement);
                }

                if (ViewModel.Readme != null)
                {
                    sec2.Add(readmeElement);
                }

                Root.Reset(new Section {
                    _split
                }, sec1, sec2, new Section {
                    commitsElement, pullRequestsElement, sourceElement
                });

                if (!string.IsNullOrEmpty(model.Homepage))
                {
                    Root.Add(new Section {
                        websiteElement
                    });
                }
            });

            OnActivation(d => {
                d(HeaderView.Clicked.InvokeCommand(ViewModel.GoToOwnerCommand));

                d(_splitElements[1].Button1.Clicked.InvokeCommand(ViewModel.GoToIssuesCommand));
                d(_splitElements[1].Button2.Clicked.InvokeCommand(ViewModel.GoToContributors));
                d(_splitElements[2].Button1.Clicked.InvokeCommand(ViewModel.GoToReleasesCommand));
                d(_splitElements[2].Button2.Clicked.InvokeCommand(ViewModel.GoToBranchesCommand));

                d(events.Clicked.InvokeCommand(ViewModel.GoToEventsCommand));
                d(issuesElement.Clicked.InvokeCommand(ViewModel.GoToIssuesCommand));
                d(websiteElement.Clicked.InvokeCommand(ViewModel.GoToHomepageCommand));
                d(forkedElement.Clicked.InvokeCommand(ViewModel.GoToForkParentCommand));
                d(readmeElement.Clicked.InvokeCommand(ViewModel.GoToReadmeCommand));

                d(stargazers.Clicked.InvokeCommand(ViewModel.GoToStargazersCommand));
                d(watchers.Clicked.InvokeCommand(ViewModel.GoToWatchersCommand));
                d(forks.Clicked.InvokeCommand(ViewModel.GoToForksCommand));

                d(commitsElement.Clicked.InvokeCommand(ViewModel.GoToCommitsCommand));
                d(pullRequestsElement.Clicked.InvokeCommand(ViewModel.GoToPullRequestsCommand));
                d(sourceElement.Clicked.InvokeCommand(ViewModel.GoToSourceCommand));

                d(this.WhenAnyValue(x => x.ViewModel.Stargazers)
                  .Select(x => x != null ? x.ToString() : "-")
                  .Subscribe(x => stargazers.Text = x));

                d(this.WhenAnyValue(x => x.ViewModel.Watchers)
                  .Select(x => x != null ? x.ToString() : "-")
                  .Subscribe(x => watchers.Text = x));

                d(this.WhenAnyValue(x => x.ViewModel.Repository.ForksCount)
                  .Subscribe(x => forks.Text = x.ToString()));

                d(this.WhenAnyValue(x => x.ViewModel.Repository)
                  .IsNotNull()
                  .Subscribe(x =>
                {
                    _splitElements[0].Button1.Text = x.Private ? "Private" : "Public";
                    _splitElements[0].Button2.Text = x.Language ?? "N/A";
                    _splitElements[1].Button1.Text = x.OpenIssuesCount + (x.OpenIssuesCount == 1 ? " Issue" : " Issues");
                }));

                d(this.WhenAnyValue(x => x.ViewModel.RepositoryName)
                  .Subscribe(x => HeaderView.Text = x));

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

                d(this.WhenAnyValue(x => x.ViewModel.Branches)
                  .Select(x => x == null ? "Branches" : (x.Count >= 100 ? "100+" : x.Count.ToString()) + (x.Count == 1 ? " Branch" : " Branches"))
                  .SubscribeSafe(x => _splitElements[2].Button2.Text = x));

                d(this.WhenAnyValue(x => x.ViewModel.Contributors)
                  .Select(x => x == null ? "Contributors" : (x >= 100 ? "100+" : x.ToString()) + (x == 1 ? " Contributor" : " Contributors"))
                  .SubscribeSafe(x => _splitElements[1].Button2.Text = x));

                d(this.WhenAnyValue(x => x.ViewModel.Releases)
                  .Select(x => x == null ? "Releases" : (x >= 100 ? "100+" : x.ToString()) + (x == 1 ? " Release" : " Releases"))
                  .SubscribeSafe(x => _splitElements[2].Button1.Text = x));

                d(this.WhenAnyValue(x => x.ViewModel.Description).Subscribe(x => RefreshHeaderView(subtext: x)));

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

                d(this.WhenAnyValue(x => x.ViewModel.Repository)
                  .IsNotNull()
                  .Subscribe(_ => renderFunc()));

                d(this.WhenAnyValue(x => x.ViewModel.Readme)
                  .Where(x => x != null && ViewModel.Repository != null)
                  .Subscribe(_ => renderFunc()));
            });
        }
Exemplo n.º 30
0
        public void RenderIssue()
        {
            if (ViewModel.Issue == null)
            {
                return;
            }

            var avatar = new Avatar(ViewModel.Issue.ReportedBy?.Avatar);

            NavigationItem.RightBarButtonItem.Enabled = true;
            HeaderView.Text = ViewModel.Issue.Title;
            HeaderView.SetImage(avatar.ToUrl(), Images.Avatar);
            HeaderView.SubText = ViewModel.Issue.Content ?? "Updated " + ViewModel.Issue.UtcLastUpdated.Humanize();
            RefreshHeaderView();

            var split = new SplitButtonElement();

            split.AddButton("Comments", ViewModel.Comments.Items.Count.ToString());
            split.AddButton("Watches", ViewModel.Issue.FollowerCount.ToString());

            var root = new RootElement(Title);

            root.Add(new Section {
                split
            });

            var secDetails = new Section();

            if (!string.IsNullOrEmpty(ViewModel.Issue.Content))
            {
                _descriptionElement.LoadContent(new MarkdownRazorView {
                    Model = ViewModel.Issue.Content
                }.GenerateString());
                secDetails.Add(_descriptionElement);
            }

            _split1.Button1.Text = ViewModel.Issue.Status;
            _split1.Button2.Text = ViewModel.Issue.Priority;
            secDetails.Add(_split1);

            _split2.Button1.Text = ViewModel.Issue.Metadata.Kind;
            _split2.Button2.Text = ViewModel.Issue.Metadata.Component ?? "No Component";
            secDetails.Add(_split2);

            _split3.Button1.Text = ViewModel.Issue.Metadata.Version ?? "No Version";
            _split3.Button2.Text = ViewModel.Issue.Metadata.Milestone ?? "No Milestone";
            secDetails.Add(_split3);

            var assigneeElement = new StyledStringElement("Assigned", ViewModel.Issue.Responsible != null ? ViewModel.Issue.Responsible.Username : "******", UITableViewCellStyle.Value1)
            {
                Image     = AtlassianIcon.User.ToImage(),
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };

            assigneeElement.Tapped += () => ViewModel.GoToAssigneeCommand.Execute(null);
            secDetails.Add(assigneeElement);

            root.Add(secDetails);

            if (ViewModel.Comments.Any(x => !string.IsNullOrEmpty(x.Content)))
            {
                root.Add(new Section {
                    _commentsElement
                });
            }

            var addComment = new StyledStringElement("Add Comment")
            {
                Image = AtlassianIcon.Addcomment.ToImage()
            };

            addComment.Tapped += AddCommentTapped;
            root.Add(new Section {
                addComment
            });
            Root = root;
        }