// // HotLineViewController.swift // GME Remit // // Created by InKwon Devik Kim on 23/05/2019. //Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved. // import UIKit import PanModal class HotLineViewController: UIViewController { // MARK: Properties var presenter: HotLineModuleInterface? let CellHeight: CGFloat = 90 // MARK: Computed Properties var hotLines: [HotLine]? { didSet { tableView.reloadData() } } // MARK: IBOutlets @IBOutlet weak var tableView: UITableView! @IBOutlet weak var informationLabel: UILabel! // MARK: VC's Life cycle override func viewDidLoad() { super.viewDidLoad() setup() } // MARK: IBActions @IBAction func touchHeadOfficeButton(_ sender: UIButton) { if let url = URL(string: "tel://1588-6864"), UIApplication.shared.canOpenURL(url) { if #available(iOS 10, *) { UIApplication.shared.open(url) } else { UIApplication.shared.openURL(url) } } } } // MARK: HotLineViewInterface extension HotLineViewController: HotLineViewInterface { func setHotLine(with model: [HotLine]?) { hotLines = model } func setError(with error: Error) { alert(type: .error, message: error.localizedDescription) } } // MARK: Other Functions extension HotLineViewController { private func setup() { // all setup should be done here tableView.dataSource = self informationLabel.text = "help_you_text".localized() presenter?.fetchHotLines() } } // MARK: - UITableViewDataSource extension HotLineViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return hotLines?.count ?? 0 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { guard let cell = tableView.dequeueReusableCell(withIdentifier: "HotLineCell") as? HotLineCell else { return UITableViewCell() } cell.setModel(hotLines?[indexPath.row]) return cell } } // MARK: - PanModalPresentable extension HotLineViewController: PanModalPresentable { var panScrollable: UIScrollView? { return self.tableView } var shortFormHeight: PanModalHeight { return .contentHeight(CellHeight + 100) } var longFormHeight: PanModalHeight { return .maxHeight } }