mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
19cd9d13c5
Created a generic PagedDatabaseObserver (common logic for conversation & gallery paged database queries and observation) Updated the MediaGallery to use the PagedDatabaseObserver Split the interaction and thread data queries for the conversationVC
77 lines
2.8 KiB
Swift
77 lines
2.8 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import UIKit
|
|
import SessionMessagingKit
|
|
|
|
final class MediaPlaceholderView: UIView {
|
|
private static let iconSize: CGFloat = 24
|
|
private static let iconImageViewSize: CGFloat = 40
|
|
|
|
// MARK: - Lifecycle
|
|
|
|
init(cellViewModel: MessageCell.ViewModel, textColor: UIColor) {
|
|
super.init(frame: CGRect.zero)
|
|
|
|
setUpViewHierarchy(cellViewModel: cellViewModel, textColor: textColor)
|
|
}
|
|
|
|
override init(frame: CGRect) {
|
|
preconditionFailure("Use init(viewItem:textColor:) instead.")
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
preconditionFailure("Use init(viewItem:textColor:) instead.")
|
|
}
|
|
|
|
private func setUpViewHierarchy(
|
|
cellViewModel: MessageCell.ViewModel,
|
|
textColor: UIColor
|
|
) {
|
|
let (iconName, attachmentDescription): (String, String) = {
|
|
guard
|
|
cellViewModel.variant == .standardIncoming,
|
|
let attachment: Attachment = cellViewModel.attachments?.first
|
|
else {
|
|
return ("actionsheet_document_black", "file") // Should never occur
|
|
}
|
|
|
|
if attachment.isAudio { return ("attachment_audio", "audio") }
|
|
if attachment.isImage || attachment.isVideo { return ("actionsheet_camera_roll_black", "media") }
|
|
|
|
return ("actionsheet_document_black", "file")
|
|
}()
|
|
|
|
// Image view
|
|
let imageView = UIImageView(
|
|
image: UIImage(named: iconName)?
|
|
.withRenderingMode(.alwaysTemplate)
|
|
.resizedImage(
|
|
to: CGSize(
|
|
width: MediaPlaceholderView.iconSize,
|
|
height: MediaPlaceholderView.iconSize
|
|
)
|
|
)
|
|
)
|
|
imageView.tintColor = textColor
|
|
imageView.contentMode = .center
|
|
imageView.set(.width, to: MediaPlaceholderView.iconImageViewSize)
|
|
imageView.set(.height, to: MediaPlaceholderView.iconImageViewSize)
|
|
|
|
// Body label
|
|
let titleLabel = UILabel()
|
|
titleLabel.lineBreakMode = .byTruncatingTail
|
|
titleLabel.text = "Tap to download \(attachmentDescription)"
|
|
titleLabel.textColor = textColor
|
|
titleLabel.font = .systemFont(ofSize: Values.mediumFontSize)
|
|
|
|
// Stack view
|
|
let stackView = UIStackView(arrangedSubviews: [ imageView, titleLabel ])
|
|
stackView.axis = .horizontal
|
|
stackView.alignment = .center
|
|
stackView.isLayoutMarginsRelativeArrangement = true
|
|
stackView.layoutMargins = UIEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 12)
|
|
addSubview(stackView)
|
|
stackView.pin(to: self, withInset: Values.smallSpacing)
|
|
}
|
|
}
|