CloudFileCell.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // CloudFileCell.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2019/10/8.
  6. // Copyright © 2019 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. class CloudFileCell: UITableViewCell {
  10. @IBOutlet weak var fileImage: UIImageView!
  11. @IBOutlet weak var fileNameLabel: UILabel!
  12. @IBOutlet weak var fileUpdateTimeLabel: UILabel!
  13. @IBOutlet weak var fileSizeLabel: UILabel!
  14. @IBOutlet weak var checkBoxImage: UIImageView!
  15. var checkDelegate: CloudFileCheckDelegate?
  16. override func awakeFromNib() {
  17. super.awakeFromNib()
  18. // Initialization code
  19. }
  20. override func setSelected(_ selected: Bool, animated: Bool) {
  21. super.setSelected(selected, animated: animated)
  22. }
  23. func setData(file: OOAttachment) {
  24. self.fileNameLabel.text = file.name ?? ""
  25. self.fileUpdateTimeLabel.text = file.lastUpdateTime ?? ""
  26. self.fileSizeLabel.text = self.formatSize(len: file.length)
  27. // self.setFileTypeImage(ext: file.extension)
  28. self.fileImage.image = UIImage(named: O2.fileExtension2Icon(file.extension))
  29. if self.checkDelegate != nil {
  30. self.checkBoxImage.addTapGesture { (tap) in
  31. self.checkDelegate?.checkItem(file)
  32. }
  33. }
  34. }
  35. private func formatSize(len: Int?) -> String {
  36. if let size = len {
  37. if size < 1024 {
  38. return size.toString
  39. } else if size < (1024 * 1024) {
  40. return (size / 1024).toString + "K"
  41. } else {
  42. return (size / 1024 / 1024).toString + "M"
  43. }
  44. }else {
  45. return "0K"
  46. }
  47. }
  48. // private func setFileTypeImage(ext: String?) {
  49. // if let type = ext {
  50. // switch type {
  51. // case "jpg", "png", "jepg", "gif":
  52. // self.fileImage.image = UIImage(named: "icon_img")
  53. // break
  54. // case "html":
  55. // self.fileImage.image = UIImage(named: "icon_html")
  56. // break
  57. // case "xls", "xlsx":
  58. // self.fileImage.image = UIImage(named: "icon_excel")
  59. // break
  60. // case "doc", "docx":
  61. // self.fileImage.image = UIImage(named: "icon_word")
  62. // break
  63. // case "ppt", "pptx":
  64. // self.fileImage.image = UIImage(named: "icon_ppt")
  65. // break
  66. // case "pdf":
  67. // self.fileImage.image = UIImage(named: "icon_pdf")
  68. // break
  69. // case "mp4":
  70. // self.fileImage.image = UIImage(named: "icon_mp4")
  71. // break
  72. // case "mp3":
  73. // self.fileImage.image = UIImage(named: "icon_mp3")
  74. // break
  75. // case "zip", "rar", "7z":
  76. // self.fileImage.image = UIImage(named: "icon_zip")
  77. // break
  78. // default :
  79. // self.fileImage.image = UIImage(named: "icon_file_more")
  80. // break
  81. // }
  82. // }else {
  83. // self.fileImage.image = UIImage(named: "icon_file_more")
  84. // }
  85. // }
  86. }