private void Render() { var section = new Section(); section.AddAll(_items.Select(item => { var el = new MultilinedElement(item.Name + " (" + item.Price + ")", item.Description); if (_features.IsActivated(item.Id)) { el.Accessory = MonoTouch.UIKit.UITableViewCellAccessory.Checkmark; } else { el.Accessory = MonoTouch.UIKit.UITableViewCellAccessory.DisclosureIndicator; el.Tapped += () => Tapped(item); } return(el); })); var root = new RootElement(Title) { UnevenRows = true }; root.Add(section); Root = root; }
public override void ViewDidLoad() { base.ViewDidLoad(); var source = new DialogTableViewSource(TableView); TableView.Source = source; NavigationItem.RightBarButtonItem = new UIBarButtonItem(Images.SaveButton, UIBarButtonItemStyle.Plain, (s, e) => { View.EndEditing(true); ViewModel.SaveCommand.ExecuteIfCan(); }); NavigationItem.RightBarButtonItem.EnableIfExecutable(ViewModel.SaveCommand.CanExecuteObservable); var title = new InputElement("Title", string.Empty, string.Empty); title.Changed += (sender, e) => ViewModel.Subject = title.Value; var content = new MultilinedElement("Description"); content.Tapped += () => ViewModel.GoToDescriptionCommand.ExecuteIfCan(); ViewModel.WhenAnyValue(x => x.Issue.Title).Subscribe(x => title.Value = x); ViewModel.WhenAnyValue(x => x.Content).Subscribe(x => content.Value = x); source.Root.Reset(new Section { title }, new Section { content }); }
protected void UpdateView() { var root = new RootElement(Title) { UnevenRows = true }; var section = new Section(); root.Add(section); var desc = new MultilinedElement("Description") { Value = _model.Description }; desc.Tapped += ChangeDescription; section.Add(desc); if (_public == null) _public = new TrueFalseElement("Public"); _public.Value = _model.Public; if (_publicEditable) section.Add(_public); var fileSection = new Section(); root.Add(fileSection); foreach (var file in _model.Files.Keys) { var key = file; if (!_model.Files.ContainsKey(key) || _model.Files[file].Content == null) continue; var size = System.Text.ASCIIEncoding.UTF8.GetByteCount(_model.Files[file].Content); var el = new StyledElement(file, size + " bytes", UITableViewCellStyle.Subtitle) { Accessory = UITableViewCellAccessory.DisclosureIndicator }; el.Tapped += () => { if (!_model.Files.ContainsKey(key)) return; var createController = new ModifyGistFileController(key, _model.Files[key].Content); createController.Save = (name, content) => { if (string.IsNullOrEmpty(name)) throw new InvalidOperationException("Please enter a name for the file"); //If different name & exists somewhere else if (!name.Equals(key) && _model.Files.ContainsKey(name)) throw new InvalidOperationException("A filename by that type already exists"); //Remove old _model.Files.Remove(key); //Put new _model.Files[name] = new GistCreateModel.File { Content = content }; }; NavigationController.PushViewController(createController, true); }; fileSection.Add(el); } fileSection.Add(new StyledElement("Add New File", AddFile)); Root = root; }
public GistCreateView() { HeaderView.Image = Images.LoginUserUnknown; this.WhenAnyValue(x => x.ViewModel.SaveCommand) .Select(x => x.ToBarButtonItem(UIBarButtonSystemItem.Save)) .Subscribe(x => NavigationItem.RightBarButtonItem = x); this.WhenAnyValue(x => x.ViewModel.CurrentAccount).Subscribe(x => { HeaderView.SubText = x.Username; HeaderView.ImageUri = x.AvatarUrl; }); _publicElement = new BooleanElement("Public", false, (e) => ViewModel.IsPublic = e.Value); this.WhenAnyValue(x => x.ViewModel.IsPublic).Subscribe(x => _publicElement.Value = x); _descriptionElement = new MultilinedElement("Description"); _descriptionElement.Tapped += ChangeDescription; this.WhenAnyValue(x => x.ViewModel.Description).Subscribe(x => _descriptionElement.Value = x); _fileSection = new Section(null, new TableFooterButton("Add File", () => ViewModel.AddGistFileCommand.ExecuteIfCan())); this.WhenAnyValue(x => x.ViewModel.Files).Subscribe(x => { if (x == null) { _fileSection.Clear(); return; } var elements = new List <Element>(); foreach (var file in x.Keys) { var key = file; if (string.IsNullOrEmpty(ViewModel.Files[file])) { continue; } var size = System.Text.Encoding.UTF8.GetByteCount(ViewModel.Files[file]); var el = new StyledStringElement(file, size + " bytes", UITableViewCellStyle.Subtitle) { Accessory = UITableViewCellAccessory.DisclosureIndicator, Image = Images.FileCode }; el.Tapped += () => ViewModel.ModifyGistFileCommand.ExecuteIfCan(key); elements.Add(el); } _fileSection.Reset(elements); }); }
// private void ForkRepository() // { // var repoModel = Controller.Model.RepositoryModel; // var alert = new UIAlertView(); // alert.Title = "Fork".t(); // alert.Message = "What would you like to name your fork?".t(); // alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput; // var forkButton = alert.AddButton("Fork!".t()); // var cancelButton = alert.AddButton("Cancel".t()); // alert.CancelButtonIndex = cancelButton; // alert.DismissWithClickedButtonIndex(cancelButton, true); // alert.GetTextField(0).Text = repoModel.Name; // alert.Clicked += (object sender2, UIButtonEventArgs e2) => { // if (e2.ButtonIndex == forkButton) // { // var text = alert.GetTextField(0).Text; // this.DoWork("Forking...".t(), () => { // //var fork = Application.Client.Users[model.Owner.Login].Repositories[model.Name].Fo(text); // BeginInvokeOnMainThread(() => { // // NavigationController.PushViewController(new RepositoryInfoViewController(fork), true); // }); // }, (ex) => { // //We typically get a 'BAD REQUEST' but that usually means that a repo with that name already exists // MonoTouch.Utilities.ShowAlert("Unable to fork".t(), "A repository by that name may already exist in your collection or an internal error has occured.".t()); // }); // } // }; // // alert.Show(); // } public void Render(RepositoryModel model) { Title = model.Name; var root = new RootElement(Title) { UnevenRows = true }; _header.Subtitle = "Updated ".t() + (model.UpdatedAt).ToDaysAgo(); _header.ImageUri = (model.Fork ? Images.GitHubRepoForkUrl : Images.GitHubRepoUrl).AbsoluteUri; root.Add(new Section(_header)); var sec1 = new Section(); if (!string.IsNullOrEmpty(model.Description) && !string.IsNullOrWhiteSpace(model.Description)) { var element = new MultilinedElement(model.Description) { BackgroundColor = UIColor.White, CaptionColor = Theme.CurrentTheme.MainTitleColor, ValueColor = Theme.CurrentTheme.MainTextColor }; element.CaptionColor = element.ValueColor; element.CaptionFont = element.ValueFont; sec1.Add(element); } sec1.Add(new SplitElement(new SplitElement.Row { Text1 = model.Private ? "Private".t() : "Public".t(), Image1 = model.Private ? Images.Locked : Images.Unlocked, Text2 = model.Language ?? "N/A", Image2 = Images.Language })); //Calculate the best representation of the size string size; if (model.Size / 1024f < 1) { size = string.Format("{0:0.##}KB", model.Size); } else if ((model.Size / 1024f / 1024f) < 1) { size = string.Format("{0:0.##}MB", model.Size / 1024f); } else { size = string.Format("{0:0.##}GB", model.Size / 1024f / 1024f); } sec1.Add(new SplitElement(new SplitElement.Row { Text1 = model.OpenIssues + (model.OpenIssues == 1 ? " Issue".t() : " Issues".t()), Image1 = Images.Flag, Text2 = model.Forks.ToString() + (model.Forks == 1 ? " Fork".t() : " Forks".t()), Image2 = Images.Fork })); sec1.Add(new SplitElement(new SplitElement.Row { Text1 = (model.CreatedAt).ToString("MM/dd/yy"), Image1 = Images.Create, Text2 = size, Image2 = Images.Size })); var owner = new StyledStringElement("Owner".t(), model.Owner.Login) { Image = Images.Person, Accessory = UITableViewCellAccessory.DisclosureIndicator }; owner.Tapped += () => ViewModel.GoToOwnerCommand.Execute(null); sec1.Add(owner); if (model.Parent != null) { var parent = new StyledStringElement("Forked From".t(), model.Parent.FullName) { Image = Images.Fork, Accessory = UITableViewCellAccessory.DisclosureIndicator }; parent.Tapped += () => ViewModel.GoToForkParentCommand.Execute(model.Parent); sec1.Add(parent); } var followers = new StyledStringElement("Stargazers".t(), "" + model.StargazersCount) { Image = Images.Star, Accessory = UITableViewCellAccessory.DisclosureIndicator }; followers.Tapped += () => ViewModel.GoToStargazersCommand.Execute(null); sec1.Add(followers); var events = new StyledStringElement("Events".t(), () => ViewModel.GoToEventsCommand.Execute(null), Images.Event); var sec2 = new Section { events }; if (model.HasIssues) { sec2.Add(new StyledStringElement("Issues".t(), () => ViewModel.GoToIssuesCommand.Execute(null), Images.Flag)); } if (ViewModel.Readme != null) { sec2.Add(new StyledStringElement("Readme".t(), () => ViewModel.GoToReadmeCommand.Execute(null), Images.File)); } var sec3 = new Section { new StyledStringElement("Commits".t(), () => ViewModel.GoToCommitsCommand.Execute(null), Images.Commit), new StyledStringElement("Pull Requests".t(), () => ViewModel.GoToPullRequestsCommand.Execute(null), Images.Hand), new StyledStringElement("Source".t(), () => ViewModel.GoToSourceCommand.Execute(null), Images.Script), }; root.Add(new[] { sec1, sec2, sec3 }); if (!string.IsNullOrEmpty(model.Homepage)) { var web = new StyledStringElement("Website".t(), () => ViewModel.GoToUrlCommand.Execute(model.Homepage), Images.Webpage); root.Add(new Section { web }); } Root = root; }
public void Render() { if (ViewModel.PullRequest == null) { return; } var root = new RootElement(Title); _header.Title = ViewModel.PullRequest.Title; _header.Subtitle = "Updated " + (ViewModel.PullRequest.UpdatedOn).ToDaysAgo(); _header.SetNeedsDisplay(); root.Add(new Section(_header)); var secDetails = new Section(); if (!string.IsNullOrEmpty(ViewModel.PullRequest.Description)) { var desc = new MultilinedElement(ViewModel.PullRequest.Description.Trim()) { BackgroundColor = UIColor.White, CaptionColor = Theme.CurrentTheme.MainTitleColor, ValueColor = Theme.CurrentTheme.MainTextColor }; desc.CaptionFont = desc.ValueFont; desc.CaptionColor = desc.ValueColor; secDetails.Add(desc); } var merged = ViewModel.Merged; _split1.Value.Text1 = ViewModel.PullRequest.CreatedOn.ToString("MM/dd/yy"); _split1.Value.Text2 = merged ? "Merged" : "Not Merged"; secDetails.Add(_split1); root.Add(secDetails); root.Add(new Section { new StyledStringElement("Commits", () => ViewModel.GoToCommitsCommand.Execute(null), Images.Commit), }); // if (!merged) // { // MonoTouch.Foundation.NSAction mergeAction = async () => // { // try // { // await this.DoWorkAsync("Merging...", ViewModel.Merge); // } // catch (Exception e) // { // MonoTouch.Utilities.ShowAlert("Unable to Merge", e.Message); // } // }; // // root.Add(new Section { new StyledStringElement("Merge".t(), mergeAction, Images.Fork) }); // } if (ViewModel.Comments.Items.Count > 0) { var commentsSec = new Section(); foreach (var x in ViewModel.Comments.Where(x => !string.IsNullOrEmpty(x.Content.Raw) && x.Inline == null).OrderBy(x => (x.CreatedOn))) { commentsSec.Add(new CommentElement { Name = x.User.Username, Time = x.CreatedOn.ToDaysAgo(), String = x.Content.Raw, Image = Theme.CurrentTheme.AnonymousUserImage, ImageUri = new Uri(x.User.Links.Avatar.Href), BackgroundColor = UIColor.White, }); } //Load more if there's more comments // if (model.MoreComments != null) // { // var loadMore = new PaginateElement("Load More".t(), "Loading...".t(), // e => this.DoWorkNoHud(() => model.MoreComments(), // x => Utilities.ShowAlert("Unable to load more!".t(), x.Message))) { AutoLoadOnVisible = false, Background = false }; // commentsSec.Add(loadMore); // } if (commentsSec.Elements.Count > 0) { root.Add(commentsSec); } } var addComment = new StyledStringElement("Add Comment") { Image = Images.Pencil }; addComment.Tapped += AddCommentTapped; root.Add(new Section { addComment }); Root = root; }
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(); }); }
public override void ViewDidLoad() { Title = "New Issue"; base.ViewDidLoad(); _hud = this.CreateHud(); var vm = (IssueAddViewModel)ViewModel; NavigationItem.RightBarButtonItem = new UIBarButtonItem(Theme.CurrentTheme.SaveButton, UIBarButtonItemStyle.Plain, (s, e) => { View.EndEditing(true); vm.SaveCommand.Execute(null); }); var title = new InputElement("Title", string.Empty, string.Empty); title.Changed += (object sender, EventArgs e) => vm.Title = title.Value; var assignedTo = new StyledStringElement("Responsible", "Unassigned", UITableViewCellStyle.Value1); assignedTo.Accessory = UITableViewCellAccessory.DisclosureIndicator; assignedTo.Tapped += () => vm.GoToAssigneeCommand.Execute(null); var milestone = new StyledStringElement("Milestone".t(), "None", UITableViewCellStyle.Value1); milestone.Accessory = UITableViewCellAccessory.DisclosureIndicator; milestone.Tapped += () => vm.GoToMilestonesCommand.Execute(null); var labels = new StyledStringElement("Labels".t(), "None", UITableViewCellStyle.Value1); labels.Accessory = UITableViewCellAccessory.DisclosureIndicator; labels.Tapped += () => vm.GoToLabelsCommand.Execute(null); var content = new MultilinedElement("Description"); content.Tapped += () => { var composer = new MarkdownComposerViewController { Title = "Issue Description", Text = content.Value }; composer.NewComment(this, (text) => { vm.Content = text; composer.CloseComposer(); }); }; vm.Bind(x => x.Title, x => title.Value = x); vm.Bind(x => x.Content, x => content.Value = x); vm.Bind(x => x.AssignedTo, x => { assignedTo.Value = x == null ? "Unassigned" : x.Login; Root.Reload(assignedTo, UITableViewRowAnimation.None); }); vm.Bind(x => x.Milestone, x => { milestone.Value = x == null ? "None" : x.Title; Root.Reload(milestone, UITableViewRowAnimation.None); }); vm.BindCollection(x => x.Labels, x => { labels.Value = vm.Labels.Items.Count == 0 ? "None" : string.Join(", ", vm.Labels.Items.Select(i => i.Name)); Root.Reload(labels, UITableViewRowAnimation.None); }); vm.Bind(x => x.IsSaving, x => { if (x) { _hud.Show("Saving..."); } else { _hud.Hide(); } }); Root = new RootElement(Title) { new Section { title, assignedTo, milestone, labels }, new Section { content } }; }
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() : "-")); }); }
public void Render() { if (ViewModel.PullRequest == null) { return; } var root = new RootElement(Title); _header.Title = ViewModel.PullRequest.Title; _header.Subtitle = "Updated " + (ViewModel.PullRequest.UpdatedAt).ToDaysAgo(); _header.SetNeedsDisplay(); root.Add(new Section(_header)); var secDetails = new Section(); if (!string.IsNullOrEmpty(ViewModel.PullRequest.Body)) { var desc = new MultilinedElement(ViewModel.PullRequest.Body.Trim()) { BackgroundColor = UIColor.White, CaptionColor = Theme.CurrentTheme.MainTitleColor, ValueColor = Theme.CurrentTheme.MainTextColor }; desc.CaptionFont = desc.ValueFont; desc.CaptionColor = desc.ValueColor; secDetails.Add(desc); } var merged = (ViewModel.PullRequest.Merged == null || !ViewModel.PullRequest.Merged.Value) ? false : true; _split1.Value.Text1 = ViewModel.PullRequest.State; _split1.Value.Text2 = merged ? "Merged" : "Not Merged"; secDetails.Add(_split1); root.Add(secDetails); root.Add(new Section { new StyledStringElement("Commits", () => NavigationController.PushViewController(new ChangesetsViewController(ViewModel.User, ViewModel.Repo, ViewModel.PullRequestId), true), Images.Commit), new StyledStringElement("Files", () => NavigationController.PushViewController(new PullRequestFilesViewController(ViewModel.User, ViewModel.Repo, ViewModel.PullRequestId), true), Images.File), }); if (!merged) { MonoTouch.Foundation.NSAction mergeAction = async() => { try { await this.DoWorkTest("Merging...", () => ViewModel.Merge()); } catch (Exception e) { MonoTouch.Utilities.ShowAlert("Unable to Merge", e.Message); } }; if (ViewModel.PullRequest.Mergable == null) { var el = new StyledStringElement("Merge".t(), mergeAction, Images.Fork); root.Add(new Section(null, "The mergable state is unknown and merging may not be successful.") { el }); } else if (ViewModel.PullRequest.Mergable.Value) { root.Add(new Section { new StyledStringElement("Merge".t(), mergeAction, Images.Fork) }); } else { root.Add(new Section { new StyledStringElement("Unable to merge!".t()) { Image = Images.Fork } }); } } if (ViewModel.Comments.Items.Count > 0) { var commentsSec = new Section(); ViewModel.Comments.OrderBy(x => (x.CreatedAt)).ToList().ForEach(x => { if (!string.IsNullOrEmpty(x.Body)) { commentsSec.Add(new CommentElement { Name = x.User.Login, Time = x.CreatedAt.ToDaysAgo(), String = x.Body, Image = Theme.CurrentTheme.AnonymousUserImage, ImageUri = new Uri(x.User.AvatarUrl), BackgroundColor = UIColor.White, }); } }); //Load more if there's more comments // if (model.MoreComments != null) // { // var loadMore = new PaginateElement("Load More".t(), "Loading...".t(), // e => this.DoWorkNoHud(() => model.MoreComments(), // x => Utilities.ShowAlert("Unable to load more!".t(), x.Message))) { AutoLoadOnVisible = false, Background = false }; // commentsSec.Add(loadMore); // } if (commentsSec.Elements.Count > 0) { root.Add(commentsSec); } } var addComment = new StyledStringElement("Add Comment") { Image = Images.Pencil }; addComment.Tapped += AddCommentTapped; root.Add(new Section { addComment }); Root = root; // if (_scrollToLastComment && _comments.Elements.Count > 0) // { // TableView.ScrollToRow(NSIndexPath.FromRowSection(_comments.Elements.Count - 1, 2), UITableViewScrollPosition.Top, true); // _scrollToLastComment = false; // } }
public override void ViewDidLoad() { base.ViewDidLoad(); var save = NavigationItem.RightBarButtonItem = new UIBarButtonItem { Image = Images.Buttons.Save }; var title = new EntryElement("Title", string.Empty, string.Empty) { TextAlignment = UITextAlignment.Right }; var assignedTo = new StringElement("Responsible", "Unassigned", UITableViewCellStyle.Value1); var kind = new StringElement("Issue Type", ViewModel.Kind, UITableViewCellStyle.Value1); var priority = new StringElement("Priority", ViewModel.Priority, UITableViewCellStyle.Value1); var milestone = new StringElement("Milestone", "None", UITableViewCellStyle.Value1); var component = new StringElement("Component", "None", UITableViewCellStyle.Value1); var version = new StringElement("Version", "None", UITableViewCellStyle.Value1); var content = new MultilinedElement("Description"); Root.Reset(new Section { title, assignedTo, kind, priority }, new Section { milestone, component, version }, new Section { content }); OnActivation(d => { d(ViewModel.Bind(x => x.IsSaving).SubscribeStatus("Saving...")); d(ViewModel.Bind(x => x.Title).Subscribe(x => title.Value = x)); d(ViewModel.Bind(x => x.AssignedTo).Subscribe(x => assignedTo.Value = x == null ? "Unassigned" : x.Username)); d(ViewModel.Bind(x => x.Kind, true).Subscribe(x => kind.Value = x)); d(ViewModel.Bind(x => x.Priority, true).Subscribe(x => priority.Value = x)); d(ViewModel.Bind(x => x.Milestone, true).Subscribe(x => milestone.Value = x ?? "None")); d(ViewModel.Bind(x => x.Component, true).Subscribe(x => component.Value = x ?? "None")); d(ViewModel.Bind(x => x.Version, true).Subscribe(x => version.Value = x ?? "None")); d(ViewModel.Bind(x => x.Content, true).Subscribe(x => version.Value = x)); d(title.Changed.Subscribe(x => ViewModel.Title = x)); d(version.Clicked.BindCommand(ViewModel.GoToVersionsCommand)); d(assignedTo.Clicked.BindCommand(ViewModel.GoToAssigneeCommand)); d(milestone.Clicked.BindCommand(ViewModel.GoToMilestonesCommand)); d(component.Clicked.BindCommand(ViewModel.GoToComponentsCommand)); d(save.GetClickedObservable().Subscribe(_ => { View.EndEditing(true); ViewModel.SaveCommand.Execute(null); })); d(content.Clicked.Subscribe(_ => { var composer = new Composer { Title = "Issue Description", Text = ViewModel.Content }; composer.NewComment(this, (text) => { ViewModel.Content = text; composer.CloseComposer(); }); })); d(priority.Clicked.Subscribe(_ => { var ctrl = new IssueAttributesView(IssueModifyViewModel.Priorities, ViewModel.Priority) { Title = "Priority" }; ctrl.SelectedValue = x => ViewModel.Priority = x.ToLower(); NavigationController.PushViewController(ctrl, true); })); d(kind.Clicked.Subscribe(_ => { var ctrl = new IssueAttributesView(IssueModifyViewModel.Kinds, ViewModel.Kind) { Title = "Issue Type" }; ctrl.SelectedValue = x => ViewModel.Kind = x.ToLower(); NavigationController.PushViewController(ctrl, true); })); }); }
public override void ViewDidLoad() { Title = "Edit Issue"; base.ViewDidLoad(); NavigationItem.RightBarButtonItem = new UIBarButtonItem(Theme.CurrentTheme.SaveButton, UIBarButtonItemStyle.Plain, (s, e) => { View.EndEditing(true); ViewModel.SaveCommand.ExecuteIfCan(); }); NavigationItem.RightBarButtonItem.EnableIfExecutable(ViewModel.SaveCommand.CanExecuteObservable); var title = new InputElement("Title", string.Empty, string.Empty); title.Changed += (sender, e) => ViewModel.Title = title.Value; var assignedTo = new StyledStringElement("Responsible", "Unassigned", UITableViewCellStyle.Value1); assignedTo.Accessory = UITableViewCellAccessory.DisclosureIndicator; assignedTo.Tapped += () => ViewModel.GoToAssigneeCommand.Execute(null); var milestone = new StyledStringElement("Milestone", "None", UITableViewCellStyle.Value1); milestone.Accessory = UITableViewCellAccessory.DisclosureIndicator; milestone.Tapped += () => ViewModel.GoToMilestonesCommand.Execute(null); var labels = new StyledStringElement("Labels", "None", UITableViewCellStyle.Value1); labels.Accessory = UITableViewCellAccessory.DisclosureIndicator; labels.Tapped += () => ViewModel.GoToLabelsCommand.Execute(null); var content = new MultilinedElement("Description"); content.Tapped += () => ViewModel.GoToDescriptionCommand.ExecuteIfCan(); var state = new BooleanElement("Open", true); state.ValueChanged += (sender, e) => ViewModel.IsOpen = state.Value; ViewModel.WhenAnyValue(x => x.Issue.Title).Subscribe(x => title.Value = x); ViewModel.WhenAnyValue(x => x.Content).Subscribe(x => content.Value = x); ViewModel.WhenAnyValue(x => x.AssignedTo).Subscribe(x => { assignedTo.Value = x == null ? "Unassigned" : x.Login; if (assignedTo.GetRootElement() != null) { Root.Reload(assignedTo, UITableViewRowAnimation.None); } }); ViewModel.WhenAnyValue(x => x.Milestone).Subscribe(x => { milestone.Value = x == null ? "None" : x.Title; if (assignedTo.GetRootElement() != null) { Root.Reload(milestone, UITableViewRowAnimation.None); } }); ViewModel.WhenAnyValue(x => x.Labels).Subscribe(x => { labels.Value = (ViewModel.Labels == null && ViewModel.Labels.Length == 0) ? "None" : string.Join(", ", ViewModel.Labels.Select(i => i.Name)); if (assignedTo.GetRootElement() != null) { Root.Reload(labels, UITableViewRowAnimation.None); } }); ViewModel.WhenAnyValue(x => x.IsOpen).Subscribe(x => { state.Value = x; if (assignedTo.GetRootElement() != null) { Root.Reload(state, UITableViewRowAnimation.None); } }); ViewModel.SaveCommand.IsExecuting.Subscribe(x => { if (x) { _statusIndicatorService.Show("Updating..."); } else { _statusIndicatorService.Hide(); } }); Root.Reset(new Section { title, assignedTo, milestone, labels }, new Section { state }, new Section { content }); }
// private void ForkRepository() // { // var repoModel = Controller.Model.RepositoryModel; // var alert = new UIAlertView(); // alert.Title = "Fork".t(); // alert.Message = "What would you like to name your fork?".t(); // alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput; // var forkButton = alert.AddButton("Fork!".t()); // var cancelButton = alert.AddButton("Cancel".t()); // alert.CancelButtonIndex = cancelButton; // alert.DismissWithClickedButtonIndex(cancelButton, true); // alert.GetTextField(0).Text = repoModel.Name; // alert.Clicked += (object sender2, UIButtonEventArgs e2) => { // if (e2.ButtonIndex == forkButton) // { // var text = alert.GetTextField(0).Text; // this.DoWork("Forking...".t(), () => { // //var fork = Application.Client.Users[model.Owner.Login].Repositories[model.Name].Fo(text); // BeginInvokeOnMainThread(() => { // // NavigationController.PushViewController(new RepositoryInfoViewController(fork), true); // }); // }, (ex) => { // //We typically get a 'BAD REQUEST' but that usually means that a repo with that name already exists // MonoTouch.Utilities.ShowAlert("Unable to fork".t(), "A repository by that name may already exist in your collection or an internal error has occured.".t()); // }); // } // }; // // alert.Show(); // } public void Render(RepositoryModel model) { Title = model.Name; var root = new RootElement(Title) { UnevenRows = true }; _header.Subtitle = "Updated ".t() + (model.UpdatedAt).ToDaysAgo(); var imageUrl = model.Fork ? CodeHub.Images.GitHubRepoForkUrl : CodeHub.Images.GitHubRepoUrl; _header.Image = ImageLoader.DefaultRequestImage(imageUrl, this); root.Add(new Section(_header)); var sec1 = new Section(); if (!string.IsNullOrEmpty(model.Description) && !string.IsNullOrWhiteSpace(model.Description)) { var element = new MultilinedElement(model.Description) { BackgroundColor = UIColor.White, CaptionColor = Theme.CurrentTheme.MainTitleColor, ValueColor = Theme.CurrentTheme.MainTextColor }; element.CaptionColor = element.ValueColor; element.CaptionFont = element.ValueFont; sec1.Add(element); } sec1.Add(new SplitElement(new SplitElement.Row { Text1 = model.Private ? "Private".t() : "Public".t(), Image1 = model.Private ? Images.Locked : Images.Unlocked, Text2 = model.Language, Image2 = Images.Language })); //Calculate the best representation of the size string size; if (model.Size / 1024f < 1) { size = string.Format("{0:0.##}KB", model.Size); } else if ((model.Size / 1024f / 1024f) < 1) { size = string.Format("{0:0.##}MB", model.Size / 1024f); } else { size = string.Format("{0:0.##}GB", model.Size / 1024f / 1024f); } sec1.Add(new SplitElement(new SplitElement.Row { Text1 = model.OpenIssues + (model.OpenIssues == 1 ? " Issue".t() : " Issues".t()), Image1 = Images.Flag, Text2 = model.Forks.ToString() + (model.Forks == 1 ? " Fork".t() : " Forks".t()), Image2 = Images.Fork })); sec1.Add(new SplitElement(new SplitElement.Row { Text1 = (model.CreatedAt).ToString("MM/dd/yy"), Image1 = Images.Create, Text2 = size, Image2 = Images.Size })); var owner = new StyledStringElement("Owner".t(), model.Owner.Login) { Image = Images.Person, Accessory = UITableViewCellAccessory.DisclosureIndicator }; owner.Tapped += () => NavigationController.PushViewController(new ProfileViewController(model.Owner.Login), true); sec1.Add(owner); if (model.Parent != null) { var parent = new StyledStringElement("Forked From".t(), model.Parent.FullName) { Image = Images.Fork, Accessory = UITableViewCellAccessory.DisclosureIndicator }; parent.Tapped += () => NavigationController.PushViewController(new RepositoryViewController(model.Parent.Owner.Login, model.Parent.Name), true); sec1.Add(parent); } var followers = new StyledStringElement("Stargazers".t(), "" + model.Watchers) { Image = Images.Star, Accessory = UITableViewCellAccessory.DisclosureIndicator }; followers.Tapped += () => NavigationController.PushViewController(new StargazersViewController(model.Owner.Login, model.Name), true); sec1.Add(followers); var events = new StyledStringElement("Events".t(), () => NavigationController.PushViewController(new RepoEventsViewController(model.Owner.Login, model.Name), true), Images.Event); var sec2 = new Section { events }; if (model.HasIssues) { sec2.Add(new StyledStringElement("Issues".t(), () => NavigationController.PushViewController(new IssuesViewController(model.Owner.Login, model.Name), true), Images.Flag)); } if (ViewModel.Readme != null) { sec2.Add(new StyledStringElement("Readme".t(), () => NavigationController.PushViewController(new ReadmeViewController(model.Owner.Login, model.Name), true), Images.File)); } var sec3 = new Section { new StyledStringElement("Changes".t(), ChangesTapped, Images.Commit), new StyledStringElement("Pull Requests".t(), () => NavigationController.PushViewController(new PullRequestsViewController(model.Owner.Login, model.Name), true), Images.Hand), new StyledStringElement("Branches".t(), () => NavigationController.PushViewController(new BranchesViewController(model.Owner.Login, model.Name), true), Images.Branch), new StyledStringElement("Tags".t(), () => NavigationController.PushViewController(new TagsViewController(model.Owner.Login, model.Name), true), Images.Tag) }; root.Add(new[] { sec1, sec2, sec3 }); if (!string.IsNullOrEmpty(model.Homepage)) { var web = new StyledStringElement("Website".t(), () => UIApplication.SharedApplication.OpenUrl(NSUrl.FromString(model.Homepage)), Images.Webpage); root.Add(new Section { web }); } Root = root; }
private void PopulateRoot() { _title = new InputElement("Title", string.Empty, string.Empty); _assignedTo = new StyledStringElement("Responsible", Unassigned, UITableViewCellStyle.Value1); _assignedTo.Accessory = UITableViewCellAccessory.DisclosureIndicator; _assignedTo.Tapped += () => { var p = new IssueAssigneesViewController(Username, RepoSlug); p.SelectedUser = (x) => { _selectedAssignee = x; NavigationController.PopViewControllerAnimated(true); }; NavigationController.PushViewController(p, true); }; _milestone = new StyledStringElement("Milestone".t(), None, UITableViewCellStyle.Value1); _milestone.Accessory = UITableViewCellAccessory.DisclosureIndicator; _milestone.Tapped += () => { var p = new IssueMilestonesViewController(Username, RepoSlug); p.MilestoneSelected = (x) => { _selectedMilestone = x; NavigationController.PopViewControllerAnimated(true); }; NavigationController.PushViewController(p, true); }; _labels = new StyledStringElement("Labels".t(), None, UITableViewCellStyle.Value1); _labels.Accessory = UITableViewCellAccessory.DisclosureIndicator; _labels.Tapped += () => { var p = new IssueLabelsViewController(Username, RepoSlug) { SelectedLabels = _selectedLabels }; NavigationController.PushViewController(p, true); }; _state = new TrueFalseElement("Open", true); _content = new MultilinedElement("Description"); _content.Tapped += () => { var composer = new Composer { Title = "Issue Description", Text = _content.Value, ActionButtonText = "Save" }; composer.NewComment(this, (text) => { _content.Value = text; composer.CloseComposer(); }); }; var root = new RootElement(Title) { new Section { _title, _assignedTo, _milestone, _labels }, new Section { _content } }; //See if it's an existing issue or not... if (ExistingIssue != null) { _title.Value = ExistingIssue.Title; _selectedAssignee = ExistingIssue.Assignee; _selectedMilestone = ExistingIssue.Milestone; _selectedLabels = ExistingIssue.Labels; _content.Value = ExistingIssue.Body; _state.Value = ExistingIssue.State.Equals("open"); //Insert the status thing inbetween title and assigned to elements root.Insert(1, new Section() { _state }); } Root = root; }
protected void UpdateView() { var root = new RootElement(Title) { UnevenRows = true }; var section = new Section(); root.Add(section); var desc = new MultilinedElement("Description") { Value = _model.Description }; desc.Tapped += ChangeDescription; section.Add(desc); var fileSection = new Section(); root.Add(fileSection); foreach (var file in _model.Files.Keys) { var key = file; if (!_model.Files.ContainsKey(key) || _model.Files[file] == null || _model.Files[file].Content == null) continue; var elName = key; if (_model.Files[key].Filename != null) elName = _model.Files[key].Filename; var el = new FileElement(elName, key, _model.Files[key]); el.Tapped += () => { if (!_model.Files.ContainsKey(key)) return; var createController = new ModifyGistFileController(key, _model.Files[key].Content); createController.Save = (name, content) => { if (string.IsNullOrEmpty(name)) throw new InvalidOperationException("Please enter a name for the file"); //If different name & exists somewhere else if (!name.Equals(key)) if (IsDuplicateName(name)) throw new InvalidOperationException("A filename by that type already exists"); if (_originalGist.Files.ContainsKey(key)) _model.Files[key] = new GistEditModel.File { Content = content, Filename = name }; else { _model.Files.Remove(key); _model.Files[name] = new GistEditModel.File { Content = content }; } }; NavigationController.PushViewController(createController, true); }; fileSection.Add(el); } fileSection.Add(new StyledElement("Add New File", AddFile)); Root = root; }
public override void ViewDidLoad() { base.ViewDidLoad(); HeaderView.SetImage(null, Images.Avatar); var detailsSection = new Section(); var diffButton = new ButtonElement(AtlassianIcon.ListAdd.ToImage()); var removedButton = new ButtonElement(AtlassianIcon.ListRemove.ToImage()); var modifiedButton = new ButtonElement(AtlassianIcon.Edit.ToImage()); var allChangesButton = new ButtonElement("All Changes", AtlassianIcon.Devtoolssidediff.ToImage()); detailsSection.Add(new [] { diffButton, removedButton, modifiedButton, allChangesButton }); var additions = ViewModel.WhenAnyValue(x => x.DiffAdditions); diffButton.BindClick(ViewModel.GoToAddedFiles); diffButton.BindDisclosure(additions.Select(x => x > 0)); diffButton.BindCaption(additions.Select(x => $"{x} Added")); var deletions = ViewModel.WhenAnyValue(x => x.DiffDeletions); removedButton.BindClick(ViewModel.GoToRemovedFiles); removedButton.BindDisclosure(deletions.Select(x => x > 0)); removedButton.BindCaption(deletions.Select(x => $"{x} Removed")); var modifications = ViewModel.WhenAnyValue(x => x.DiffModifications); modifiedButton.BindClick(ViewModel.GoToModifiedFiles); modifiedButton.BindDisclosure(modifications.Select(x => x > 0)); modifiedButton.BindCaption(modifications.Select(x => $"{x} Modified")); allChangesButton.BindClick(ViewModel.GoToAllFiles); var split = new SplitButtonElement(); var commentCount = split.AddButton("Comments", "-"); var participants = split.AddButton("Participants", "-"); var approvals = split.AddButton("Approvals", "-"); var headerSection = new Section { split }; var actionButton = new UIBarButtonItem(UIBarButtonSystemItem.Action); NavigationItem.RightBarButtonItem = actionButton; var detailSection = new Section(); var detailsElement = new MultilinedElement(); detailSection.Add(detailsElement); var approvalSection = new Section("Approvals"); var approveElement = new LoaderButtonElement("Approve", AtlassianIcon.Approve.ToImage()); approveElement.Accessory = UITableViewCellAccessory.None; approveElement.BindLoader(ViewModel.ToggleApproveButton); approveElement.BindCaption(ViewModel.WhenAnyValue(x => x.Approved).Select(x => x ? "Unapprove" : "Approve")); var commentsSection = new Section("Comments"); var addCommentElement = new ButtonElement("Add Comment", AtlassianIcon.Addcomment.ToImage()); commentsSection.Add(addCommentElement); if (ViewModel.ShowRepository) { var repo = new ButtonElement(ViewModel.Repository) { TextColor = StringElement.DefaultDetailColor, Image = AtlassianIcon.Devtoolsrepository.ToImage() }; detailSection.Add(repo); repo.Clicked.SelectUnit().BindCommand(ViewModel.GoToRepositoryCommand); } ViewModel.WhenAnyValue(x => x.Commit).Where(x => x != null).Subscribe(x => { participants.Text = x?.Participants?.Count.ToString() ?? "-"; approvals.Text = x?.Participants?.Count(y => y.Approved).ToString() ?? "-"; var titleMsg = (ViewModel.Commit.Message ?? string.Empty).Split(new [] { '\n' }, 2).FirstOrDefault(); var avatarUrl = ViewModel.Commit.Author?.User?.Links?.Avatar?.Href; HeaderView.SubText = titleMsg ?? "Commited " + (ViewModel.Commit.Date).Humanize(); HeaderView.SetImage(new Avatar(avatarUrl).ToUrl(128), Images.Avatar); RefreshHeaderView(); var user = x.Author?.User?.DisplayName ?? x.Author?.Raw ?? "Unknown"; detailsElement.Caption = user; detailsElement.Details = x.Message; }); this.WhenAnyValue(x => x.ViewModel.Approvals) .Select(x => x.Select(y => new UserElement(y)).OfType <Element>()) .Subscribe(x => approvalSection.Reset(x.Concat(new[] { approveElement }))); ViewModel.Comments .CountChanged .Select(x => x.ToString()) .StartWith("-") .Subscribe(x => commentCount.Text = x); ViewModel .Comments .ChangedObservable() .Subscribe(x => { if (x.Count > 0) { var comments = x.Select(y => new Comment(y.Avatar.ToUrl(), y.Name, y.Content, y.CreatedOn)).ToList(); var commentModel = new Views.CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize); var content = new CommentsView { Model = commentModel }.GenerateString(); _commentsElement.SetValue(content); commentsSection.Insert(0, UITableViewRowAnimation.None, _commentsElement); } else { commentsSection.Remove(_commentsElement); } }); ViewModel.WhenAnyValue(x => x.Commit) .Where(x => x != null) .Take(1) .Subscribe(_ => Root.Reset(headerSection, detailsSection, approvalSection, commentsSection)); ViewModel.GoToAddedFiles.Select(_ => CommitFileType.Added).Subscribe(GoToFiles); ViewModel.GoToRemovedFiles.Select(_ => CommitFileType.Removed).Subscribe(GoToFiles); ViewModel.GoToModifiedFiles.Select(_ => CommitFileType.Modified).Subscribe(GoToFiles); ViewModel.GoToAllFiles.Subscribe(_ => GoToAllFiles()); OnActivation(d => { actionButton .GetClickedObservable() .Select(x => (object)x) .BindCommand(ViewModel.ShowMenuCommand) .AddTo(d); addCommentElement .Clicked .SelectUnit() .BindCommand(ViewModel.AddCommentCommand) .AddTo(d); this.WhenAnyObservable(x => x.ViewModel.AddCommentCommand) .Subscribe(_ => NewCommentViewController.Present(this, ViewModel.AddComment)) .AddTo(d); }); }
protected void UpdateView() { ICollection <Section> sections = new LinkedList <Section>(); var section = new Section(); sections.Add(section); var desc = new MultilinedElement("Description", ViewModel.Description); desc.Clicked.Subscribe(_ => ChangeDescription()); section.Add(desc); var pub = new BooleanElement("Public", ViewModel.Public); pub.Changed.Subscribe(x => ViewModel.Public = x); section.Add(pub); var fileSection = new Section(); sections.Add(fileSection); foreach (var file in ViewModel.Files.Keys) { var key = file; if (string.IsNullOrEmpty(ViewModel.Files[file])) { continue; } var size = System.Text.Encoding.UTF8.GetByteCount(ViewModel.Files[file]); var el = new StringElement(file, size + " bytes", UITableViewCellStyle.Subtitle) { Accessory = UITableViewCellAccessory.DisclosureIndicator }; el.Clicked.Subscribe(_ => { if (!ViewModel.Files.ContainsKey(key)) { return; } var createController = new ModifyGistFileController(key, ViewModel.Files[key]); createController.Save = (name, content) => { if (string.IsNullOrEmpty(name)) { throw new InvalidOperationException("Please enter a name for the file"); } //If different name & exists somewhere else if (!name.Equals(key) && ViewModel.Files.ContainsKey(name)) { throw new InvalidOperationException("A filename by that type already exists"); } ViewModel.Files.Remove(key); ViewModel.Files[name] = content; ViewModel.Files = ViewModel.Files; // Trigger refresh }; NavigationController.PushViewController(createController, true); }); fileSection.Add(el); } var add = new StringElement("Add New File"); add.Clicked.Subscribe(_ => AddFile()); fileSection.Add(add); Root.Reset(sections); }
protected void UpdateView() { var root = new RootElement(Title) { UnevenRows = true }; var section = new Section(); root.Add(section); var desc = new MultilinedElement("Description") { Value = ViewModel.Description }; desc.Tapped += ChangeDescription; section.Add(desc); var pub = new TrueFalseElement("Public", ViewModel.Public, (e) => ViewModel.Public = e.Value); section.Add(pub); var fileSection = new Section(); root.Add(fileSection); foreach (var file in ViewModel.Files.Keys) { var key = file; if (string.IsNullOrEmpty(ViewModel.Files[file])) { continue; } var size = System.Text.Encoding.UTF8.GetByteCount(ViewModel.Files[file]); var el = new StyledStringElement(file, size + " bytes", UITableViewCellStyle.Subtitle) { Accessory = UITableViewCellAccessory.DisclosureIndicator }; el.Tapped += () => { if (!ViewModel.Files.ContainsKey(key)) { return; } var createController = new ModifyGistFileController(key, ViewModel.Files[key]); createController.Save = (name, content) => { if (string.IsNullOrEmpty(name)) { throw new InvalidOperationException("Please enter a name for the file"); } //If different name & exists somewhere else if (!name.Equals(key) && ViewModel.Files.ContainsKey(name)) { throw new InvalidOperationException("A filename by that type already exists"); } ViewModel.Files.Remove(key); ViewModel.Files[name] = content; ViewModel.Files = ViewModel.Files; // Trigger refresh }; NavigationController.PushViewController(createController, true); }; fileSection.Add(el); } fileSection.Add(new StyledStringElement("Add New File", AddFile)); Root = root; }
public override void ViewDidLoad() { base.ViewDidLoad(); TableView.RowHeight = UITableView.AutomaticDimension; TableView.EstimatedRowHeight = 44f; var vm = (IssueEditViewModel)ViewModel; var saveButton = new UIBarButtonItem { Image = Images.Buttons.SaveButton }; NavigationItem.RightBarButtonItem = saveButton; var title = new InputElement("Title", string.Empty, string.Empty); var assignedTo = new StringElement("Responsible", "Unassigned", UITableViewCellStyle.Value1); var milestone = new StringElement("Milestone", "None", UITableViewCellStyle.Value1); var labels = new StringElement("Labels", "None", UITableViewCellStyle.Value1); var content = new MultilinedElement("Description"); var state = new BooleanElement("Open", true); Root.Reset(new Section { title, assignedTo, milestone, labels }, new Section { state }, new Section { content }); OnActivation(d => { d(vm.Bind(x => x.IssueTitle, true).Subscribe(x => title.Value = x)); d(title.Changed.Subscribe(x => vm.IssueTitle = x)); d(assignedTo.Clicked.BindCommand(vm.GoToAssigneeCommand)); d(milestone.Clicked.BindCommand(vm.GoToMilestonesCommand)); d(labels.Clicked.BindCommand(vm.GoToLabelsCommand)); d(vm.Bind(x => x.IsOpen, true).Subscribe(x => state.Value = x)); d(vm.Bind(x => x.IsSaving).SubscribeStatus("Updating...")); d(state.Changed.Subscribe(x => vm.IsOpen = x)); d(vm.Bind(x => x.Content, true).Subscribe(x => content.Details = x)); d(vm.Bind(x => x.AssignedTo, true).Subscribe(x => { assignedTo.Value = x == null ? "Unassigned" : x.Login; })); d(vm.Bind(x => x.Milestone, true).Subscribe(x => { milestone.Value = x == null ? "None" : x.Title; })); d(vm.BindCollection(x => x.Labels, true).Subscribe(x => { labels.Value = vm.Labels.Items.Count == 0 ? "None" : string.Join(", ", vm.Labels.Items.Select(i => i.Name)); })); d(saveButton.GetClickedObservable().Subscribe(_ => { View.EndEditing(true); vm.SaveCommand.Execute(null); })); d(content.Clicked.Subscribe(_ => { var composer = new MarkdownComposerViewController { Title = "Issue Description", Text = content.Details }; composer.NewComment(this, (text) => { vm.Content = text; composer.CloseComposer(); }); })); }); }
protected void UpdateView() { var root = new RootElement(Title) { UnevenRows = true }; var section = new Section(); root.Add(section); var desc = new MultilinedElement("Description") { Value = _model.Description }; desc.Tapped += ChangeDescription; section.Add(desc); var fileSection = new Section(); root.Add(fileSection); foreach (var file in _model.Files.Keys) { var key = file; if (!_model.Files.ContainsKey(key) || _model.Files[file] == null || _model.Files[file].Content == null) { continue; } var elName = key; if (_model.Files[key].Filename != null) { elName = _model.Files[key].Filename; } var el = new FileElement(elName, key, _model.Files[key]); el.Tapped += () => { if (!_model.Files.ContainsKey(key)) { return; } var createController = new ModifyGistFileController(key, _model.Files[key].Content); createController.Save = (name, content) => { if (string.IsNullOrEmpty(name)) { throw new InvalidOperationException("Please enter a name for the file"); } //If different name & exists somewhere else if (!name.Equals(key)) { if (IsDuplicateName(name)) { throw new InvalidOperationException("A filename by that type already exists"); } } if (_originalGist.Files.ContainsKey(key)) { _model.Files[key] = new GistEditModel.File { Content = content, Filename = name } } ; else { _model.Files.Remove(key); _model.Files[name] = new GistEditModel.File { Content = content }; } }; NavigationController.PushViewController(createController, true); }; fileSection.Add(el); } fileSection.Add(new StyledStringElement("Add New File", AddFile)); Root = root; }
public override void ViewDidLoad() { base.ViewDidLoad(); _hud = this.CreateHud(); NavigationItem.RightBarButtonItem = new UIBarButtonItem(Theme.CurrentTheme.SaveButton, UIBarButtonItemStyle.Plain, (s, e) => { View.EndEditing(true); ViewModel.SaveCommand.Execute(null); }); var title = new InputElement("Title", string.Empty, string.Empty) { TextAlignment = UITextAlignment.Right }; title.Changed += (object sender, EventArgs e) => ViewModel.Title = title.Value; var assignedTo = new StyledStringElement("Responsible", "Unassigned", UITableViewCellStyle.Value1); assignedTo.Accessory = UITableViewCellAccessory.DisclosureIndicator; assignedTo.Tapped += () => ViewModel.GoToAssigneeCommand.Execute(null); var kind = new StyledStringElement("Issue Type", ViewModel.Kind, UITableViewCellStyle.Value1); kind.Accessory = UITableViewCellAccessory.DisclosureIndicator; kind.Tapped += () => { var ctrl = new IssueAttributesView(IssueModifyViewModel.Kinds, ViewModel.Kind) { Title = "Issue Type" }; ctrl.SelectedValue = x => ViewModel.Kind = x.ToLower(); NavigationController.PushViewController(ctrl, true); }; var priority = new StyledStringElement("Priority", ViewModel.Priority, UITableViewCellStyle.Value1); priority.Accessory = UITableViewCellAccessory.DisclosureIndicator; priority.Tapped += () => { var ctrl = new IssueAttributesView(IssueModifyViewModel.Priorities, ViewModel.Priority) { Title = "Priority" }; ctrl.SelectedValue = x => ViewModel.Priority = x.ToLower(); NavigationController.PushViewController(ctrl, true); }; var milestone = new StyledStringElement("Milestone".t(), "None", UITableViewCellStyle.Value1); milestone.Accessory = UITableViewCellAccessory.DisclosureIndicator; milestone.Tapped += () => ViewModel.GoToMilestonesCommand.Execute(null); var component = new StyledStringElement("Component".t(), "None", UITableViewCellStyle.Value1); component.Accessory = UITableViewCellAccessory.DisclosureIndicator; component.Tapped += () => ViewModel.GoToComponentsCommand.Execute(null); var version = new StyledStringElement("Version".t(), "None", UITableViewCellStyle.Value1); version.Accessory = UITableViewCellAccessory.DisclosureIndicator; version.Tapped += () => ViewModel.GoToVersionsCommand.Execute(null); var content = new MultilinedElement("Description"); content.Tapped += () => { var composer = new Composer { Title = "Issue Description", Text = content.Value }; composer.NewComment(this, (text) => { ViewModel.Content = text; composer.CloseComposer(); }); }; ViewModel.Bind(x => x.IsSaving, x => { if (x) { _hud.Show("Saving..."); } else { _hud.Hide(); } }); Root = new RootElement(Title) { new Section { title, assignedTo, kind, priority }, new Section { milestone, component, version }, new Section { content } }; ViewModel.Bind(x => x.Title, x => { title.Value = x; Root.Reload(title, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.AssignedTo, x => { assignedTo.Value = x == null ? "Unassigned" : x.Username; Root.Reload(assignedTo, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.Kind, x => { kind.Value = x; Root.Reload(kind, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.Priority, x => { priority.Value = x; Root.Reload(priority, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.Milestone, x => { milestone.Value = x ?? "None"; Root.Reload(milestone, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.Component, x => { component.Value = x ?? "None"; Root.Reload(component, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.Version, x => { version.Value = x ?? "None"; Root.Reload(version, UITableViewRowAnimation.None); }, true); ViewModel.Bind(x => x.Content, x => { content.Value = x; Root.Reload(content, UITableViewRowAnimation.None); }, true); }