Skip to content

Commit

Permalink
NMC 1988 - Merging changes after Nextcloud release 4.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
TSI-amrutwaghmare committed Dec 5, 2023
1 parent fe5929d commit 98d944b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 35 deletions.
58 changes: 25 additions & 33 deletions iOSClient/Scan document/NCCreateFormUploadScanDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
var serverUrl = ""
var titleServerUrl = ""
var arrayImages: [UIImage] = []
var fileName = CCUtility.createFileNameDate("scan", extension: "pdf")
var fileName = NCUtilityFileSystem().createFileNameDate("scan", ext: "pdf")
var password: String = ""
var fileType = "PDF"
var isPDFWithOCRSwitchOn = false
Expand All @@ -57,14 +57,17 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC


var cellBackgoundColor = NCBrandColor.shared.secondarySystemGroupedBackground
let utilityFileSystem = NCUtilityFileSystem()
let utility = NCUtility()
let contentPresenter = NCContentPresenter()

// MARK: - View Life Cycle

convenience init(serverUrl: String, arrayImages: [UIImage]) {

self.init()

if serverUrl == NCUtilityFileSystem.shared.getHomeServer(urlBase: appDelegate?.urlBase ?? "", userId: appDelegate?.userId ?? "") {
if serverUrl == utilityFileSystem.getHomeServer(urlBase: appDelegate?.urlBase ?? "", userId: appDelegate?.userId ?? "") {
titleServerUrl = "/"
} else {
titleServerUrl = (serverUrl as NSString).lastPathComponent
Expand Down Expand Up @@ -96,7 +99,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC

initializeForm()

let value = CCUtility.getTextRecognitionStatus()
let value = NCKeychain().textRecognitionStatus
setTextRecognition(newValue: value)
NotificationCenter.default.addObserver(self, selector: #selector(appTerminateNotify), name: UIApplication.willTerminateNotification, object: nil)
}
Expand Down Expand Up @@ -301,8 +304,8 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC

let fileNameNew = newValue as? String

if fileNameNew != nil {
self.fileName = CCUtility.removeForbiddenCharactersServer(fileNameNew)
if let fileNameNew = newValue as? String {
self.fileName = utility.removeForbiddenCharacters(fileNameNew)
} else {
self.fileName = ""
}
Expand Down Expand Up @@ -438,7 +441,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
self.updateFormRow(rowFileName)
self.tableView.reloadData()

CCUtility.setTextRecognitionStatus(newValue)
NCKeychain().textRecognitionStatus = newValue

self.form.delegate = self
}
Expand All @@ -449,7 +452,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
var newFileName: String = ""

if fileName == nil || fileName == "" {
name = CCUtility.createFileNameDate("scan", extension: "pdf") ?? "scan.pdf"
name = utilityFileSystem.createFileNameDate("scan", ext: "pdf")
} else {
name = fileName!
}
Expand All @@ -473,7 +476,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC

self.serverUrl = serverUrl!

if serverUrl == NCUtilityFileSystem.shared.getHomeServer(urlBase: appDelegate?.urlBase ?? "", userId: appDelegate?.userId ?? "") {
if serverUrl == utilityFileSystem.getHomeServer(urlBase: appDelegate?.urlBase ?? "", userId: appDelegate?.userId ?? "") {
self.titleServerUrl = "/"
} else {
self.titleServerUrl = (serverUrl! as NSString).lastPathComponent
Expand Down Expand Up @@ -783,7 +786,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC

fileprivate func showDeleteAlert() {

let path = CCUtility.getDirectoryScan()!
let path = utilityFileSystem.directoryScan

do {
let filePaths = try FileManager.default.contentsOfDirectory(atPath: path)
Expand Down Expand Up @@ -860,16 +863,11 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC

DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
// self.dismissAndUpload(metadataForUpload, fileType: fileType.uppercased())
guard let fileNameGenerateExport = CCUtility.getDirectoryProviderStorageOcId(metadataForUpload.ocId, fileNameView: metadataForUpload.fileNameView) else {
NCActivityIndicator.shared.stop()
let error = NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_")
NCContentPresenter.shared.showError(error: error)
return
}
let fileNameGenerateExport = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadataForUpload.ocId, fileNameView: metadataForUpload.fileNameView)
guard let data = image.jpegData(compressionQuality: CGFloat(0.5)) else {
NCActivityIndicator.shared.stop()
let error = NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_")
NCContentPresenter.shared.showError(error: error)
self.contentPresenter.showError(error: error)
return
}

Expand All @@ -878,7 +876,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
} catch {
NCActivityIndicator.shared.stop()
let error = NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_")
NCContentPresenter.shared.showError(error: error)
self.contentPresenter.showError(error: error)
return
}

Expand Down Expand Up @@ -928,13 +926,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC

func dismissAndUpload(_ metadata: tableMetadata, fileType: String?) {

guard let fileNameGenerateExport = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) else {
NCActivityIndicator.shared.stop()

let error = NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_")
NCContentPresenter.shared.showError(error: error)
return
}
let fileNameGenerateExport = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)
let fileUrl = URL(fileURLWithPath: fileNameGenerateExport)

// Text Recognition TXT
Expand Down Expand Up @@ -972,7 +964,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
} catch {
NCActivityIndicator.shared.stop()
let error = NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_")
NCContentPresenter.shared.showError(error: error)
contentPresenter.showError(error: error)
return
}
}
Expand All @@ -986,7 +978,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
if !char.isASCII {
NCActivityIndicator.shared.stop()
let error = NKError(errorCode: NCGlobal.shared.errorForbidden, errorDescription: "_password_ascii_")
NCContentPresenter.shared.showError(error: error)
contentPresenter.showError(error: error)
return
}
}
Expand Down Expand Up @@ -1065,15 +1057,15 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
// let image = changeCompressionImage(self.arrayImages[0])
guard let data = image.jpegData(compressionQuality: CGFloat(0.5)) else {
NCActivityIndicator.shared.stop()
NCContentPresenter.shared.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_"), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
contentPresenter.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_"), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
return
}

do {
try data.write(to: fileUrl, options: .atomic)
} catch {
NCActivityIndicator.shared.stop()
NCContentPresenter.shared.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_"), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
contentPresenter.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_"), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
return
}
}
Expand All @@ -1089,21 +1081,21 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
// let image = changeCompressionImage(self.arrayImages[0])
guard let data = image.jpegData(compressionQuality: CGFloat(0.5)) else {
NCActivityIndicator.shared.stop()
NCContentPresenter.shared.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_"), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
contentPresenter.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_"), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
return
}

do {
try data.write(to: NSURL.fileURL(withPath: fileNameGenerateExport), options: .atomic)
} catch {
NCActivityIndicator.shared.stop()
NCContentPresenter.shared.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_"), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
contentPresenter.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_"), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
return
}
}
}

metadata.size = NCUtilityFileSystem.shared.getFileSize(filePath: fileNameGenerateExport)
metadata.size = utilityFileSystem.getFileSize(filePath: fileNameGenerateExport)

NCActivityIndicator.shared.stop()

Expand All @@ -1112,9 +1104,9 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
// Request delete all image scanned
let alertController = UIAlertController(title: "", message: NSLocalizedString("_delete_all_scanned_images_", comment: ""), preferredStyle: .alert)

let actionYes = UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (_: UIAlertAction) in
let actionYes = UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { [self] (_: UIAlertAction) in

let path = CCUtility.getDirectoryScan()!
let path = utilityFileSystem.directoryScan

do {
let filePaths = try FileManager.default.contentsOfDirectory(atPath: path)
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/Scan document/NCDocumentCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class NCDocumentCamera: NSObject, VNDocumentCameraViewControllerDelegate {
var itemsDestination: [String] = []

do {
let atPath = CCUtility.getDirectoryScan()!
let atPath = utilityFileSystem.directoryScan
let directoryContents = try FileManager.default.contentsOfDirectory(atPath: atPath)
for fileName in directoryContents {
if fileName.first != "." {
Expand All @@ -101,7 +101,7 @@ class NCDocumentCamera: NSObject, VNDocumentCameraViewControllerDelegate {

if !itemsDestination.contains(fileName) {

let fileNamePathAt = CCUtility.getDirectoryScan() + "/" + fileName
let fileNamePathAt = utilityFileSystem.directoryScan + "/" + fileName

guard let data = try? Data(contentsOf: URL(fileURLWithPath: fileNamePathAt)) else { return }
guard let image = UIImage(data: data) else { return }
Expand Down

0 comments on commit 98d944b

Please sign in to comment.