CFFileTableViewCell.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.showCheckBox = isShowCheck
  41. if self.showCheckBox {
  42. self.checkBoxButton.isHidden = false
  43. if checked {
  44. self.checkBoxButton.setImage(UIImage(named: "icon__ok2_click"), for: .normal)
  45. }else {
  46. self.checkBoxButton.setImage(UIImage(named: "icon_circle"), for: .normal)
  47. }
  48. }else {
  49. self.checkBoxButton.isHidden = true
  50. }
  51. }
  52. private func formatSize(len: Int?) -> String {
  53. if let size = len {
  54. if size < 1024 {
  55. return size.toString
  56. } else if size < (1024 * 1024) {
  57. return (size / 1024).toString + "K"
  58. } else {
  59. return (size / 1024 / 1024).toString + "M"
  60. }
  61. }else {
  62. return "0K"
  63. }
  64. }
  65. private func setFileTypeImage(ext: String?) {
  66. if let type = ext {
  67. switch type {
  68. case "jpg", "png", "jepg", "gif":
  69. self.fileTypeImageView.image = UIImage(named: "icon_img")
  70. break
  71. case "html":
  72. self.fileTypeImageView.image = UIImage(named: "icon_html")
  73. break
  74. case "xls", "xlsx":
  75. self.fileTypeImageView.image = UIImage(named: "icon_excel")
  76. break
  77. case "doc", "docx":
  78. self.fileTypeImageView.image = UIImage(named: "icon_word")
  79. break
  80. case "ppt", "pptx":
  81. self.fileTypeImageView.image = UIImage(named: "icon_ppt")
  82. break
  83. case "pdf":
  84. self.fileTypeImageView.image = UIImage(named: "icon_pdf")
  85. break
  86. case "mp4":
  87. self.fileTypeImageView.image = UIImage(named: "icon_mp4")
  88. break
  89. case "mp3":
  90. self.fileTypeImageView.image = UIImage(named: "icon_mp3")
  91. break
  92. case "zip", "rar", "7z":
  93. self.fileTypeImageView.image = UIImage(named: "icon_zip")
  94. break
  95. default :
  96. self.fileTypeImageView.image = UIImage(named: "icon_moren")
  97. break
  98. }
  99. }else {
  100. self.fileTypeImageView.image = UIImage(named: "icon_moren")
  101. }
  102. }
  103. }