CloudFileCell.swift 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. if self.checkDelegate != nil {
  29. self.checkBoxImage.addTapGesture { (tap) in
  30. self.checkDelegate?.checkItem(file)
  31. }
  32. }
  33. }
  34. private func formatSize(len: Int?) -> String {
  35. if let size = len {
  36. if size < 1024 {
  37. return size.toString
  38. } else if size < (1024 * 1024) {
  39. return (size / 1024).toString + "K"
  40. } else {
  41. return (size / 1024 / 1024).toString + "M"
  42. }
  43. }else {
  44. return "0K"
  45. }
  46. }
  47. private func setFileTypeImage(ext: String?) {
  48. if let type = ext {
  49. switch type {
  50. case "jpg", "png", "jepg", "gif":
  51. self.fileImage.image = UIImage(named: "icon_img")
  52. break
  53. case "html":
  54. self.fileImage.image = UIImage(named: "icon_html")
  55. break
  56. case "xls", "xlsx":
  57. self.fileImage.image = UIImage(named: "icon_excel")
  58. break
  59. case "doc", "docx":
  60. self.fileImage.image = UIImage(named: "icon_word")
  61. break
  62. case "ppt", "pptx":
  63. self.fileImage.image = UIImage(named: "icon_ppt")
  64. break
  65. case "pdf":
  66. self.fileImage.image = UIImage(named: "icon_pdf")
  67. break
  68. case "mp4":
  69. self.fileImage.image = UIImage(named: "icon_mp4")
  70. break
  71. case "mp3":
  72. self.fileImage.image = UIImage(named: "icon_mp3")
  73. break
  74. case "zip", "rar", "7z":
  75. self.fileImage.image = UIImage(named: "icon_zip")
  76. break
  77. default :
  78. self.fileImage.image = UIImage(named: "icon_moren")
  79. break
  80. }
  81. }else {
  82. self.fileImage.image = UIImage(named: "icon_moren")
  83. }
  84. }
  85. }