CustomGroupDetailVideoCell.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2017-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. import UIKit
  21. import ThreemaFramework
  22. class CustomGroupDetailVideoCell: CustomGroupDetailImageCell {
  23. class override func cellReuseIdentifier() -> String {
  24. return "CustomVideoAssetIdentifier"
  25. }
  26. override init(frame: CGRect) {
  27. super.init(frame: frame)
  28. self.contentView.insertSubview(videoInfoView, belowSubview: checkView)
  29. }
  30. required init?(coder aDecoder: NSCoder) {
  31. fatalError("init(coder:) has not been implemented")
  32. }
  33. override func layoutSubviews() {
  34. super.layoutSubviews()
  35. let height: CGFloat = 30
  36. self.videoInfoView.frame = CGRect(x: 0, y: self.contentView.bounds.height - height,
  37. width: self.contentView.bounds.width, height: height)
  38. }
  39. override weak var asset: DKAsset? {
  40. didSet {
  41. if let asset = asset {
  42. let videoDurationLabel = self.videoInfoView.viewWithTag(-1) as! UILabel
  43. let minutes: Int = Int(asset.duration!) / 60
  44. let seconds: Int = Int(round(asset.duration!)) % 60
  45. videoDurationLabel.text = String(format: "\(minutes):%02d", seconds)
  46. }
  47. }
  48. }
  49. override var isSelected: Bool {
  50. didSet {
  51. self.videoInfoView.backgroundColor = UIColor(white: 0.0, alpha: 0.7)
  52. let videoDurationLabel = self.videoInfoView.viewWithTag(-1) as! UILabel
  53. // videoDurationLabel.isHidden = super.isSelected
  54. if super.isSelected {
  55. videoDurationLabel.frame = CGRect(x: 0, y: 0, width: videoInfoView.bounds.width - 27, height: videoInfoView.bounds.height)
  56. } else {
  57. videoDurationLabel.frame = CGRect(x: 0, y: 0, width: videoInfoView.bounds.width - 7, height: videoInfoView.bounds.height)
  58. }
  59. }
  60. }
  61. fileprivate lazy var videoInfoView: UIView = {
  62. let videoInfoView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 0))
  63. let videoImageView = UIImageView(image: DKImageResource.videoCameraIcon())
  64. videoInfoView.addSubview(videoImageView)
  65. videoImageView.center = CGPoint(x: videoImageView.bounds.width / 2 + 7, y: videoInfoView.bounds.height / 2)
  66. videoImageView.autoresizingMask = [.flexibleBottomMargin, .flexibleTopMargin]
  67. let videoDurationLabel = UILabel()
  68. videoDurationLabel.tag = -1
  69. videoDurationLabel.textAlignment = .right
  70. videoDurationLabel.font = UIFont.systemFont(ofSize: 12)
  71. videoDurationLabel.textColor = UIColor.white
  72. videoInfoView.addSubview(videoDurationLabel)
  73. videoDurationLabel.frame = CGRect(x: 0, y: 0, width: videoInfoView.bounds.width - 7, height: videoInfoView.bounds.height)
  74. videoDurationLabel.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  75. return videoInfoView
  76. }()
  77. }