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.
 
 
 
 

187 lines
5.9 KiB

//
// ConfirmViewController.swift
// GME Remit
//
// Created by InKwon Devik Kim on 07/05/2019.
// Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
//
import UIKit
protocol ConfirmViewControllerDelegate: class {
func confirm(_ viewController: ConfirmViewController)
func cancel(_ viewController: ConfirmViewController)
}
struct ConfirmViewControllerConfiguration {
var title: String? = "confirm_viewconroller_default_title_text".localized()
var content1: String? = ""
var content2: String? = ""
var multiLineContent: String? = ""
var model: RewardProduct?
var receiveLocation: String = ""
var productType: String = ""
var confirmButtonTitle: String? = "Confirm"
var cancelButtonTitle: String? = "Cancel"
}
class ConfirmViewController: UIViewController {
weak var delegate: ConfirmViewControllerDelegate?
private var configure: ConfirmViewControllerConfiguration?
private var rewardType: RewardProduct? {
didSet {
if rewardType?.rewardType == "Coupon" {
titleLabel.text = configure?.title
content1Label.text = configure?.content1
content2Label.text = configure?.content2
receiveLocationLabel.text = configure?.receiveLocation
multiLineContentLabel.text = configure?.multiLineContent
} else {
self.content1Label.text = self.configure?.content1
self.content2Label.text = self.configure?.content2
receiveLocationLabel.text = "branch_text".localized()
self.multiLineContentLabel.text = self.configure?.multiLineContent
}
}
}
@IBOutlet private weak var titleLabel: UILabel!
@IBOutlet private weak var content1Label: UILabel!
@IBOutlet private weak var content2Label: UILabel!
@IBOutlet weak var receiveLocationLabel: UILabel!
@IBOutlet private weak var multiLineContentLabel: UILabel!
@IBOutlet private weak var mainView: UIView!
@IBOutlet private weak var confirmButton: UIButton!
@IBOutlet private weak var cancelButton: UIButton!
@IBOutlet weak var receiverTitleLabel: UILabel!
@IBOutlet weak var mobileNumberTitleLabel: UILabel!
@IBOutlet weak var transparentView: UIView!
@IBAction private func touchCancel(_ sender: UIButton) {
cancel()
}
@IBAction private func touchConfirm(_ sender: UIButton) {
confirm()
}
override func viewDidLoad() {
super.viewDidLoad()
self.roundView()
// self.titleLabel.text = self.configure?.title
// self.content1Label.text = self.configure?.content1
// self.content2Label.text = self.configure?.content2
self.multiLineContentLabel.text = self.configure?.multiLineContent
self.confirmButton.setTitle(self.configure?.confirmButtonTitle, for: .normal)
// self.cancelButton.setTitle(self.configure?.cancelButtonTitle, for: .normal)
setMultiLanguage()
self.mainView.invalidateIntrinsicContentSize()
let tapGestureRecognizer = UITapGestureRecognizer()
transparentView.addGestureRecognizer(tapGestureRecognizer)
tapGestureRecognizer.addTarget(self, action: #selector(tapGesture(_:)))
tapGestureRecognizer.delegate = self
confirmButton.backgroundColor = .themeRed
cancelButton.setTitleColor(.themeRed, for: .normal)
transparentView.backgroundColor = .themeBackgroundGray
}
@objc func tapGesture(_ sender: UITapGestureRecognizer) {
touchCancel(UIButton())
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
mainView.layer.cornerRadius = 5
confirmButton.layer.cornerRadius = 5
mainView.bottomToOrigin()
setupBranchOrOnline(model: configure?.model)
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
self.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
}
func setConfigure(with configure: ConfirmViewControllerConfiguration) {
self.configure = configure
}
private func roundView() {
// mainView.layer.cornerRadius = 5
// confirmButton.layer.cornerRadius = 5
// cancelButton.layer.cornerRadius = 5
}
private func setMultiLanguage() {
receiverTitleLabel.text = "receiver_text".localized()
mobileNumberTitleLabel.text = "mobile_number_text".localized()
// receiveLocationLabel.text = "branch_text".localized()
// cancelButton.setTitle("cancel_text".localized(), for: .normal)
//
confirmButton.setTitle("confirm_text".localized(), for: .normal)
}
private func setupBranchOrOnline(model: RewardProduct?) {
if configure?.productType == "Coupon" {
titleLabel.text = configure?.title
content1Label.text = configure?.content1
content2Label.text = configure?.content2
receiveLocationLabel.text = configure?.receiveLocation
multiLineContentLabel.text = configure?.multiLineContent
} else {
self.content1Label.text = self.configure?.content1
self.content2Label.text = self.configure?.content2
receiveLocationLabel.text = "branch_text".localized()
self.multiLineContentLabel.text = self.configure?.multiLineContent
}
}
private func cancel() {
mainView.originToBottom {
self.dismiss(animated: true) {
self.delegate?.cancel(self)
}
}
}
private func confirm() {
mainView.originToBottom {
self.dismiss(animated: true) {
self.delegate?.confirm(self)
}
}
}
}
extension ConfirmViewController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
return touch.view == gestureRecognizer.view
}
}