You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
188 lines
4.7 KiB
188 lines
4.7 KiB
//
|
|
// GmeContactsViewController.swift
|
|
// GMERemittance
|
|
//
|
|
// Created by gme_2 on 25/08/2018.
|
|
//Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import Localize_Swift
|
|
|
|
class GmeContactsViewController: UIViewController {
|
|
// MARK: IBOutlets
|
|
@IBOutlet weak var tableview: UITableView!
|
|
var presenter: GmeContactsModuleInterface?
|
|
var contacts: [GmeContacts] = [] {
|
|
didSet {
|
|
self.tableview.reloadData()
|
|
}
|
|
}
|
|
|
|
var model: [Branch]? {
|
|
didSet {
|
|
guard let model = model else { return }
|
|
|
|
contacts = model.map {
|
|
let branch = GmeContacts()
|
|
branch.title = $0.agentName
|
|
branch.address = $0.agentAddress
|
|
branch.contactNumber = [$0.agentPhone1] as? [String]
|
|
return branch
|
|
}
|
|
}
|
|
}
|
|
// MARK: Properties
|
|
|
|
// MARK: VC's Life cycle
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
self.setup()
|
|
presenter?.fetchBranch()
|
|
}
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
self.navigationItem.title = "branch_text".localized()
|
|
|
|
setupNormalNavigation()
|
|
|
|
if self.presentingViewController == nil {
|
|
self.navigationItem.leftBarButtonItem = nil
|
|
}
|
|
}
|
|
|
|
// MARK: IBActions
|
|
@IBAction func touchClose(_ sender: UIBarButtonItem) {
|
|
self.dismiss(animated: true, completion: nil)
|
|
}
|
|
|
|
// MARK: Other Functions
|
|
|
|
private func setup() {
|
|
self.tableview.dataSource = self
|
|
self.tableview.delegate = self
|
|
|
|
NotificationCenter.default.addObserver(
|
|
self,
|
|
selector: #selector(setupTabItem),
|
|
name: NSNotification.Name(LCLLanguageChangeNotification),
|
|
object: nil
|
|
)
|
|
}
|
|
|
|
struct StringConstants {
|
|
|
|
}
|
|
|
|
private func call(number: String) {
|
|
let number = number.removeWhitespacesInBetween()
|
|
UIApplication.tryURL(url: "tel://\(number)")
|
|
}
|
|
|
|
override func setupTabItem() {
|
|
let image = UIImage.init(named: "ic-agent")
|
|
self.tabBarItem = UITabBarItem(title: "branch_text".localized(), image: image, selectedImage: nil)
|
|
|
|
self.tabBarItem.titlePositionAdjustment = UIOffset(
|
|
horizontal: 0,
|
|
vertical: UI_USER_INTERFACE_IDIOM() == .pad ? 2 : -6
|
|
)
|
|
}
|
|
}
|
|
|
|
// MARK: GmeContactsViewInterface
|
|
extension GmeContactsViewController: GmeContactsViewInterface {
|
|
func setBranchModel(with model: [Branch]?) {
|
|
self.model = model
|
|
}
|
|
|
|
func setBranchesError(with error: Error) {
|
|
// alertWithOk(message: error.localizedDescription)
|
|
}
|
|
|
|
func startLoading() {
|
|
showProgressHud()
|
|
}
|
|
|
|
func endLoading() {
|
|
hideProgressHud()
|
|
}
|
|
}
|
|
|
|
extension GmeContactsViewController {
|
|
func viperSetup() {
|
|
let service = GmeContactsService()
|
|
let interactor = GmeContactsInteractor(service: service, model: nil)
|
|
let presenter = GmeContactsPresenter()
|
|
let wireframe = GmeContactsWireframe()
|
|
|
|
self.presenter = presenter
|
|
|
|
interactor.output = presenter
|
|
presenter.interactor = interactor
|
|
presenter.wireframe = wireframe
|
|
presenter.view = self
|
|
wireframe.view = self
|
|
}
|
|
}
|
|
|
|
extension GmeContactsViewController: UITableViewDelegate {
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
return UITableView.automaticDimension
|
|
}
|
|
}
|
|
|
|
extension GmeContactsViewController: UITableViewDataSource {
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
return contacts.count
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
guard let cell = tableView.dequeueReusableCell(
|
|
withIdentifier: "GmeContactsTableViewCell"
|
|
) as? GmeContactsTableViewCell else {
|
|
return UITableViewCell()
|
|
}
|
|
cell.contact = self.contacts.elementAt(index: indexPath.row)
|
|
cell.delegate = self
|
|
cell.index = indexPath.row
|
|
cell.setup()
|
|
return cell
|
|
}
|
|
}
|
|
|
|
extension GmeContactsViewController: GmeContactCallDelegate {
|
|
func call(index: Int?) {
|
|
guard let index = index else {return}
|
|
if let contact = self.contacts.elementAt(index: index) {
|
|
let numbers = contact.contactNumber
|
|
|
|
let alert = UIAlertController(
|
|
title:nil,
|
|
message:"help_you_text".localized(),
|
|
preferredStyle: .actionSheet
|
|
)
|
|
|
|
numbers?.forEach({ number in
|
|
let action = UIAlertAction(
|
|
title: "\(number)",
|
|
style: UIAlertAction.Style.default,
|
|
handler: { _ in
|
|
self.call(number: number)
|
|
})
|
|
alert.addAction(action)
|
|
})
|
|
|
|
alert.view.tintColor = UIColor.darkGray
|
|
|
|
alert.addAction(
|
|
UIAlertAction(title: "cancel_text".localized(), style: UIAlertAction.Style.cancel, handler: nil)
|
|
)
|
|
present(alert, animated: true, completion: nil)
|
|
}
|
|
|
|
}
|
|
}
|