|
@@ -4,13 +4,14 @@ import DcCore
|
|
|
class FileView: UIView {
|
|
|
|
|
|
static let badgeSize: CGFloat = 54
|
|
|
- let defaultHeight: CGFloat = 100
|
|
|
- let defaultWidth: CGFloat = 250
|
|
|
+ static let defaultHeight: CGFloat = 78
|
|
|
+ static let defaultWidth: CGFloat = 250
|
|
|
|
|
|
private lazy var previewImageView: UIImageView = {
|
|
|
let imageView = UIImageView()
|
|
|
imageView.contentMode = .scaleAspectFill
|
|
|
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ imageView.isHidden = true
|
|
|
return imageView
|
|
|
}()
|
|
|
|
|
@@ -22,6 +23,9 @@ class FileView: UIView {
|
|
|
|
|
|
private lazy var subtitleView: MessageLabel = {
|
|
|
let label = MessageLabel()
|
|
|
+ label.numberOfLines = 1
|
|
|
+ label.adjustsFontSizeToFitWidth = false
|
|
|
+ label.lineBreakMode = .byTruncatingTail
|
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
|
return label
|
|
|
}()
|
|
@@ -31,78 +35,53 @@ class FileView: UIView {
|
|
|
let badge: InitialsBadge = InitialsBadge(image: defaultImage, size: FileView.badgeSize)
|
|
|
badge.setColor(DcColors.middleGray)
|
|
|
badge.isAccessibilityElement = false
|
|
|
+ badge.isHidden = false
|
|
|
return badge
|
|
|
}()
|
|
|
|
|
|
- private lazy var stackView: UIStackView = {
|
|
|
+ private lazy var verticalStackView: UIStackView = {
|
|
|
let stackView = UIStackView(arrangedSubviews: [titleView, subtitleView])
|
|
|
stackView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
stackView.axis = .vertical
|
|
|
stackView.alignment = .leading
|
|
|
+ stackView.isLayoutMarginsRelativeArrangement = true
|
|
|
+ stackView.directionalLayoutMargins = NSDirectionalEdgeInsets(top: FileMessageCell.insetHorizontalSmall,
|
|
|
+ leading: FileMessageCell.insetHorizontalSmall,
|
|
|
+ bottom: FileMessageCell.insetHorizontalSmall,
|
|
|
+ trailing: FileMessageCell.insetHorizontalSmall)
|
|
|
return stackView
|
|
|
}()
|
|
|
|
|
|
init() {
|
|
|
- super.init(frame: CGRect(x: 0, y: 0, width: defaultWidth, height: defaultHeight))
|
|
|
+ super.init(frame: .zero)
|
|
|
translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ addSubview(fileBadgeView)
|
|
|
+ addSubview(verticalStackView)
|
|
|
}
|
|
|
|
|
|
func configureFor(mediaItem: MediaItem) {
|
|
|
removeConstraints(self.constraints)
|
|
|
previewImageView.removeFromSuperview()
|
|
|
- //titleView.removeFromSuperview()
|
|
|
- //subtitleView.removeFromSuperview()
|
|
|
- fileBadgeView.removeFromSuperview()
|
|
|
- setupSubviews(mediaItem: mediaItem)
|
|
|
- }
|
|
|
-
|
|
|
- private func setupSubviews(mediaItem: MediaItem) {
|
|
|
if let previewImage = mediaItem.image {
|
|
|
previewImageView.image = previewImage
|
|
|
addSubview(previewImageView)
|
|
|
- addSubview(stackView)
|
|
|
- //addSubview(titleView)
|
|
|
- //addSubview(subtitleView)
|
|
|
addConstraints([
|
|
|
previewImageView.constraintAlignTopTo(self),
|
|
|
previewImageView.constraintAlignLeadingTo(self),
|
|
|
previewImageView.constraintAlignTrailingTo(self),
|
|
|
- /*titleView.constraintAlignTopTo(previewImageView),
|
|
|
- titleView.constraintAlignLeadingTo(self),
|
|
|
- titleView.constraintAlignTrailingTo(self),
|
|
|
- subtitleView.constraintAlignLeadingTo(self),
|
|
|
- subtitleView.constraintAlignTrailingTo(self),
|
|
|
- subtitleView.constraintAlignTopTo(titleView)*/
|
|
|
])
|
|
|
} else {
|
|
|
- fileBadgeView.setImage(mediaItem.placeholderImage)
|
|
|
-
|
|
|
-
|
|
|
- addSubview(fileBadgeView)
|
|
|
addConstraints([
|
|
|
- fileBadgeView.constraintAlignLeadingTo(self, paddingLeading: FileMessageCell.insetHorizontalSmall),
|
|
|
+ fileBadgeView.constraintAlignLeadingTo(self),
|
|
|
fileBadgeView.constraintWidthTo(FileView.badgeSize),
|
|
|
fileBadgeView.constraintHeightTo(FileView.badgeSize),
|
|
|
fileBadgeView.constraintCenterYTo(self)
|
|
|
])
|
|
|
- addSubview(stackView)
|
|
|
addConstraints([
|
|
|
- stackView.constraintCenterYTo(self),
|
|
|
- stackView.constraintToTrailingOf(fileBadgeView, paddingLeading: FileMessageCell.insetHorizontalSmall),
|
|
|
- stackView.constraintAlignTrailingTo(self, paddingTrailing: FileMessageCell.insetHorizontalSmall)
|
|
|
+ verticalStackView.constraintCenterYTo(self),
|
|
|
+ verticalStackView.constraintToTrailingOf(fileBadgeView),
|
|
|
+ verticalStackView.constraintAlignTrailingTo(self)
|
|
|
])
|
|
|
- /*addSubview(titleView)
|
|
|
- addConstraints([
|
|
|
- titleView.constraintAlignTopTo(self, paddingTop: FileMessageCell.insetTop),
|
|
|
- titleView.constraintToTrailingOf(fileBadgeView, paddingLeading: FileMessageCell.insetHorizontalSmall),
|
|
|
- titleView.constraintAlignTrailingTo(self, paddingTrailing: FileMessageCell.insetHorizontalSmall),
|
|
|
- ])
|
|
|
- addSubview(subtitleView)
|
|
|
- addConstraints([
|
|
|
- subtitleView.constraintToTrailingOf(fileBadgeView, paddingLeading: FileMessageCell.insetHorizontalSmall),
|
|
|
- subtitleView.constraintAlignTrailingTo(self, paddingTrailing: FileMessageCell.insetHorizontalSmall),
|
|
|
- subtitleView.constraintToBottomOf(titleView)
|
|
|
- ])*/
|
|
|
}
|
|
|
if let title = mediaItem.text?[MediaItemConstants.mediaTitle] {
|
|
|
titleView.attributedText = title
|