async Task LoadSource(string content, string filename, bool isMarkdown) { var fontSize = (int)UIFont.PreferredSubheadline.PointSize; if (isMarkdown) { var markdownContent = await _applicationService.Client.Markdown.GetMarkdown(content); var model = new MarkdownModel(markdownContent, fontSize); var htmlContent = new MarkdownWebView { Model = model }; LoadContent(htmlContent.GenerateString()); } else { var zoom = UIDevice.CurrentDevice.UserInterfaceIdiom != UIUserInterfaceIdiom.Phone; var theme = _applicationService.Account.CodeEditTheme; var model = new SyntaxHighlighterModel(content, theme, fontSize, zoom, file: filename); var contentView = new SyntaxHighlighterWebView { Model = model }; LoadContent(contentView.GenerateString()); } }
async Task LoadSource(Uri fileUri) { var fontSize = (int)UIFont.PreferredSubheadline.PointSize; var content = System.IO.File.ReadAllText(fileUri.LocalPath, System.Text.Encoding.UTF8); if (ViewModel.IsMarkdown) { var markdownContent = await Mvx.Resolve <IApplicationService>().Client.Markdown.GetMarkdown(content); var model = new MarkdownModel(markdownContent, fontSize); var htmlContent = new MarkdownWebView { Model = model }; LoadContent(htmlContent.GenerateString()); } else { var zoom = UIDevice.CurrentDevice.UserInterfaceIdiom != UIUserInterfaceIdiom.Phone; var model = new SyntaxHighlighterModel(content, "idea", fontSize, zoom, fileUri.LocalPath); var contentView = new SyntaxHighlighterWebView { Model = model }; LoadContent(contentView.GenerateString()); } }
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)); }); }