| 1 | // |
| 2 | // ContinueWatchingCell.swift |
| 3 | // JomloCollectionView Example |
| 4 | // |
| 5 | // Created by Seto Elkahfi on 2026-01-27. |
| 6 | // Copyright © 2026 Seto Elkahfi. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | import JomloCollectionView |
| 10 | import UIKit |
| 11 | |
| 12 | final class ContinueWatchingCell: UICollectionViewCell, JomloSelfConfiguringCell { |
| 13 | |
| 14 | private let thumbnailView: UIView = { |
| 15 | let view = UIView() |
| 16 | view.layer.cornerRadius = 8 |
| 17 | view.clipsToBounds = true |
| 18 | return view |
| 19 | }() |
| 20 | |
| 21 | private let titleLabel: UILabel = { |
| 22 | let label = UILabel() |
| 23 | label.font = .preferredFont(forTextStyle: .subheadline) |
| 24 | label.adjustsFontForContentSizeCategory = true |
| 25 | label.textColor = .label |
| 26 | return label |
| 27 | }() |
| 28 | |
| 29 | private let episodeLabel: UILabel = { |
| 30 | let label = UILabel() |
| 31 | label.font = .preferredFont(forTextStyle: .caption1) |
| 32 | label.adjustsFontForContentSizeCategory = true |
| 33 | label.textColor = .secondaryLabel |
| 34 | return label |
| 35 | }() |
| 36 | |
| 37 | private let progressView: UIProgressView = { |
| 38 | let progress = UIProgressView(progressViewStyle: .default) |
| 39 | progress.trackTintColor = .darkGray |
| 40 | progress.progressTintColor = .systemRed |
| 41 | return progress |
| 42 | }() |
| 43 | |
| 44 | override init(frame: CGRect) { |
| 45 | super.init(frame: frame) |
| 46 | setupViews() |
| 47 | } |
| 48 | |
| 49 | required init?(coder: NSCoder) { |
| 50 | fatalError("init(coder:) not supported") |
| 51 | } |
| 52 | |
| 53 | func configure(with item: ContinueWatchingItem) { |
| 54 | titleLabel.text = item.title |
| 55 | episodeLabel.text = item.episodeInfo |
| 56 | progressView.progress = item.progress |
| 57 | thumbnailView.backgroundColor = UIColor(hex: item.colorHex) ?? .gray |
| 58 | } |
| 59 | |
| 60 | private func setupViews() { |
| 61 | let textStack = UIStackView(arrangedSubviews: [titleLabel, episodeLabel]) |
| 62 | textStack.axis = .vertical |
| 63 | textStack.spacing = 2 |
| 64 | |
| 65 | let mainStack = UIStackView(arrangedSubviews: [thumbnailView, textStack, progressView]) |
| 66 | mainStack.axis = .vertical |
| 67 | mainStack.spacing = 6 |
| 68 | mainStack.translatesAutoresizingMaskIntoConstraints = false |
| 69 | |
| 70 | contentView.addSubview(mainStack) |
| 71 | NSLayoutConstraint.activate([ |
| 72 | mainStack.topAnchor.constraint(equalTo: contentView.topAnchor), |
| 73 | mainStack.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), |
| 74 | mainStack.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), |
| 75 | mainStack.bottomAnchor.constraint(lessThanOrEqualTo: contentView.bottomAnchor), |
| 76 | thumbnailView.heightAnchor.constraint( |
| 77 | equalTo: thumbnailView.widthAnchor, multiplier: 0.56), |
| 78 | ]) |
| 79 | |
| 80 | isAccessibilityElement = true |
| 81 | accessibilityTraits = .button |
| 82 | } |
| 83 | |
| 84 | override var accessibilityLabel: String? { |
| 85 | get { "\(titleLabel.text ?? ""), \(episodeLabel.text ?? "")" } |
| 86 | set {} |
| 87 | } |
| 88 | } |