2 // BookDescriptionView.swift
5 // Created by Pawel Dabrowski on 18/06/2018.
6 // Copyright © 2018 Fundacja Nowoczesna Polska. All rights reserved.
11 class BookDescriptionView: DesignableXibView {
13 @IBOutlet weak var authorLabel: UILabel!
14 @IBOutlet weak var titleLabel: UILabel!
16 @IBOutlet weak var epochTitleLabel: UILabel!
17 @IBOutlet weak var kindTitleLabel: UILabel!
18 @IBOutlet weak var genreTitleLabel: UILabel!
20 @IBOutlet weak var epochLabel: UILabel!
21 @IBOutlet weak var kindLabel: UILabel!
22 @IBOutlet weak var genreLabel: UILabel!
24 @IBOutlet weak var lineView: UIView!
26 @IBOutlet weak var descFirstImageView: UIImageView!
27 @IBOutlet weak var descFirstLabel: UILabel!
28 @IBOutlet weak var descSecondImageView: UIImageView!
29 @IBOutlet weak var descSecondLabel: UILabel!
31 @IBOutlet weak var epochTopConstraint: NSLayoutConstraint!
32 @IBOutlet weak var titleLabelTrailingConstraint: NSLayoutConstraint!
34 @IBOutlet weak var trashButton: UIButton!
36 let orangeTextColor = UIColor(red: 255.0/255.0, green: 165/255.0, blue: 0, alpha: 1.0)
37 let whiteTextColor = UIColor.white
39 override func awakeFromNib() {
41 epochTitleLabel.text = "book_epoch".localized.uppercased()
42 kindTitleLabel.text = "book_kind".localized.uppercased()
43 genreTitleLabel.text = "book_genre".localized.uppercased()
44 descFirstImageView.tintColor = lineView.backgroundColor
45 descSecondImageView.tintColor = lineView.backgroundColor
46 descFirstImageView.image = #imageLiteral(resourceName: "icon_glasses-mid")
47 descSecondImageView.image = #imageLiteral(resourceName: "icon_speaker-mid")
48 setTrashButtonHidden(isHidden: true)
51 func setDescViewsVisibility(hidden: Bool){
52 descFirstImageView.isHidden = hidden
53 descFirstLabel.isHidden = hidden
54 descSecondImageView.isHidden = hidden
55 descSecondLabel.isHidden = hidden
57 epochTopConstraint.constant = hidden ? 10 : 30
60 func setup(bookModel: BookModel, isPremium: Bool = false){
61 setDescViewsVisibility(hidden: false)
63 descSecondImageView.isHidden = !bookModel.has_audio
64 descSecondLabel.isHidden = !bookModel.has_audio
67 authorLabel.textColor = whiteTextColor
68 epochTitleLabel.textColor = whiteTextColor
69 kindTitleLabel.textColor = whiteTextColor
70 genreTitleLabel.textColor = whiteTextColor
72 descFirstImageView.tintColor = whiteTextColor
73 descFirstLabel.textColor = whiteTextColor
74 descSecondImageView.tintColor = whiteTextColor
75 descSecondLabel.textColor = whiteTextColor
77 lineView.backgroundColor = whiteTextColor
79 titleLabel.textColor = orangeTextColor
80 epochLabel.textColor = orangeTextColor
81 kindLabel.textColor = orangeTextColor
82 genreLabel.textColor = orangeTextColor
85 authorLabel.text = bookModel.author
86 titleLabel.text = bookModel.title
87 epochLabel.text = bookModel.epoch
88 kindLabel.text = bookModel.kind
89 genreLabel.text = bookModel.genre
92 func setup(bookDetailsModel: BookDetailsModel){
93 setDescViewsVisibility(hidden: false)
95 authorLabel.text = bookDetailsModel.getAuthor()
96 titleLabel.text = bookDetailsModel.title
97 epochLabel.text = bookDetailsModel.getEpochs()
98 kindLabel.text = bookDetailsModel.getKinds()
99 genreLabel.text = bookDetailsModel.getGenres()
101 if bookDetailsModel.totalChapters > 0 && bookDetailsModel.currentChapter <= bookDetailsModel.totalChapters{
102 let progress = Double(bookDetailsModel.currentChapter)/Double(bookDetailsModel.totalChapters) * 100.0
103 descFirstLabel.text = String(format: "reading_progress".localized, progress).uppercased()
106 descFirstLabel.text = ""
109 descSecondImageView.isHidden = bookDetailsModel.audio_length.count == 0
110 descSecondLabel.isHidden = bookDetailsModel.audio_length.count == 0
113 if bookDetailsModel.totalAudioChapters > 0 && bookDetailsModel.currentAudioChapter < bookDetailsModel.totalAudioChapters{
114 let progress = Double(bookDetailsModel.currentAudioChapter + 1)/Double(bookDetailsModel.totalAudioChapters) * 100.0
115 descSecondLabel.text = String(format: "listening_progress".localized, progress).uppercased()
118 descSecondLabel.text = ""
121 setTrashButtonHidden(isHidden: false)
124 func setTrashButtonHidden(isHidden: Bool){
125 trashButton.isHidden = isHidden
126 titleLabelTrailingConstraint.constant = isHidden ? 0 : 30