DetailViewController.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Drawing;
  3. #if __UNIFIED__
  4. using Foundation;
  5. using UIKit;
  6. #else
  7. using MonoTouch.Foundation;
  8. using MonoTouch.UIKit;
  9. using nint = System.Int32;
  10. #endif
  11. using SDWebImage;
  12. namespace SDWebImageSample
  13. {
  14. public partial class DetailViewController : UIViewController
  15. {
  16. public NSUrl ImageUrl { get; set; }
  17. UIActivityIndicatorView activityIndicator;
  18. public DetailViewController () : base ("DetailViewController", null)
  19. {
  20. }
  21. public override void DidReceiveMemoryWarning ()
  22. {
  23. // Releases the view if it doesn't have a superview.
  24. base.DidReceiveMemoryWarning ();
  25. // Release any cached data, images, etc that aren't in use.
  26. }
  27. public override void ViewDidLoad ()
  28. {
  29. base.ViewDidLoad ();
  30. configureView ();
  31. }
  32. void configureView ()
  33. {
  34. if (ImageUrl != null) {
  35. ImageView.SetImage (ImageUrl, null, SDWebImageOptions.ProgressiveDownload, ProgressHandler, CompletedHandler);
  36. }
  37. }
  38. void ProgressHandler (nint receivedSize, nint expectedSize)
  39. {
  40. if (activityIndicator == null) {
  41. InvokeOnMainThread (() => {
  42. activityIndicator = new UIActivityIndicatorView (UIActivityIndicatorViewStyle.Gray);
  43. ImageView.AddSubview (activityIndicator);
  44. activityIndicator.Center = ImageView.Center;
  45. activityIndicator.StartAnimating ();
  46. });
  47. }
  48. }
  49. void CompletedHandler (UIImage image, NSError error, SDImageCacheType cacheType, NSUrl url)
  50. {
  51. if (activityIndicator != null) {
  52. InvokeOnMainThread (() => {
  53. activityIndicator.RemoveFromSuperview ();
  54. activityIndicator = null;
  55. });
  56. }
  57. }
  58. }
  59. }