Browse Source

add vc

pull/1/head
InKwon James Kim 5 years ago
parent
commit
4a5c710f70
  1. 175
      GME Remit/Modules/RegisterModules/NewRegisterStep1/User Interface/View/NewRegisterStep1ViewController.swift

175
GME Remit/Modules/RegisterModules/NewRegisterStep1/User Interface/View/NewRegisterStep1ViewController.swift

@ -0,0 +1,175 @@
//
// NewRegisterStep1ViewController.swift
// GME Remit
//
// Created by InKwon James Kim on 2019/12/02.
//Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
//
import UIKit
import RxSwift
import RxCocoa
import CoreLocation
class NewRegisterStep1ViewController: UIViewController {
// MARK: Properties
var presenter: NewRegisterStep1Presenter!
private let disposeBag = DisposeBag()
private let sendLocation = PublishSubject<CLLocation>()
private let locationManager = CLLocationManager()
// MARK: Computed Properties
// MARK: IBOutlets
@IBOutlet private weak var userNameTextField: ValidationTextField!
@IBOutlet private weak var genderTextField: ValidationTextField!
@IBOutlet private weak var dobTextField: ValidationTextField!
@IBOutlet private weak var emailTextField: ValidationTextField!
@IBOutlet private weak var mobileTextField: ValidationTextField!
@IBOutlet private weak var nativeCountryTextField: ValidationTextField!
@IBOutlet private weak var addressTextField: ValidationTextField!
@IBOutlet private weak var gpsButton: UIButton!
@IBOutlet private weak var idTextField: ValidationTextField!
@IBOutlet private weak var passwordTextField: ValidationTextField!
@IBOutlet private weak var continueButton: UIButton!
// MARK: VC's Life cycle
override func viewDidLoad() {
super.viewDidLoad()
setup()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}
// willMove -> It appears on the parent screen.
override func willMove(toParent parent: UIViewController?) {
print(#function)
if let `parent` = parent as UIViewController? {
print(parent)
}
}
// It appears on the parent screen. -> didMove
override func didMove(toParent parent: UIViewController?) {
print(#function)
if let `parent` = parent as UIViewController? {
print(parent)
}
}
// MARK: IBActions
@IBAction func touchGPSButton(_ sender: UIButton) {
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
showProgressHud()
}
}
}
// MARK: Other Functions
extension NewRegisterStep1ViewController {
private func setup() {
setUI()
setBinding()
setUIBinding()
}
private func setUI() {
let genderConfigure = TablePresenterConfiguration(presenterTitle: "Select Gender")
genderTextField.useAsDropDown(
with: genderConfigure,
items: ["Male", "Female", "Others"] as? [TablePresenterProtocol]
)
let dobConfigure = TablePresenterConfiguration(presenterTitle: "Select Dob")
dobTextField.useAsDropDown(
with: dobConfigure,
items: ["Male", "Female", "Others"] as? [TablePresenterProtocol]
)
let nativeCountryConfigure = TablePresenterConfiguration(presenterTitle: "Select Native Country")
nativeCountryTextField.useAsDropDown(
with: nativeCountryConfigure,
items: ["Male", "Female", "Others"] as? [TablePresenterProtocol]
)
}
private func setUIBinding() {
}
private func setBinding() {
let input = NewRegisterStep1Presenter.Input(
sendLocation: sendLocation.asDriverOnErrorJustComplete()
)
let output = presenter.transform(input: input)
output.isError
.drive(
onNext: { self.alert(type: .error, message: $0.localizedDescription) }
).disposed(by: disposeBag)
output.isProgress
.drive(
onNext: { $0 ? self.showProgressHud() : self.hideProgressHud() }
).disposed(by: disposeBag)
output.gpsAddress.drive(addressTextField.rx.text).disposed(by: disposeBag)
}
}
extension NewRegisterStep1ViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
hideProgressHud()
guard let location = manager.location else { return }
sendLocation.onNext(location)
locationManager.stopUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
hideProgressHud()
locationManager.stopUpdatingLocation()
let alert = UIAlertController(
title: "Settings",
message: "Allow location from settings",
preferredStyle: .alert
)
self.present(alert, animated: true, completion: nil)
alert.addAction(UIAlertAction(title: "Move setting", style: .default, handler: { action in
switch action.style {
case .default:
UIApplication
.shared
.open(
NSURL(string: UIApplication.openSettingsURLString)! as URL,
options: [:],
completionHandler: nil
)
case .cancel: print("cancel")
case .destructive: print("destructive")
@unknown default: break
}
}))
}
}
Loading…
Cancel
Save