CFFileTableViewCell.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // CFFileTableViewCell.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2019/10/17.
  6. // Copyright © 2019 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CocoaLumberjack
  10. class CFFileTableViewCell: UITableViewCell {
  11. @IBOutlet weak var checkBoxButton: UIButton!
  12. @IBOutlet weak var fileTypeImageView: UIImageView!
  13. @IBOutlet weak var fileSizeLabel: UILabel!
  14. @IBOutlet weak var fileTimeLabel: UILabel!
  15. @IBOutlet weak var fileNameLabel: UILabel!
  16. var file: OOAttachment?
  17. var clickdelegate: CloudFileCheckClickDelegate?
  18. var showCheckBox = true
  19. @IBAction func clickBoxAction(_ sender: Any) {
  20. DDLogDebug("点击。。。。。。。。CFFileTableViewCell")
  21. if self.showCheckBox {
  22. if self.file != nil {
  23. DDLogDebug("enter click file")
  24. self.clickdelegate?.clickFile(self.file!)
  25. }
  26. }
  27. }
  28. override func awakeFromNib() {
  29. super.awakeFromNib()
  30. }
  31. override func setSelected(_ selected: Bool, animated: Bool) {
  32. super.setSelected(selected, animated: animated)
  33. }
  34. func setData(file: OOAttachment, checked: Bool, isShowCheck: Bool = true) {
  35. self.file = file
  36. self.fileNameLabel.text = file.name ?? ""
  37. self.fileTimeLabel.text = file.lastUpdateTime ?? ""
  38. self.fileSizeLabel.text = self.formatSize(len: file.length)
  39. // self.setFileTypeImage(ext: file.extension)
  40. self.fileTypeImageView.image = UIImage(named: O2.fileExtension2Icon(file.extension))
  41. self.showCheckBox = isShowCheck
  42. if self.showCheckBox {
  43. self.checkBoxButton.isHidden = false
  44. if checked {
  45. self.checkBoxButton.setImage(UIImage(named: "icon__ok2_click"), for: .normal)
  46. }else {
  47. self.checkBoxButton.setImage(UIImage(named: "icon_circle"), for: .normal)
  48. }
  49. }else {
  50. self.checkBoxButton.isHidden = true
  51. }
  52. }
  53. private func formatSize(len: Int?) -> String {
  54. if let size = len {
  55. if size < 1024 {
  56. return size.toString
  57. } else if size < (1024 * 1024) {
  58. return (size / 1024).toString + "K"
  59. } else {
  60. return (size / 1024 / 1024).toString + "M"
  61. }
  62. }else {
  63. return "0K"
  64. }
  65. }
  66. // private func setFileTypeImage(ext: String?) {
  67. // if let type = ext {
  68. // switch type {
  69. // case "jpg", "png", "jepg", "gif":
  70. // self.fileTypeImageView.image = UIImage(named: "icon_img")
  71. // break
  72. // case "html":
  73. // self.fileTypeImageView.image = UIImage(named: "icon_html")
  74. // break
  75. // case "xls", "xlsx":
  76. // self.fileTypeImageView.image = UIImage(named: "icon_excel")
  77. // break
  78. // case "doc", "docx":
  79. // self.fileTypeImageView.image = UIImage(named: "icon_word")
  80. // break
  81. // case "ppt", "pptx":
  82. // self.fileTypeImageView.image = UIImage(named: "icon_ppt")
  83. // break
  84. // case "pdf":
  85. // self.fileTypeImageView.image = UIImage(named: "icon_pdf")
  86. // break
  87. // case "mp4":
  88. // self.fileTypeImageView.image = UIImage(named: "icon_mp4")
  89. // break
  90. // case "mp3":
  91. // self.fileTypeImageView.image = UIImage(named: "icon_mp3")
  92. // break
  93. // case "zip", "rar", "7z":
  94. // self.fileTypeImageView.image = UIImage(named: "icon_zip")
  95. // break
  96. // default :
  97. // self.fileTypeImageView.image = UIImage(named: "icon_file_more")
  98. // break
  99. // }
  100. // }else {
  101. // self.fileTypeImageView.image = UIImage(named: "icon_file_more")
  102. // }
  103. // }
  104. }