public override void ViewDidLoad() { base.ViewDidLoad(); NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, (s, e) => ShowMore()); NavigationItem.RightBarButtonItem.EnableIfExecutable(this.WhenAnyValue(x => x.ViewModel) .Where(x => x != null) .Select(x => x.WhenAnyValue(y => y.Repository)) .Switch().Select(x => x != null)); HeaderView.Text = string.Empty; HeaderView.TextColor = UIColor.White; HeaderView.SubTextColor = UIColor.FromWhiteAlpha(0.9f, 1.0f); var section = new Section { HeaderView = HeaderView }; var section2 = new Section(); var split = new SplitButtonElement(); var stars = split.AddButton("Stargazers", "-"); var forks = split.AddButton("Forks", "-"); var collaborators = split.AddButton("Contributors", "-"); section.Add(split); this.WhenAnyValue(x => x.ViewModel) .Where(x => x != null) .Select(x => x.WhenAnyValue(y => y.RepositoryIdentifier).Where(y => y != null)) .Switch() .Subscribe(x => { Title = HeaderView.Text = x.Name; ReloadData(); }); this.WhenAnyValue(x => x.ViewModel) .Where(x => x != null) .Select(x => x.WhenAnyValue(y => y.ContributorCount)) .Switch() .Subscribe(x => collaborators.Text = x.HasValue ? x.Value.ToString() : "-"); this.WhenAnyValue(x => x.ViewModel) .Where(x => x != null) .Select(x => x.WhenAnyValue(y => y.Repository)) .Switch() .Subscribe(x => { if (x == null) { HeaderView.ImageUri = null; HeaderView.Text = null; HeaderView.SubText = null; stars.Text = "-"; forks.Text = "-"; } else { HeaderView.ImageUri = x.Owner.AvatarUrl; HeaderView.Text = x.Name; HeaderView.SubText = x.Description; stars.Text = x.WatchersCount.ToString(); forks.Text = x.ForksCount.ToString(); } ReloadData(); }); this.WhenAnyValue(x => x.ViewModel) .Where(x => x != null) .Select(x => x.WhenAnyValue(y => y.Liked)) .Switch() .Subscribe(x => { if (x == null) { DislikeButton.Image = Images.ThumbDown; LikeButton.Image = Images.ThumbUp; } else if (x.Value) { DislikeButton.Image = Images.ThumbDown; LikeButton.Image = Images.ThumbUpFilled; } else { DislikeButton.Image = Images.ThumbDownFilled; LikeButton.Image = Images.ThumbUp; } }); _webElement = new WebElement("readme"); _webElement.UrlRequested += (obj) => ViewModel.GoToUrlCommand.ExecuteIfCan(obj); ViewModel.WhenAnyValue(y => y.Readme).Where(_ => !_disposed).Subscribe(x => { if (x == null) { _webElement.ContentPath = null; section2.HeaderView = new LoadingView(); if (_webElement.GetRootElement() != null) { section2.Remove(_webElement); } } else { var view = new ReadmeRazorView { Model = x }; var file = System.IO.Path.GetTempFileName() + ".html"; using (var stream = new System.IO.StreamWriter(file, false, System.Text.Encoding.UTF8)) { view.Generate(stream); _webElement.ContentPath = file; } section2.HeaderView = null; if (_webElement.GetRootElement() == null) { section2.Add(_webElement); } } ReloadData(); }); ViewModel.DismissCommand.Subscribe(_ => { _disposed = true; _webElement.Dispose(); }); Root.Reset(section, section2); ToolbarItems = new [] { new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace), DislikeButton, new UIBarButtonItem(UIBarButtonSystemItem.FixedSpace) { Width = 80 }, LikeButton, new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace), }; }