|
@@ -17,6 +17,7 @@ class DocumentGalleryController: UIViewController {
|
|
init(fileMessageIds: [Int]) {
|
|
init(fileMessageIds: [Int]) {
|
|
self.fileMessageIds = fileMessageIds
|
|
self.fileMessageIds = fileMessageIds
|
|
super.init(nibName: nil, bundle: nil)
|
|
super.init(nibName: nil, bundle: nil)
|
|
|
|
+ self.title = String.localized("documents")
|
|
}
|
|
}
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
required init?(coder: NSCoder) {
|
|
@@ -54,93 +55,27 @@ extension DocumentGalleryController: UITableViewDelegate, UITableViewDataSource
|
|
cell.update(msg: msg)
|
|
cell.update(msg: msg)
|
|
return cell
|
|
return cell
|
|
}
|
|
}
|
|
-}
|
|
|
|
-
|
|
|
|
-class FileTableViewCell: UITableViewCell {
|
|
|
|
-
|
|
|
|
- static let reuseIdentifier = "file_table_view_cell"
|
|
|
|
-
|
|
|
|
- private let fileImageView: UIImageView = {
|
|
|
|
- let imageView = UIImageView()
|
|
|
|
- imageView.contentMode = .scaleAspectFit
|
|
|
|
- return imageView
|
|
|
|
- }()
|
|
|
|
-
|
|
|
|
- override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
|
|
- super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
|
|
|
|
- setupSubviews()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- required init?(coder: NSCoder) {
|
|
|
|
- fatalError("init(coder:) has not been implemented")
|
|
|
|
- }
|
|
|
|
|
|
|
|
- override func prepareForReuse() {
|
|
|
|
- fileImageView.image = nil
|
|
|
|
- detailTextLabel?.text = nil
|
|
|
|
- textLabel?.text = nil
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // MARK: - layout
|
|
|
|
- private func setupSubviews() {
|
|
|
|
- guard let textLabel = textLabel, let detailTextLabel = detailTextLabel else { return }
|
|
|
|
-
|
|
|
|
- contentView.addSubview(fileImageView)
|
|
|
|
- fileImageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
- fileImageView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor, constant: 0).isActive = true
|
|
|
|
- fileImageView.heightAnchor.constraint(lessThanOrEqualTo: contentView.heightAnchor, multiplier: 0.9).isActive = true
|
|
|
|
- fileImageView.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor, constant: 0).isActive = true
|
|
|
|
- fileImageView.widthAnchor.constraint(equalToConstant: 50).isActive = true
|
|
|
|
- textLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
- detailTextLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
- textLabel.leadingAnchor.constraint(equalTo: fileImageView.trailingAnchor, constant: 10).isActive = true
|
|
|
|
- textLabel.topAnchor.constraint(equalTo: contentView.layoutMarginsGuide.topAnchor, constant: 0).isActive = true
|
|
|
|
- textLabel.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor, constant: 0).isActive = true
|
|
|
|
- detailTextLabel.leadingAnchor.constraint(equalTo: textLabel.leadingAnchor, constant: 0).isActive = true
|
|
|
|
- detailTextLabel.topAnchor.constraint(equalTo: textLabel.bottomAnchor, constant: 0).isActive = true
|
|
|
|
- detailTextLabel.trailingAnchor.constraint(equalTo: textLabel.trailingAnchor, constant: 0).isActive = true
|
|
|
|
- detailTextLabel.bottomAnchor.constraint(equalTo: contentView.layoutMarginsGuide.bottomAnchor, constant: 0).isActive = true
|
|
|
|
|
|
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
+ let msgId = fileMessageIds[indexPath.row]
|
|
|
|
+ showPreview(msgId: msgId)
|
|
|
|
+ tableView.deselectRow(at: indexPath, animated: false)
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- func update(msg: DcMsg) {
|
|
|
|
- switch msg.kind {
|
|
|
|
- case .fileText(let mediaItem):
|
|
|
|
- if let url = mediaItem.url {
|
|
|
|
- let controller = UIDocumentInteractionController(url: url)
|
|
|
|
- fileImageView.image = controller.icons.first ?? mediaItem.placeholderImage
|
|
|
|
- } else {
|
|
|
|
- fileImageView.image = mediaItem.placeholderImage
|
|
|
|
- }
|
|
|
|
- textLabel?.text = msg.filename
|
|
|
|
- detailTextLabel?.attributedText = mediaItem.text?[MediaItemConstants.mediaSubtitle]
|
|
|
|
- default:
|
|
|
|
- break
|
|
|
|
|
|
+// MARK: - coordinator
|
|
|
|
+extension DocumentGalleryController {
|
|
|
|
+ func showPreview(msgId: Int) {
|
|
|
|
+ guard let index = fileMessageIds.index(of: msgId) else {
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- /*
|
|
|
|
- if let fileUrl = msg.fileURL {
|
|
|
|
- let controller = UIDocumentInteractionController(url: fileUrl)
|
|
|
|
- cell.imageView?.image = controller.icons.first
|
|
|
|
- }
|
|
|
|
- if let fileName = msg.filename {
|
|
|
|
- let messageKind = msg.createFileMessage(text: fileName)
|
|
|
|
- switch messageKind {
|
|
|
|
- case .fileText(let mediaItem):
|
|
|
|
- if let title = mediaItem.text?[MediaItemConstants.mediaTitle] {
|
|
|
|
- cell.textLabel?.attributedText = title
|
|
|
|
- cell.textLabel?.makeBorder(color: .yellow)
|
|
|
|
- }
|
|
|
|
- if let subtitle = mediaItem.text?[MediaItemConstants.mediaSubtitle] {
|
|
|
|
- cell.detailTextLabel?.attributedText = subtitle
|
|
|
|
- cell.detailTextLabel?.makeBorder()
|
|
|
|
- }
|
|
|
|
- default:
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ let mediaUrls = fileMessageIds.compactMap {
|
|
|
|
+ return DcMsg(id: $0).fileURL
|
|
}
|
|
}
|
|
- */
|
|
|
|
|
|
+ let previewController = PreviewController(currentIndex: index, urls: mediaUrls)
|
|
|
|
+ present(previewController, animated: true, completion: nil)
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|