added iOS source code
[wl-app.git] / iOS / WolneLektury / Screens / Common / Views / BookDescriptionView.swift
1 //
2 //  BookDescriptionView.swift
3 //  WolneLektury
4 //
5 //  Created by Pawel Dabrowski on 18/06/2018.
6 //  Copyright © 2018 Fundacja Nowoczesna Polska. All rights reserved.
7 //
8
9 import UIKit
10
11 class BookDescriptionView: DesignableXibView {
12
13     @IBOutlet weak var authorLabel: UILabel!
14     @IBOutlet weak var titleLabel: UILabel!
15     
16     @IBOutlet weak var epochTitleLabel: UILabel!
17     @IBOutlet weak var kindTitleLabel: UILabel!
18     @IBOutlet weak var genreTitleLabel: UILabel!
19     
20     @IBOutlet weak var epochLabel: UILabel!
21     @IBOutlet weak var kindLabel: UILabel!
22     @IBOutlet weak var genreLabel: UILabel!
23     
24     @IBOutlet weak var lineView: UIView!
25     
26     @IBOutlet weak var descFirstImageView: UIImageView!
27     @IBOutlet weak var descFirstLabel: UILabel!
28     @IBOutlet weak var descSecondImageView: UIImageView!
29     @IBOutlet weak var descSecondLabel: UILabel!
30     
31     @IBOutlet weak var epochTopConstraint: NSLayoutConstraint!
32     @IBOutlet weak var titleLabelTrailingConstraint: NSLayoutConstraint!
33     
34     @IBOutlet weak var trashButton: UIButton!
35     
36     let orangeTextColor = UIColor(red: 255.0/255.0, green: 165/255.0, blue: 0, alpha: 1.0)
37     let whiteTextColor = UIColor.white
38     
39     override func awakeFromNib() {
40         super.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)
49     }
50     
51     func setDescViewsVisibility(hidden: Bool){
52         descFirstImageView.isHidden = hidden
53         descFirstLabel.isHidden = hidden
54         descSecondImageView.isHidden = hidden
55         descSecondLabel.isHidden = hidden
56         
57         epochTopConstraint.constant = hidden ? 10 : 30
58     }
59     
60     func setup(bookModel: BookModel, isPremium: Bool = false){
61         setDescViewsVisibility(hidden: false)
62         
63         descSecondImageView.isHidden = !bookModel.has_audio
64         descSecondLabel.isHidden = !bookModel.has_audio
65         if isPremium{
66             
67             authorLabel.textColor = whiteTextColor
68             epochTitleLabel.textColor = whiteTextColor
69             kindTitleLabel.textColor = whiteTextColor
70             genreTitleLabel.textColor = whiteTextColor
71             
72             descFirstImageView.tintColor = whiteTextColor
73             descFirstLabel.textColor = whiteTextColor
74             descSecondImageView.tintColor = whiteTextColor
75             descSecondLabel.textColor = whiteTextColor
76             
77             lineView.backgroundColor = whiteTextColor
78             
79             titleLabel.textColor = orangeTextColor
80             epochLabel.textColor = orangeTextColor
81             kindLabel.textColor = orangeTextColor
82             genreLabel.textColor = orangeTextColor
83         }
84         
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
90     }
91     
92     func setup(bookDetailsModel: BookDetailsModel){
93         setDescViewsVisibility(hidden: false)
94         
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()
100         
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()
104         }
105         else {
106             descFirstLabel.text = ""
107         }
108         
109         descSecondImageView.isHidden = bookDetailsModel.audio_length.count == 0
110         descSecondLabel.isHidden = bookDetailsModel.audio_length.count == 0
111
112         /*
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()
116         }
117         else {
118             descSecondLabel.text = ""
119         }
120         */
121         setTrashButtonHidden(isHidden: false)
122     }
123     
124     func setTrashButtonHidden(isHidden: Bool){
125         trashButton.isHidden = isHidden
126         titleLabelTrailingConstraint.constant = isHidden ? 0 : 30
127     }
128
129 }