public DetailViewController(RSSFeedItem item) : base(UITableViewStyle.Grouped, null, true) { var attributes = new NSAttributedStringDocumentAttributes(); attributes.DocumentType = NSDocumentType.HTML; attributes.StringEncoding = NSStringEncoding.UTF8; var error = new NSError(); var htmlString = new NSAttributedString(item.Description, attributes, ref error); Root = new RootElement(item.Title) { new Section{ new StringElement(item.Author), new StringElement(item.PublishDate), new StyledMultilineElement(htmlString), new HtmlElement("Full Article", item.Link) } }; NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, async delegate { var message = item.Title + " " + item.Link + " #PlanetXamarin"; var social = new UIActivityViewController(new NSObject[] { new NSString(message)}, new UIActivity[] { new UIActivity() }); PresentViewController(social, true, null); }); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); var idString = string.Empty; //parse out id and get feed item from cache if (NavigationContext.QueryString.TryGetValue("id", out idString)) { var id = 0; int.TryParse(idString, out id); item = MasterPage.ViewModel.GetFeedItem(id); DataContext = item; var fullHtml = WebBrowserHelper.WrapHtml(item.Description, Browser.ActualWidth); Browser.NavigateToString(fullHtml); } }
public DetailViewController(RSSFeedItem item) : base(UITableViewStyle.Grouped, null, true) { var attributes = new NSAttributedStringDocumentAttributes(); attributes.DocumentType = NSDocumentType.HTML; attributes.StringEncoding = NSStringEncoding.UTF8; var error = new NSError(); var htmlString = new NSAttributedString(item.Description, attributes, ref error); Root = new RootElement(item.Title) { new Section{ new StringElement(item.Author), new StringElement(item.PublishDate), new StyledMultilineElement(htmlString), new HtmlElement("Full Article", item.Link) } }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Detail); webView = FindViewById<WebView>(Resource.Id.webview); var id = Intent.GetIntExtra("id", 0); feedItem = MasterActivity.ViewModel.GetFeedItem(id); webView.LoadData(feedItem.Description, "text/html", "charset=UTF-8"); webView.Settings.JavaScriptEnabled = true; ActionBar.Title = feedItem.Title; readFullButton = FindViewById<Button>(Resource.Id.button_read_full); readFullButton.Click += (sender, args) => { webView.LoadUrl(feedItem.Link); readFullButton.Visibility = ViewStates.Gone; }; }
void BeginDownloadingImage (RSSFeedItem app, NSIndexPath path) { // Queue the image to be downloaded. This task will execute // as soon as the existing ones have finished. byte[] data = null; DownloadTask = DownloadTask.ContinueWith (prevTask => { try { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; using (var c = new GzipWebClient ()) data = c.DownloadData (app.Image); } finally { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; } }); // When the download task is finished, queue another task to update the UI. // Note that this task will run only if the download is successful and it // uses the CurrentSyncronisationContext, which on MonoTouch causes the task // to be run on the main UI thread. This allows us to safely access the UI. DownloadTask = DownloadTask.ContinueWith (t => { // Load the image from the byte array. app.TheImage = UIImage.LoadFromData (NSData.FromArray (data)); // Retrieve the cell which corresponds to the current App. If the cell is null, it means the user // has already scrolled that app off-screen. var cell = TableView.VisibleCells.Where (c => c.Tag == viewModel.FeedItems.IndexOf (app)).FirstOrDefault (); if (cell != null) cell.ImageView.Image = app.TheImage; }, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext ()); }