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.
|
|
// // 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..<inviteviewmodel.getCount()]{ if i.status == "pending" { inviteePendingCount = inviteePendingCount + 1 } else if i.status == "active" { inviteeActiveCount = inviteeActiveCount + 1 } else { } } self.labelNumberRefer.text = String(inviteePendingCount) self.labelEarnedAmount.text = "+" + String(inviteeActiveCount * 7000) } /**
Disable user interaction while fetching data from api */ func startLoading(){ disableUserInteractions() showActivityIndicator(activityIndicator: activityIndicator) } /**
Enable user interaction after fetching data from api */ func stopLoading(){ self.enableUserInteractions() if self.activityIndicator.isAnimating { self.dismissActivityIndicator(activityIndicator: self.activityIndicator) } } /**
Redirect to view name ReferringViewController. A user can refer app to others through. */ @IBAction func buttonInviteTap(_ sender: Any) { performSegue(withIdentifier: "refering", sender: nil) } /**
Redirect to view name InviteViewController. A user can view the list of referred people who still haven't used the app. */ @IBAction func pendingTap(_ sender: UITapGestureRecognizer) { InviteViewController.inviteStatus = false bonusStatus = true performSegue(withIdentifier: "earned", sender: nil) } /**
Redirect to view name InviteViewController. A user can view the list of referred people who still haven't used the app. */ @IBAction func earnedTap(_ sender: UITapGestureRecognizer) { InviteViewController.inviteStatus = false bonusStatus = false performSegue(withIdentifier: "earned", sender: nil) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }
/**
Redirect to EarnedViewController. If var bonusStatus is true then redirect to Pending segment else redirect to Earned segment. */ override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if (segue.identifier == "earned") { let vc = segue.destination as! EarnedViewController vc.bonusStatus = bonusStatus vc.inviteeArray = inviteviewmodel.getInviteeArray().reversed() } } }
|