pEpForiOS/UI/EmailDisplay/MessageAttachmentsCell.swift
author Dirk Zimmermann <dirk@pep-project.org>
Thu, 01 Feb 2018 11:29:01 +0100
changeset 3866 b5901734830a
parent 3511 574344f14a5c
child 4216 8bb2fe2b24bd
permissions -rw-r--r--
IOS-915 logging to pinpoint the problem
     1 //
     2 //  MessageAttachmentsCell.swift
     3 //  pEpForiOS
     4 //
     5 //  Created by Dirk Zimmermann on 04.04.17.
     6 //  Copyright © 2017 p≡p Security S.A. All rights reserved.
     7 //
     8 
     9 import Foundation
    10 
    11 import MessageModel
    12 
    13 class MessageAttachmentsCell: MessageCell {
    14     @IBOutlet weak var attachmentsImageView: AttachmentsView!
    15 
    16     var attachmentsViewHelper = AttachmentsViewHelper()
    17     var lastMessage: Message?
    18 
    19     override func awakeFromNib() {
    20         attachmentsViewHelper.attachmentsImageView = attachmentsImageView
    21         attachmentsViewHelper.delegate = self
    22         attachmentsImageView.delegate = self
    23         selectionStyle = .none
    24     }
    25 
    26     public override func updateCell(model: ComposeFieldModel, message: Message,
    27                                     indexPath: IndexPath) {
    28         super.updateCell(model: model, message: message, indexPath: indexPath)
    29         guard message.underAttack == false else {
    30             return
    31         }
    32         if let m = lastMessage, m == message {
    33             // Avoid processing the same message over and over again, unless
    34             // the attachment count changes, which is considered by `==`.
    35             return
    36         }
    37         attachmentsViewHelper.message = message
    38         lastMessage = message
    39 
    40         // Work around auto-layout problems
    41         if !message.viewableAttachments().isEmpty {
    42             let cZeroHeight = contentView.heightAnchor.constraint(equalToConstant: 0)
    43             let cMinimumHeight = contentView.heightAnchor.constraint(greaterThanOrEqualToConstant: 44)
    44             cZeroHeight.isActive = false
    45             cMinimumHeight.isActive = true
    46         }
    47     }
    48 }
    49 
    50 // MARK: - AttachmentsViewDelegate
    51 
    52 extension MessageAttachmentsCell: AttachmentsViewDelegate {
    53     func didTap(attachment: Attachment, location: CGPoint, inView: UIView?) {
    54         (delegate as? MessageAttachmentDelegate)?.didTap(cell: self, attachment: attachment,
    55                                                          location: location, inView: inView)
    56     }
    57 }
    58 
    59 // MARK: - AttachmentsViewHelperDelegate
    60 
    61 extension MessageAttachmentsCell: AttachmentsViewHelperDelegate {
    62     func didCreate(attachmentsView: UIView?, message: Message) {
    63         (delegate as? MessageContentCellDelegate)?.didUpdate(cell: self, height: 0)
    64     }
    65 }