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.
 
 
 
 

201 lines
7.2 KiB

//
// PopUpAddUserProfileViewController.swift
// GMERemittance
//
// Created by Fm-user on 2/28/18.
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import UIKit
class PopUpAddUserProfileViewController: UIViewController {
// var dialogDismissed: Box<Bool?> = Box(nil)
@IBOutlet weak var buttonProfileImage: UIButton!
private var uploadimageviewmodel = UploadImageViewModel()
private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
private var selectedImage: UIImage!
public static var uploadImageConnectionTimeOutCheckDialog = 0
let imagePicker = UIImagePickerController()
@IBOutlet weak var addLater: UIButton!
@IBOutlet weak var userName: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
setUpAnotherLoginListener(genericviewmodel: uploadimageviewmodel)
self.view.backgroundColor = UIColor.black.withAlphaComponent(0.7)
self.showAnimate()
userName.text = "Namaste, \(getFullName())"
uploadimageviewmodel.uploadImageConnectionTimeOut.value = nil
/**
connection timeout
*/
uploadimageviewmodel.uploadImageConnectionTimeOut.bind { [unowned self] in
guard $0 != nil else {
return
}
self.enableUserInteractions()
self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
if PopUpAddUserProfileViewController.uploadImageConnectionTimeOutCheckDialog == 0{
PopUpAddUserProfileViewController.uploadImageConnectionTimeOutCheckDialog = PopUpAddUserProfileViewController.uploadImageConnectionTimeOutCheckDialog+1
self.popUpMessage(value: 45)
}
}
uploadimageviewmodel.isImageSubmitted.bind { [unowned self] in
guard $0 != nil else {
return
}
self.enableUserInteractions()
self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
guard $0! else {
if PopUpAddUserProfileViewController.uploadImageConnectionTimeOutCheckDialog == 0{
PopUpAddUserProfileViewController.uploadImageConnectionTimeOutCheckDialog = PopUpAddUserProfileViewController.uploadImageConnectionTimeOutCheckDialog+1
self.popUpMessageError(value: 10, message: self.uploadimageviewmodel.getErrorMessage())
}
self.uploadimageviewmodel.isImageSubmitted.value = nil
return
}
self.addLater.setTitle("Done", for: .normal)
self.addLater.setTitleColor(UIColor(hex: 0xec1c24), for: .normal)
self.buttonProfileImage.setImage(self.selectedImage, for: .normal)
self.uploadimageviewmodel.isImageSubmitted.value = nil
}
}
// override func showAnimate() {
// super.showAnimate()
// self.navigationController?.navigationBar.isHidden = true
// self.tabBarController?.tabBar.isHidden = true
// self.tabBarController?.tabBar.isUserInteractionEnabled = false
//
// }
func showAnimate()
{
self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
self.view.alpha = 0.0
self.view.alpha = 1.0
self.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
UIView.animate(withDuration: 0.1, animations: {
self.view.alpha = 1.0
self.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
});
}
func dismissDialog()
{
self.navigationController?.navigationBar.isUserInteractionEnabled = true
UIView.animate(withDuration: 0.0, animations: {
self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
self.view.alpha = 0.0;
}, completion:{(finished : Bool) in
if (finished)
{
self.view.removeFromSuperview()
}
});
UserDefaults.standard.set(false, forKey: "com.gmeremit.showImageAlert")
// dialogDismissed.value = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func addLaterAction(_ sender: Any) {
UserDefaults.standard.set(false, forKey: "com.gmeremit.showImageAlert")
self.dismissDialog()
}
@IBAction func selectProfileImage(_ sender: Any) {
let alert = UIAlertController(title: "Choose Image", message: nil, preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: .default, handler: { _ in
self.openCamera()
}))
alert.addAction(UIAlertAction(title: "Gallery", style: .default, handler: { _ in
self.openGallery()
}))
alert.addAction(UIAlertAction.init(title: "Cancel", style: .destructive, handler: {_ in
self.dismiss(animated: true, completion: nil)
}))
self.present(alert, animated: true, completion: nil)
}
func openCamera(){
if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.camera)) {
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = true
present(imagePicker, animated: true, completion: nil)
}
else {
let alert = UIAlertController(title: "Warning", message: "You don't have camera", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
func openGallery(){
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
imagePicker.allowsEditing = true
present(imagePicker, animated: true, completion: nil)
}
}
extension PopUpAddUserProfileViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage
let imageData: NSData = UIImageJPEGRepresentation(selectedImage, 0.25)! as NSData
let imageDataBase64: String = imageData.base64EncodedString(options: .lineLength64Characters)
uploadUserProfileImage(profileImage: imageDataBase64);
dismiss(animated: true, completion: nil)
showActivityIndicator(activityIndicator: activityIndicator)
disableUserInteractions()
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}
func uploadUserProfileImage(profileImage: String){
uploadimageviewmodel.uploadProfileImage(docType: kycCode.UserImage.rawValue, imageBase64: profileImage)
}
}