pEpForiOS/UI/EmailDisplay/EmailListViewCell.swift
author buff <andreas@pep-project.org>
Mon, 04 Dec 2017 17:39:36 +0100
changeset 3521 2628538df4d5
parent 3368 e79ab6166c5b
child 3522 9326deae631d
permissions -rw-r--r--
IOS-827 stops showing accessory disclosure indicator in draft folder
dirk@31
     1
//
dirk@31
     2
//  EmailListViewCell.swift
dirk@31
     3
//  pEpForiOS
dirk@31
     4
//
dirk@31
     5
//  Created by Dirk Zimmermann on 16/04/16.
dirk@31
     6
//  Copyright © 2016 p≡p Security S.A. All rights reserved.
dirk@31
     7
//
dirk@31
     8
dirk@31
     9
import UIKit
igor@1260
    10
import MessageModel
xavier@3368
    11
import SwipeCellKit
dirk@31
    12
xavier@3368
    13
class EmailListViewCell: SwipeTableViewCell {
andreas@3151
    14
    static let storyboardId = "EmailListViewCell"
andreas@3151
    15
    static var flaggedImage: UIImage? = nil
andreas@3151
    16
    static var emptyContactImage = UIImage.init(named: "empty-avatar")
dirk@3112
    17
dirk@31
    18
    @IBOutlet weak var senderLabel: UILabel!
dirk@31
    19
    @IBOutlet weak var subjectLabel: UILabel!
dirk@31
    20
    @IBOutlet weak var summaryLabel: UILabel!
dirk@32
    21
    @IBOutlet weak var dateLabel: UILabel!
dirk@1605
    22
dirk@1605
    23
    /**
dirk@1931
    24
     Used for \Flagged, contrary to the name.
dirk@1605
    25
     */
dirk@1931
    26
    @IBOutlet weak var flaggedImageView: UIImageView!
dirk@1605
    27
igor@1300
    28
    @IBOutlet weak var ratingImage: UIImageView!
yves@1364
    29
    @IBOutlet weak var attachmentIcon: UIImageView!
dirk@1917
    30
    @IBOutlet weak var contactImageView: UIImageView!
dirk@1917
    31
andreas@3521
    32
    @IBOutlet weak var accessoryDisclosureIndicator: UIImageView!
andreas@3151
    33
    var isFlagged:Bool = false {
andreas@3151
    34
        didSet {
andreas@3151
    35
            if isFlagged {
andreas@3151
    36
                setFlagged()
andreas@3151
    37
            } else {
andreas@3151
    38
                unsetFlagged()
andreas@3151
    39
            }
andreas@3151
    40
        }
andreas@3151
    41
    }
andreas@3151
    42
andreas@3151
    43
    var isSeen:Bool = false {
andreas@3151
    44
        didSet {
andreas@3151
    45
            if isSeen {
andreas@3151
    46
                setSeen()
andreas@3151
    47
            } else {
andreas@3151
    48
                unsetSeen()
andreas@3151
    49
            }
andreas@3151
    50
        }
andreas@3151
    51
    }
andreas@3151
    52
andreas@3151
    53
    var hasAttachment:Bool = false {
andreas@3151
    54
        didSet {
andreas@3151
    55
            if hasAttachment {
andreas@3151
    56
                attachmentIcon.isHidden = false
andreas@3151
    57
            } else {
andreas@3151
    58
                attachmentIcon.isHidden = true
andreas@3151
    59
            }
andreas@3151
    60
        }
andreas@3151
    61
    }
andreas@3151
    62
andreas@3151
    63
    func setPepRatingImage(image: UIImage?) {
andreas@3151
    64
        guard image != nil else {
andreas@3151
    65
            return
andreas@3151
    66
        }
andreas@3151
    67
        self.ratingImage.image = image
andreas@3151
    68
        self.ratingImage.isHidden = false
andreas@3151
    69
    }
andreas@3151
    70
andreas@3151
    71
    func setContactImage(image: UIImage?) {
andreas@3151
    72
        guard image != nil else {
andreas@3151
    73
            return
andreas@3151
    74
        }
andreas@3151
    75
        self.contactImageView.image = image
andreas@3151
    76
    }
dirk@1906
    77
ana@614
    78
    override func awakeFromNib() {
ana@614
    79
        super.awakeFromNib()
dirk@2015
    80
        self.contactImageView.layer.cornerRadius = round(contactImageView.bounds.size.width / 2)
dirk@1920
    81
        self.contactImageView.layer.masksToBounds = true
andreas@3151
    82
        resetToDefault()
ana@614
    83
    }
dirk@1542
    84
andreas@3151
    85
    override func prepareForReuse() {
andreas@3151
    86
        resetToDefault()
andreas@3151
    87
    }
andreas@3120
    88
andreas@3151
    89
    private func resetToDefault() {
andreas@3151
    90
        senderLabel.text = nil
andreas@3151
    91
        subjectLabel.text = nil
andreas@3151
    92
        summaryLabel.text = nil
andreas@3151
    93
        dateLabel.text = nil
andreas@3151
    94
        unsetFlagged()
andreas@3151
    95
        unsetSeen()
andreas@3151
    96
        ratingImage.isHidden = true
andreas@3151
    97
        hasAttachment = false
andreas@3151
    98
        contactImageView.image = EmailListViewCell.emptyContactImage
andreas@3151
    99
    }
andreas@3120
   100
andreas@3151
   101
    private func setFlagged() {
andreas@3151
   102
        if EmailListViewCell.flaggedImage == nil {
andreas@3151
   103
            EmailListViewCell.flaggedImage =
andreas@3151
   104
                FlagImages.create(imageSize: flaggedImageView.frame.size).flaggedImage
andreas@3151
   105
        }
andreas@3151
   106
        guard let saveImg = EmailListViewCell.flaggedImage else {
andreas@3151
   107
            return
andreas@3151
   108
        }
andreas@3151
   109
        self.flaggedImageView.isHidden = false
andreas@3151
   110
        self.flaggedImageView.image = saveImg
andreas@3151
   111
    }
dirk@1605
   112
andreas@3151
   113
    private func unsetFlagged() {
andreas@3151
   114
        self.flaggedImageView.isHidden = true
andreas@3151
   115
        self.flaggedImageView.image = nil
andreas@3151
   116
    }
andreas@3151
   117
andreas@3151
   118
    private func setSeen() {
andreas@3151
   119
        if let font = senderLabel.font {
andreas@3151
   120
            let font = UIFont.systemFont(ofSize: font.pointSize)
andreas@3168
   121
            setupLabels(font: font)
igor@1568
   122
        }
andreas@3151
   123
    }
dirk@1931
   124
andreas@3151
   125
    private func unsetSeen() {
dirk@1931
   126
        if let font = senderLabel.font {
andreas@3151
   127
            let font = UIFont.boldSystemFont(ofSize: font.pointSize)
andreas@3168
   128
            setupLabels(font: font)
dirk@1931
   129
        }
dirk@1931
   130
    }
dirk@1931
   131
andreas@3168
   132
    func setupLabels(font: UIFont) {
dirk@1931
   133
        senderLabel.font = font
dirk@1931
   134
        subjectLabel.font = font
dirk@1931
   135
        summaryLabel.font = font
dirk@1933
   136
        dateLabel.font = font
dirk@1542
   137
    }
dirk@784
   138
}