| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Drawing;
- #if __UNIFIED__
- using Foundation;
- using UIKit;
- #else
- using MonoTouch.Foundation;
- using MonoTouch.UIKit;
- using nint = System.Int32;
- #endif
- using SDWebImage;
- namespace SDWebImageSample
- {
- public partial class DetailViewController : UIViewController
- {
- public NSUrl ImageUrl { get; set; }
- UIActivityIndicatorView activityIndicator;
- public DetailViewController () : base ("DetailViewController", null)
- {
- }
-
- public override void DidReceiveMemoryWarning ()
- {
- // Releases the view if it doesn't have a superview.
- base.DidReceiveMemoryWarning ();
- // Release any cached data, images, etc that aren't in use.
- }
-
- public override void ViewDidLoad ()
- {
- base.ViewDidLoad ();
-
- configureView ();
- }
- void configureView ()
- {
- if (ImageUrl != null) {
- ImageView.SetImage (ImageUrl, null, SDWebImageOptions.ProgressiveDownload, ProgressHandler, CompletedHandler);
- }
- }
- void ProgressHandler (nint receivedSize, nint expectedSize)
- {
- if (activityIndicator == null) {
- InvokeOnMainThread (() => {
- activityIndicator = new UIActivityIndicatorView (UIActivityIndicatorViewStyle.Gray);
- ImageView.AddSubview (activityIndicator);
- activityIndicator.Center = ImageView.Center;
- activityIndicator.StartAnimating ();
- });
- }
- }
- void CompletedHandler (UIImage image, NSError error, SDImageCacheType cacheType, NSUrl url)
- {
- if (activityIndicator != null) {
- InvokeOnMainThread (() => {
- activityIndicator.RemoveFromSuperview ();
- activityIndicator = null;
- });
- }
- }
- }
- }
|