ImageLoaderElement.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using MonoTouch.Dialog;
  3. using SDWebImage;
  4. #if __UNIFIED__
  5. using Foundation;
  6. using UIKit;
  7. #else
  8. using MonoTouch.Foundation;
  9. using MonoTouch.UIKit;
  10. #endif
  11. namespace SDWebImageMTDialogSample
  12. {
  13. public class ImageLoaderStringElement : StringElement
  14. {
  15. static NSString skey = new NSString ("ImageLoaderStringElement");
  16. public UIImage Placeholder { get; private set; }
  17. public NSUrl ImageUrl { get; private set; }
  18. public UITableViewCellAccessory Accessory { get; set; }
  19. public ImageLoaderStringElement (string caption, NSUrl imageUrl, UIImage placeholder) : base (caption)
  20. {
  21. Placeholder = placeholder;
  22. ImageUrl = imageUrl;
  23. this.Accessory = UITableViewCellAccessory.None;
  24. }
  25. public ImageLoaderStringElement (string caption, string value, NSUrl imageUrl, UIImage placeholder) : base (caption, value)
  26. {
  27. Placeholder = placeholder;
  28. ImageUrl = imageUrl;
  29. this.Accessory = UITableViewCellAccessory.None;
  30. }
  31. #if __UNIFIED__
  32. public ImageLoaderStringElement (string caption, Action tapped, NSUrl imageUrl, UIImage placeholder) : base (caption, tapped)
  33. #else
  34. public ImageLoaderStringElement (string caption, NSAction tapped, NSUrl imageUrl, UIImage placeholder) : base (caption, tapped)
  35. #endif
  36. {
  37. Placeholder = placeholder;
  38. ImageUrl = imageUrl;
  39. this.Accessory = UITableViewCellAccessory.None;
  40. }
  41. protected override NSString CellKey {
  42. get {
  43. return skey;
  44. }
  45. }
  46. public override UITableViewCell GetCell (UITableView tv)
  47. {
  48. var cell = tv.DequeueReusableCell (CellKey);
  49. if (cell == null){
  50. cell = new UITableViewCell (Value == null ? UITableViewCellStyle.Default : UITableViewCellStyle.Subtitle, CellKey);
  51. cell.SelectionStyle = UITableViewCellSelectionStyle.Blue;
  52. }
  53. cell.Accessory = Accessory;
  54. cell.TextLabel.Text = Caption;
  55. cell.TextLabel.TextAlignment = Alignment;
  56. cell.ImageView.SetImage (ImageUrl, Placeholder);
  57. // The check is needed because the cell might have been recycled.
  58. if (cell.DetailTextLabel != null)
  59. cell.DetailTextLabel.Text = Value == null ? "" : Value;
  60. return cell;
  61. }
  62. }
  63. }