aboutsummaryrefslogtreecommitdiff
path: root/foray/ForayDetailViewController.swift
blob: 8d0b9eca37073d93e1553e75a32bd44d5ff84ba1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
//  ForayDetailViewController.swift
//  foray
//
//  Created by Nicholas Tay on 16/3/2022.
//

import UIKit

class ForayDetailViewController: UIViewController {
    
    let container: UIView = UIView()
    
    let nameLabel: UILabel = {
        let l = UILabel()
        l.font = UIFont.preferredFont(forTextStyle: .largeTitle)
        l.adjustsFontForContentSizeCategory = true
        l.numberOfLines = 3
        l.textAlignment = .center
        return l
    }()
    
    let itemImageView: UIImageView = {
        let iv = UIImageView()
        iv.contentMode = .scaleAspectFit
        return iv
    }()
    
    let descLabel: UILabel = {
        let l = UILabel()
        l.font = UIFont.preferredFont(forTextStyle: .body)
        l.adjustsFontForContentSizeCategory = true
        l.numberOfLines = 10
        return l
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.title = "Details"
        self.view.backgroundColor = .systemBackground
        
        initialiseViews()
    }
    
    private func initialiseViews() {
        self.view.addSubview(container)
        
        container.addSubview(nameLabel)
        container.addSubview(itemImageView)
        container.addSubview(descLabel)
        
        setupConstraints()
    }
    
    private func setupConstraints() {
        container.snp.makeConstraints { (make) in
            make.edges.equalTo(self.view.snp.margins)
        }
        
        nameLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().inset(8)
            make.leading.trailing.equalToSuperview().inset(8)
        }
        itemImageView.snp.makeConstraints { (make) in
            make.top.equalTo(nameLabel.snp.bottom).offset(32)
            make.leading.trailing.equalToSuperview()
            make.height.equalTo(150)
        }
        descLabel.snp.makeConstraints { (make) in
            make.top.equalTo(itemImageView.snp.bottom).offset(32)
            make.leading.trailing.equalToSuperview()
        }
    }
    
    public func setSelectedItem(selectedItem: PenguinItem) {
        nameLabel.text = selectedItem.name
        itemImageView.image = UIImage(named: selectedItem.id)
        
        descLabel.text = "Type: "
        switch selectedItem.type {
        case .item:
            descLabel.text! += "Item"
        case .quest:
            descLabel.text! += "Quest"
            itemImageView.image = UIImage(named: "spy")
        }
        
        descLabel.text! += "\nID: " + selectedItem.id
        
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyy-MM-dd"
        descLabel.text! += "\nReleased: " + dateFormatter.string(from: selectedItem.releaseDate)
    }

}