Professional Documents
Culture Documents
//For DocUpload
var dateCityVenueArrayDoc = NSArray()
var arMainBatchForDoc = [ImageBatchDetailForPassport]()
var selectedDateIDDoc = 0
var selectedCityIDDoc = 0
// For DoubtUpload
var arDateDoubt = [DoubtDateListTBL]()
var arCityDoubt = [DoubtCityListTBL]()
var completionHandler: AWSS3TransferUtilityUploadCompletionHandlerBlock?
var arrMedia = [Data]()
func demoAWS(){
var urlList = [String]();
var itemUploadingIndex = 0
let imageDemo = UIImage(named: "candy_camera")
let imageData = imageDemo?.jpegData(compressionQuality: 0.0)
self.arrMedia.append(imageData!)
self.completionHandler = { (task, error) -> Void in
DispatchQueue.main.async(execute: {
if let error = error {
print("Failed with error: \(error)")
DispatchQueue.main.async {
print("something went wrong")
}
}
else{
urlList.append(aiServiceManager.getAbsoluteS3Url(key:
task.key))
itemUploadingIndex += 1
// DispatchQueue.main.async {
// HIDE_CUSTOM_LOADER()
// }
if self.arrMedia.count > itemUploadingIndex{
aiServiceManager.uploadFilesToAwsS3(fileUrls:
[self.arrMedia[itemUploadingIndex]], completionHandler: self.completionHandler!)
// let appDelegate = UIApplication.shared.delegate as!
AppDelegate
// appDelegate.lblUploadingMessage?.text = "Uploading \
(itemUploadingIndex + 1) of \(self.arrMedia.count) files"
}
if urlList.count == self.arrMedia.count {
print("successfully upload")
print(urlList)
// all files are uploaded. Call the back-end server API
to update portfolio.
// DispatchQueue.main.async {
// HIDE_CUSTOM_LOADER()
// }
// self.callBackendServerAPI(urlList: urlList)
}
}
})
}
if self.arrMedia.count > 0{
aiServiceManager.uploadFilesToAwsS3(fileUrls: [self.arrMedia[0]],
completionHandler: completionHandler!)
// let appDelegate = UIApplication.shared.delegate as! AppDelegate
// appDelegate.lblUploadingMessage?.text = "Uploading \
(itemUploadingIndex + 1) of \(self.arrMedia.count) files"
}
}
func removeHistoryNotifications(){
NotificationCenter.default.removeObserver(self, name:
NSNotification.Name(rawValue: "DoubtHistoryLogOutShow"), object: nil)
}
//MARK: IBActions
}
DropDownDocumentCityArray.show()
DropDownDocumentCityArray.selectionAction = { [unowned self] (index, item)
in
self.lblDocumentTestCity.text = item
self.selectedCityIDDoc = Int(self.arCityDoubt[index].cityID)
self.fillUpDocCity()
self.deactivateDocCameraBtn()
self.checkAllDocValueFill()
}
DropDownDocumentCityArray.anchorView = self.viewDocumentCity
DropDownDocumentCityArray.bottomOffset = CGPoint(x: 0,
y:self.viewDocumentCity.bounds.height)
}
func createDocAndPassToNextVC(){
self.appDelegate.batchDoubtId = self.randomString(length: 25)
print(UIDevice.current.orientation)
var text=""
switch UIDevice.current.orientation{
case .portrait:
text="Portrait"
case .portraitUpsideDown:
text="PortraitUpsideDown"
case .landscapeLeft:
text="LandscapeLeft"
case .landscapeRight:
text="LandscapeRight"
default:
text="Another"
}
print("you have moved: \(text)")
let secondStoryboard: UIStoryboard = UIStoryboard(name: "SecondStoryboard",
bundle: nil)
let vc = secondStoryboard.instantiateViewController(withIdentifier:
"PassportScanDoubtViewController")as! PassportScanDoubtViewController
vc.passSelfVC = self
vc.userid = (UserDefaults.standard.object(forKey: "userId") as! String)
vc.AppBatchId = self.appDelegate.batchDoubtId
vc.FileName = UUID().uuidString
vc.Module = ""
vc.Guestmode = true
let localCapture = self.getCaptureTimeAndCaptureDate()
vc.IsImpersonate = "true"
vc.ImpersonateBy = (UserDefaults.standard.object(forKey: "userId") as!
String)
vc.ImpersonateDate = localCapture.1
vc.DateID = self.selectedDateIDDoc
vc.CityID = self.selectedCityIDDoc
vc.PrimaryInfoID = 0
vc.DeviceID = UIDevice.current.identifierForVendor!.uuidString
vc.UploadedTime = localCapture.0
vc.MarkingType = ""
vc.comeFromUploadScreen = true
vc.TotalCandidates = ""
vc.spkLocation = ""
vc.speakingType = ""
vc.isComeFromDocuments = true
vc.testDate = self.lblDocumentTestDate.text ?? ""
vc.testCity = self.lblDocumentTestCity.text ?? ""
self.navigationController!.pushViewController(vc, animated: true)
}
@IBAction func docUploadCameraClicked(_ sender: AnyObject){
let errorTuple = self.validationCheckForDoc()
if errorTuple.0{
self.showAlertViewForErrorCheck(message: errorTuple.1)
return
}
self.createDocAndPassToNextVC()
}
func fillMainHistoryTab(){
self.btnMainHistory.setTitleColor(UIColor(red: 205.0/255.0, green:
9.0/255.0, blue: 21.0/255.0, alpha: 1.0), for: UIControl.State.normal)
self.btnMainUploads.setTitleColor(UIColor(red: 56.0/255.0, green:
56.0/255.0, blue: 56.0/255.0, alpha: 1.0), for: UIControl.State.normal)
self.viewHistory.isHidden = false
}
func activateDocDate(){
self.selectedDateIDDoc = 0
self.viewDocumentDate.isUserInteractionEnabled = true
self.lblDocumentTestDate.text = "Test Date"
self.lblDocumentTestDate.textColor = self.model.themecolor
self.imgDocumentTestDateDropDown.image = UIImage(named:
"dropdown_arrowred.png")
self.imgIconTestDate.image = UIImage(named: "Availability_red.png")
self.imgDocumentTestDateBottom.backgroundColor = self.model.themecolor
}
func deactivateDocDate(){
self.selectedDateIDDoc = 0
self.viewDocumentDate.isUserInteractionEnabled = false
self.lblDocumentTestDate.text = "Test Date"
self.lblDocumentTestDate.textColor = self.model.disabledGrayColor
self.imgDocumentTestDateDropDown.image = UIImage(named:
"dropdown_lgrey.png")
self.imgIconTestDate.image = UIImage(named: "Availability_lgrey.png")
self.imgDocumentTestDateBottom.backgroundColor =
self.model.disabledGrayColor
}
func fillUpDocDate(){
self.lblDocumentTestDate.textColor = self.model.DarkgrayColor
self.imgDocumentTestDateDropDown.image = UIImage(named:
"dropdown_arrowgrey.png")
self.imgIconTestDate.image = UIImage(named: "Availability_grey.png")
self.imgDocumentTestDateBottom.backgroundColor = self.model.DarkgrayColor
}
func activateDocCity(){
self.selectedCityIDDoc = 0
self.viewDocumentCity.isUserInteractionEnabled = true
self.lblDocumentTestCity.text! = "Test City"
self.lblDocumentTestCity.textColor = self.model.themecolor
self.imgDocumentTestCityDropDown.image = UIImage(named:
"dropdown_arrowred.png")
self.imgIconTestCity.image = UIImage(named: "location_red.png")
self.imgDocumentTestCityBottom.backgroundColor = self.model.themecolor
}
func deactivateDocCity(){
self.selectedCityIDDoc = 0
self.viewDocumentCity.isUserInteractionEnabled = false
self.lblDocumentTestCity.text = "Test City"
self.lblDocumentTestCity.textColor = self.model.disabledGrayColor
self.imgDocumentTestCityDropDown.image = UIImage(named:
"dropdown_lgrey.png")
self.imgIconTestCity.image = UIImage(named: "location_lgrey.png")
self.imgDocumentTestCityBottom.backgroundColor = model.disabledGrayColor
}
func fillUpDocCity(){
self.lblDocumentTestCity.textColor = self.model.DarkgrayColor
self.imgDocumentTestCityDropDown.image = UIImage(named:
"dropdown_arrowgrey.png")
self.imgIconTestCity.image = UIImage(named: "location_grey.png")
self.imgDocumentTestCityBottom.backgroundColor = self.model.DarkgrayColor
}
func activateDocCameraBtn(){
self.btnDocumentCamera.isUserInteractionEnabled = true
self.btnDocumentCamera.alpha = 1.0
}
func deactivateDocCameraBtn(){
self.btnDocumentCamera.isUserInteractionEnabled = false
self.btnDocumentCamera.alpha = 0.2
}
func resetDocAllFields(){
self.activateDocDate()
self.deactivateDocCity()
self.deactivateDocCameraBtn()
}
func checkAllDocValueFill(){
if (self.lblDocumentTestDate.text! != "Test Date") &&
(self.lblDocumentTestCity.text! != "Test City") && self.selectedDateIDDoc != 0 &&
self.selectedCityIDDoc != 0{
self.activateDocCameraBtn()
}else{
self.deactivateDocCameraBtn()
}
}
func getTotalDocImagesForUpload(){
self.totalDocImages = 0
self.uploadedDocImages = 0
for objMainBatch in self.arMainBatchForDoc{
let arImagesRemaining =
DatabaseHelper.sharedInstance.getRemainingImagesForAppId(appBatchId:
objMainBatch.appBatchId!)
let value = arImagesRemaining.count
self.totalDocImages = self.totalDocImages + value
}
}
func uploadDataForDocument(){
if self.appDelegate.isUploadingBatchesDoubt == false{
self.countAllForPendingNotification = 0
self.appDelegate.isUploadingBatchesDoubt = true
self.arMainBatchForDoc =
DatabaseHelper.sharedInstance.getMainBatchDocDataForUploading(isUploaded: "False")
if self.arMainBatchForDoc.count > 0{
if self.model.isConnectedToNetwork() == true{
self.getTotalDocImagesForUpload()
self.updateProgessViewForDoc()
self.previousDocImages.isHidden = true
self.progressLbl.isHidden = false
self.progressViewDoc.isHidden = false
self.updateProgressViewDocOnHistoryPage(isHide: false, isState:
"Start")
let countMain = 0
self.uploadMainDocument(mainBatchObjForDoc:
self.arMainBatchForDoc[countMain], indexMainBatch: countMain)
}else{
self.appDelegate.isUploadingBatchesDoubt = false
self.previousDocImages.isHidden = false
self.progressLbl.isHidden = true
self.progressViewDoc.isHidden = true
self.updateProgressViewDocOnHistoryPage(isHide: true, isState:
"Stop")
self.countAllForPendingNotification =
self.countAllForPendingNotification + 1
if self.countAllForPendingNotification ==
1{ self.fireUploadPendingNotification() }
}
}else{
self.deleteMainBatchForDoc()
self.appDelegate.isUploadingBatchesDoubt = false
}
}
}
func checkUploadingBatchesForDocument(){
let arRemainUploadDoc =
DatabaseHelper.sharedInstance.getMainBatchDocDataForUploading(isUploaded: "False")
if arRemainUploadDoc.count > 0{
self.previousDocImages.isHidden = false
}
}
DatabaseHelper.sharedInstance.editMainBatchDocData(objMainBatch:
mainBatchObjForDoc)
var indexMainBatch = indexMainBatch
indexMainBatch = indexMainBatch + 1
if indexMainBatch < self.arMainBatchForDoc.count{
self.uploadMainDocument(mainBatchObjForDoc:
self.arMainBatchForDoc[indexMainBatch], indexMainBatch: indexMainBatch)
}else{
print("All Batches complete")
print("Try to delete all specific and main batch document
data2")
self.deleteMainBatchForDoc()
print("Try to SecureUpload data")
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.previousDocImages.isHidden = true
self.progressLbl.isHidden = true
self.progressViewDoc.isHidden = true
self.updateProgressViewDocOnHistoryPage(isHide: true,
isState: "Finish")
}
self.appDelegate.isUploadingBatchesDoubt = false
}
}
}else {
self.appDelegate.isUploadingBatchesDoubt = false
if response?.object(forKey: "isLogout") != nil && !
(response?.object(forKey: "isLogout") is NSNull){
if response?.object(forKey: "isLogout") as! Bool{
self.showLogOutAlertView(message: response?.object(forKey:
"message") as! String)
}
}else{
self.view.makeToast(message: response?.object(forKey:
"message") as! String)
}
}
})
}
func deleteMainBatchForDoc(){
let arDeleteMainDoc =
DatabaseHelper.sharedInstance.getMainBatchDocDataForUploading(isUploaded: "True")
for objDeleteMainDoc in arDeleteMainDoc{
let arAllImagesForObj = objDeleteMainDoc.imagesBatchArray?.allObjects
as! [ImagesForPassport]
for objImage in arAllImagesForObj{
DatabaseHelper.sharedInstance.deleteImagesPassportData(objImagePassport: objImage)
}
DatabaseHelper.sharedInstance.deleteMainBatchDocData(objMainBatch:
objDeleteMainDoc)
}
//MARK:- API
func getDocumentsData(){
if self.model.isConnectedToNetwork() == false{
return
}
let parameters = ["":""]
AppEngine().getDoubtsData(parameter: parameters as NSDictionary,
completionHandler: { (response: NSDictionary?) in
if response == nil{ return }
if response?.object(forKey: "success") as! Bool == true{
if response?.object(forKey: "data") != nil && !
(response?.object(forKey: "data") is NSNull){
let dicArray : NSArray = response?.object(forKey: "data") as!
NSArray
DoubtDatabaseHelper.sharedInstance.deleteDoubtDateCityEntities()
for dateObj in dicArray{
let dateID = (dateObj as! NSDictionary).object(forKey:
"dateID") as! Int64
let examDate = (dateObj as! NSDictionary).object(forKey:
"examDate") as! String
print(examDate)
var dateList = [String : Any]()
dateList["dateID"] = dateID
dateList["examDate"] = examDate
DoubtDatabaseHelper.sharedInstance.saveDateDoubt(dateDict:
dateList)
let cityArray = (dateObj as! NSDictionary).object(forKey:
"cityList") as! NSArray
for cityObj in cityArray{
let cityID = (cityObj as! NSDictionary).object(forKey:
"cityID") as! Int64
let cityName = (cityObj as!
NSDictionary).object(forKey: "cityName") as! String
var cityList = [String : Any]()
cityList["cityID"] = cityID
cityList["cityName"] = cityName
cityList["dateID"] = dateID
print(cityName)
DoubtDatabaseHelper.sharedInstance.saveCityDoubt(cityDict: cityList)
}
}
}
if response?.object(forKey: "bucketname") != nil && !
(response?.object(forKey: "bucketname") is NSNull){
let doubtBucketName : String = response?.object(forKey:
"bucketname") as! String
self.prefs.set(doubtBucketName, forKey: "DoubtBucketName")
}
if response?.object(forKey: "accesskey") != nil && !
(response?.object(forKey: "accesskey") is NSNull){
let doubtAccessKey : String = response?.object(forKey:
"accesskey") as! String
self.prefs.set(doubtAccessKey, forKey: "DoubtAccessKey")
}
if response?.object(forKey: "secretkey") != nil && !
(response?.object(forKey: "secretkey") is NSNull){
let doubtSecretKey : String = response?.object(forKey:
"secretkey") as! String
self.prefs.set(doubtSecretKey, forKey: "DoubtSecretKey")
}
if response?.object(forKey: "foldername") != nil && !
(response?.object(forKey: "foldername") is NSNull){
let doubtFolderName : String = response?.object(forKey:
"foldername") as! String
self.prefs.set(doubtFolderName, forKey: "DoubtFolderName")
}
self.prefs.synchronize()
}else{
if response?.object(forKey: "isLogout") != nil && !
(response?.object(forKey: "isLogout") is NSNull){
if response?.object(forKey: "isLogout") as! Bool{
self.showLogOutAlertView(message: response?.object(forKey:
"message") as! String)
}
}else{
self.view.makeToast(message: response?.object(forKey:
"message") as! String)
}
}
})
}
func fireUploadPendingNotification(){
let localNotification = UILocalNotification()
localNotification.soundName = UILocalNotificationDefaultSoundName
localNotification.alertBody = "Some uploads are still pending. Tap the
refresh button to upload."
localNotification.alertTitle = "ExM"
localNotification.fireDate = Date()
UIApplication.shared.scheduleLocalNotification(localNotification)
}