// // InviteViewController.swift // GMERemittance // // Created by FMI-12 on 2/28/18. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved. // import UIKit class InviteViewController: UIViewController { public var bonusStatus: Bool? public static var inviteStatus: Bool? public static var notificationCode = "" private var inviteviewmodel = InviteViewModel() @IBOutlet weak var labelNumberRefer: UILabel! @IBOutlet weak var labelEarnedAmount: UILabel! private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView() public static var inviteConnectionTimeOutCheck = 0 public var fromNotification: Int? override func viewWillAppear(_ animated: Bool) { self.tabBarController?.navigationController?.navigationBar.barTintColor = UIColor(hex:0xEC1C24) } /** Request once again. After submitting a form view, redirect back to this view and provide updated number of count related to invitation. */ override func viewDidAppear(_ animated: Bool) { setUpAnotherLoginListener(genericviewmodel: inviteviewmodel) setUpNetworkListener() if (!(UserDefaults.standard.object(forKey: "com.gmeremit.isVerified") as! Bool)) { popUpMessage(value: 14) enableUserInteractions() } if (InviteViewController.inviteStatus != nil) && InviteViewController.inviteStatus == true { disableUserInteractions() showActivityIndicator(activityIndicator: activityIndicator) inviteviewmodel.fetchInvitee() } } /** Check internet connection */ func setUpNetworkListener() { inviteviewmodel.internetConnection.value = nil inviteviewmodel.internetConnection.bind { [unowned self] in guard $0 != nil else { return } self.stopLoading() self.popUpMessage(value: 15) } } override func viewDidLoad() { super.viewDidLoad() /** Nav Bar as per notification type i.e. push and internal notification */ inviteviewmodel.inviteeConnectionTimeOut.value = nil /** connection timeout */ inviteviewmodel.inviteeConnectionTimeOut.bind { [unowned self] in guard $0 != nil else { return } self.stopLoading() if self.fromNotification != 0{ if InviteViewController.inviteConnectionTimeOutCheck == 0{ InviteViewController.inviteConnectionTimeOutCheck = InviteViewController.inviteConnectionTimeOutCheck+1 self.popUpMessage(value: 36) } } } if InviteViewController.notificationCode == "500" { setUpNavBar(id: 201, title: "Invite") } else if InviteViewController.notificationCode == "p500"{ setUpNavBar(id: 207, title: "Invite") }else { setUpNavBar(id: 202,title: "") } if !Reachability.isConnectedToNetwork() { self.stopLoading() self.popUpMessage(value: 15) } else { /** Request Invitee Api to fetch number of invitation and total earned values */ self.startLoading() inviteviewmodel.fetchInvitee() inviteviewmodel.inviteeFetch.bind{ [unowned self] in guard $0 != nil else { return } guard $0! else { self.stopLoading() self.popUpMessageError(value: 10, message: self.inviteviewmodel.getErrorMessage()) return } self.stopLoading() /** Update UI only when api respond with data */ if (self.inviteviewmodel.getInviteeArray().count > 0){ self.viewUpdate() }else{ } } } } /** Provide number of invitations and total earned values. Count Invitation and Total Earned values as per the status. */ func viewUpdate(){ var inviteePendingCount: Int = 0 var inviteeActiveCount: Int = 0 for i in inviteviewmodel.getInviteeArray()[0..