DetailViewController.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MonoTouch.Dialog;
  5. using SDWebImage;
  6. #if __UNIFIED__
  7. using Foundation;
  8. using UIKit;
  9. #else
  10. using MonoTouch.Foundation;
  11. using MonoTouch.UIKit;
  12. using CGRect = global::System.Drawing.RectangleF;
  13. using CGSize = global::System.Drawing.SizeF;
  14. using CGPoint = global::System.Drawing.PointF;
  15. using nfloat = global::System.Single;
  16. using nint = global::System.Int32;
  17. using nuint = global::System.UInt32;
  18. #endif
  19. namespace SDWebImageMTDialogSample
  20. {
  21. public partial class DetailViewController : UIViewController
  22. {
  23. UIImageView ImageView;
  24. UIActivityIndicatorView activityIndicator;
  25. public NSUrl ImageUrl { get; private set; }
  26. public DetailViewController (NSUrl imageUrl) : base ()
  27. {
  28. ImageUrl = imageUrl;
  29. }
  30. public override void ViewDidLoad ()
  31. {
  32. base.ViewDidLoad ();
  33. View.BackgroundColor = UIColor.White;
  34. ImageView = new UIImageView (View.Bounds) {
  35. ContentMode = UIViewContentMode.ScaleAspectFit
  36. };
  37. View.AddSubview (ImageView);
  38. if (ImageUrl != null) {
  39. ImageView.SetImage (ImageUrl, null, SDWebImageOptions.ProgressiveDownload, ProgressHandler, CompletedHandler);
  40. }
  41. }
  42. void ProgressHandler (nint receivedSize, nint expectedSize)
  43. {
  44. if (activityIndicator == null) {
  45. InvokeOnMainThread (()=> {
  46. activityIndicator = new UIActivityIndicatorView (UIActivityIndicatorViewStyle.Gray);
  47. ImageView.AddSubview (activityIndicator);
  48. activityIndicator.Center = ImageView.Center;
  49. activityIndicator.StartAnimating ();
  50. });
  51. }
  52. }
  53. void CompletedHandler (UIImage image, NSError error, SDImageCacheType cacheType, NSUrl url)
  54. {
  55. if (activityIndicator != null) {
  56. InvokeOnMainThread (()=> {
  57. activityIndicator.RemoveFromSuperview ();
  58. activityIndicator = null;
  59. });
  60. }
  61. }
  62. }
  63. }