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.
309 lines
11 KiB
309 lines
11 KiB
//
|
|
// ProfileViewController.swift
|
|
// GMERemittance
|
|
//
|
|
// Created by Fm-user on 1/9/18.
|
|
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import SDWebImage
|
|
|
|
class ProfileViewController: UIViewController {
|
|
|
|
@IBOutlet weak var labelUserProfileName: UILabel!
|
|
@IBOutlet weak var imageViewUserProfile: UIImageView!
|
|
@IBOutlet weak var gmeWalletNumber: UILabel!
|
|
@IBOutlet weak var buttonEdit: UIButton!
|
|
@IBOutlet weak var labelUserName: UILabel!
|
|
@IBOutlet weak var labelEmail: UILabel!
|
|
@IBOutlet weak var labelMobileNumber: UILabel!
|
|
@IBOutlet weak var labelBalance: UILabel!
|
|
|
|
let imagePicker = UIImagePickerController()
|
|
|
|
var profileviewmodel = ProfileViewModel()
|
|
|
|
var profileImage: UIImage!
|
|
|
|
public static var profileConnectionTimeOutCheck = 0
|
|
|
|
private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
|
|
|
|
/**
|
|
Display image selection option from camera and gallery.
|
|
*/
|
|
|
|
@objc func selectProfileImage(tapGestureRecognizer: UITapGestureRecognizer) {
|
|
|
|
profileviewmodel.userDataAvailable.value = nil
|
|
|
|
let alert = UIAlertController(title: "Choose Image", message: nil, preferredStyle: .actionSheet)
|
|
|
|
let cameraAction = UIAlertAction(title: "Camera", style: .default,handler: {
|
|
(action : UIAlertAction!) -> Void in
|
|
self.openCamera()
|
|
})
|
|
|
|
let galleryAction = UIAlertAction(title: "Gallery", style: .default,handler: {
|
|
(action : UIAlertAction!) -> Void in
|
|
self.openGallery()
|
|
})
|
|
|
|
let cancelAction = UIAlertAction.init(title: "Cancel", style: .destructive, handler: nil)
|
|
|
|
cancelAction.setValue(UIColor.black, forKey: "titleTextColor")
|
|
cameraAction.setValue(UIColor(hex:0xEC1C24), forKey: "titleTextColor")
|
|
galleryAction.setValue(UIColor(hex:0xEC1C24), forKey: "titleTextColor")
|
|
|
|
alert.addAction(cameraAction)
|
|
alert.addAction(galleryAction)
|
|
alert.addAction(cancelAction)
|
|
|
|
self.present(alert, animated: true, completion: nil)
|
|
}
|
|
|
|
/**
|
|
Open camera to take picture
|
|
*/
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
/**
|
|
Open camera to take picture
|
|
*/
|
|
func openGallery() {
|
|
imagePicker.delegate = self
|
|
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
|
|
imagePicker.allowsEditing = true
|
|
present(imagePicker, animated: true, completion: nil)
|
|
}
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
self.tabBarController?.navigationController?.navigationBar.barTintColor = UIColor(hex:0xEC1C24)
|
|
setUpAnotherLoginListener(genericviewmodel: profileviewmodel)
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
setUpNavBar(id: 202,title: "")
|
|
|
|
listenNetwork()
|
|
if isVerified() {
|
|
buttonEdit.isHidden = true
|
|
} else {
|
|
buttonEdit.isHidden = true
|
|
}
|
|
|
|
imageViewUserProfile.isUserInteractionEnabled = true
|
|
labelUserProfileName.isUserInteractionEnabled = true
|
|
|
|
|
|
imageViewUserProfile.isHidden = true
|
|
labelUserProfileName.isHidden = false
|
|
|
|
labelUserProfileName.layer.backgroundColor = UIColor(hex: 0x2e3192).cgColor
|
|
labelUserProfileName.layer.cornerRadius = labelUserProfileName.frame.height / 2
|
|
|
|
imageViewUserProfile.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selectProfileImage(tapGestureRecognizer:))))
|
|
|
|
labelUserProfileName.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selectProfileImage(tapGestureRecognizer:))))
|
|
|
|
startLoading()
|
|
|
|
profileviewmodel.profileConnectionTimeOut.value = nil
|
|
/**
|
|
connection timeout
|
|
*/
|
|
profileviewmodel.profileConnectionTimeOut.bind { [unowned self] in
|
|
guard $0 != nil else {
|
|
return
|
|
}
|
|
self.stopLoading()
|
|
if ProfileViewController.profileConnectionTimeOutCheck == 0{
|
|
ProfileViewController.profileConnectionTimeOutCheck = ProfileViewController.profileConnectionTimeOutCheck+1
|
|
self.popUpMessage(value: 41)
|
|
}
|
|
}
|
|
bindUserImageToUI()
|
|
bindUserDetailsToUI()
|
|
profileviewmodel.fetchUserInfo(userId: nil)
|
|
}
|
|
|
|
func startLoading(){
|
|
disableUserInteractions()
|
|
showActivityIndicator(activityIndicator: activityIndicator)
|
|
}
|
|
|
|
func stopLoading(){
|
|
enableUserInteractions()
|
|
dismissActivityIndicator(activityIndicator: self.activityIndicator)
|
|
}
|
|
|
|
/**
|
|
Check internet connection
|
|
*/
|
|
|
|
func listenNetwork() {
|
|
profileviewmodel.internetConnection.value = nil
|
|
|
|
profileviewmodel.internetConnection.bind { [unowned self] in
|
|
guard $0 != nil else {
|
|
return
|
|
}
|
|
self.stopLoading()
|
|
self.popUpMessage(value: 15)
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
Bind call for user deatails
|
|
*/
|
|
|
|
func bindUserDetailsToUI() {
|
|
profileviewmodel.userDataAvailable.bind { [unowned self] in
|
|
guard $0 != nil else {
|
|
return
|
|
}
|
|
self.stopLoading()
|
|
guard $0! else {
|
|
if ProfileViewController.profileConnectionTimeOutCheck == 0{
|
|
ProfileViewController.profileConnectionTimeOutCheck = ProfileViewController.profileConnectionTimeOutCheck+1
|
|
self.popUpMessageError(value: 10, message: self.profileviewmodel.getErrorMessage())
|
|
}
|
|
return
|
|
}
|
|
|
|
if let userDpString = self.profileviewmodel.getProfileModel().dpUrl {
|
|
if let userDpUrl = URL(string: userDpString) {
|
|
SDImageCache.shared().clearMemory()
|
|
SDImageCache.shared().clearDisk()
|
|
self.imageViewUserProfile.sd_setImage(with: userDpUrl, completed: nil)
|
|
self.setUpImage()
|
|
}
|
|
} else {
|
|
if let firstName = self.profileviewmodel.getProfileModel().firstName{
|
|
self.labelUserProfileName.text = String(firstName.prefix(1).uppercased())
|
|
}
|
|
}
|
|
|
|
self.labelUserName.text = self.profileviewmodel.getFullName()
|
|
self.labelMobileNumber.text = self.profileviewmodel.getProfileModel().mobileNumber
|
|
self.labelEmail.text = self.profileviewmodel.getProfileModel().email
|
|
if let availableBalance = self.profileviewmodel.getProfileModel().availableBalance {
|
|
self.labelBalance.text = self.getCommaAddedAmountString(amountString: availableBalance)
|
|
}
|
|
let walletNum = self.profileviewmodel.getProfileModel().walletNumber ?? "null"
|
|
let bankName = self.profileviewmodel.getProfileModel().primaryBankName ?? ""
|
|
|
|
self.setWalletNumber(walletNumber: walletNum, bankName: "(" + bankName + ")")
|
|
}
|
|
}
|
|
|
|
/**
|
|
Display Wallet number and bank name
|
|
*/
|
|
func setWalletNumber(walletNumber:String, bankName:String){
|
|
let recipientColor = UIColor(red: 236/255, green: 28/255.0, blue: 36/255, alpha: 1.0)
|
|
|
|
let title: String = String("GME Wallet No. ")
|
|
let wNumber: String = walletNumber + " "
|
|
let bName: String = bankName
|
|
|
|
let mutableQuestion1 = NSMutableAttributedString(string: title)
|
|
let mutableQuestion2 = NSMutableAttributedString(string: wNumber)
|
|
let mutableQuestion3 = NSMutableAttributedString(string: bName)
|
|
|
|
mutableQuestion2.addAttribute(NSAttributedStringKey.foregroundColor, value: recipientColor, range: NSRange(location:0, length: mutableQuestion2.length))
|
|
|
|
let mutableQuestion = NSMutableAttributedString()
|
|
mutableQuestion.append(mutableQuestion1)
|
|
mutableQuestion.append(mutableQuestion2)
|
|
mutableQuestion.append(mutableQuestion3)
|
|
|
|
self.gmeWalletNumber.attributedText = mutableQuestion
|
|
|
|
}
|
|
|
|
/**
|
|
Bind call to display Profile image
|
|
*/
|
|
func bindUserImageToUI() {
|
|
profileviewmodel.imageSubmitted.bind{ [unowned self] in
|
|
guard $0 != nil else {
|
|
return
|
|
}
|
|
self.stopLoading()
|
|
guard $0! else {
|
|
if ProfileViewController.profileConnectionTimeOutCheck == 0{
|
|
ProfileViewController.profileConnectionTimeOutCheck = ProfileViewController.profileConnectionTimeOutCheck+1
|
|
self.popUpMessageError(value: 10, message: self.profileviewmodel.getErrorMessage())
|
|
}
|
|
return
|
|
}
|
|
self.imageViewUserProfile.image = self.profileImage
|
|
self.setUpImage()
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
Profile image view Attributes
|
|
*/
|
|
func setUpImage() {
|
|
self.labelUserProfileName.isHidden = true
|
|
self.imageViewUserProfile.isHidden = false
|
|
self.imageViewUserProfile.layer.cornerRadius = self.imageViewUserProfile.frame.height / 2
|
|
self.imageViewUserProfile.contentMode = .scaleAspectFill
|
|
}
|
|
|
|
override func didReceiveMemoryWarning() {
|
|
super.didReceiveMemoryWarning()
|
|
}
|
|
|
|
@IBAction func editProfileTap(_ sender: Any) {
|
|
self.performSegue(withIdentifier: "editProfile", sender: nil)
|
|
|
|
}
|
|
}
|
|
|
|
extension ProfileViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate {
|
|
|
|
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
|
|
|
|
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
|
|
|
|
profileImage = image
|
|
let imageData: NSData = UIImageJPEGRepresentation(image, 0.25)! as NSData
|
|
let imageDataBase64: String = imageData.base64EncodedString(options: .lineLength64Characters)
|
|
|
|
startLoading()
|
|
|
|
profileviewmodel.provideImageForSubmission(docType: kycCode.UserImage.rawValue, imageBase64: imageDataBase64)
|
|
|
|
dismiss(animated: true, completion: nil)
|
|
} else {
|
|
|
|
}
|
|
}
|
|
|
|
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
|
|
dismiss(animated: true, completion: nil)
|
|
}
|
|
}
|
|
|