Skip to content

Commit 1809a33

Browse files
NMC 1988 - Scan customisation changes
1 parent 172454f commit 1809a33

4 files changed

Lines changed: 135 additions & 165 deletions

File tree

iOSClient/Scan document/NCCreateFormUploadScanDocument.swift

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -141,47 +141,44 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
141141

142142
var section: XLFormSectionDescriptor
143143
var row: XLFormRowDescriptor
144-
144+
145145
// Section: Destination Folder
146146

147-
section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_save_path_", comment: ""))
147+
section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_save_path_", comment: "").uppercased())
148+
section.footerTitle = ""
148149
form.addFormSection(section)
149-
150-
XLFormViewController.cellClassesForRowDescriptorTypes()["NMCScamFileNameCustomInputField"] = FileNameInputTextField.self
151-
row = XLFormRowDescriptor(tag: "fileName", rowType: "NMCScamFileNameCustomInputField", title: NSLocalizedString("_filename_", comment: ""))
152-
row.cellClass = FileNameInputTextField.self
153-
row.cellConfig["fileNameInputTextField.placeholder"] = self.fileName
154-
155-
row.cellConfig["fileNameInputTextField.textAlignment"] = NSTextAlignment.left.rawValue
156-
row.cellConfig["fileNameInputTextField.font"] = UIFont.systemFont(ofSize: 15.0)
157-
row.cellConfig["fileNameInputTextField.textColor"] = NCBrandColor.shared.label
158-
159-
160-
section.addFormRow(row)
161-
//FileName custom view END
162-
163-
section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_location_", comment: ""))
164-
form.addFormSection(section)
165-
166-
//Scan documnet folder path
167-
XLFormViewController.cellClassesForRowDescriptorTypes()["NMCScanFolderPathCustomCell"] = ScanDocumentPathView.self
168-
row = XLFormRowDescriptor(tag: "ButtonDestinationFolder", rowType: "NMCScanFolderPathCustomCell", title: self.titleServerUrl)
150+
151+
XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCFolderCustomCellType"] = FolderPathCustomCell.self
152+
row = XLFormRowDescriptor(tag: "ButtonDestinationFolder", rowType: "kNMCFolderCustomCellType", title: self.titleServerUrl)
153+
row.cellConfig["backgroundColor"] = UIColor.secondarySystemGroupedBackground
169154
row.action.formSelector = #selector(changeDestinationFolder(_:))
170-
row.cellConfig["backgroundColor"] = cellBackgoundColor
171-
row.cellConfig["folderImage.image"] = UIImage(named: "folder")?.imageColor(NCBrandColor.shared.customer)
155+
row.cellConfig["folderImage.image"] = UIImage(named: "folder_nmcloud")?.image(color: NCBrandColor.shared.brandElement, size: 25)
172156
row.cellConfig["photoLabel.textAlignment"] = NSTextAlignment.left.rawValue
173157
row.cellConfig["photoLabel.font"] = UIFont.systemFont(ofSize: 15.0)
174-
row.cellConfig["photoLabel.textColor"] = NCBrandColor.shared.label
158+
row.cellConfig["photoLabel.textColor"] = UIColor.label //photos
175159
if(self.titleServerUrl == "/"){
176160
row.cellConfig["photoLabel.text"] = NSLocalizedString("_prefix_upload_path_", comment: "")
177161
}else{
178162
row.cellConfig["photoLabel.text"] = self.titleServerUrl
179163
}
180164
row.cellConfig["textLabel.text"] = ""
181-
182165
section.addFormRow(row)
183-
// END of Scan documnet folder path
166+
167+
// Section: File Name
168+
169+
XLFormViewController.cellClassesForRowDescriptorTypes()["kMyAppCustomCellType"] = TextTableViewCell.self
184170

171+
section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_filename_", comment: "").uppercased())
172+
form.addFormSection(section)
173+
174+
row = XLFormRowDescriptor(tag: "fileName", rowType: "kMyAppCustomCellType", title: NSLocalizedString("_filename_", comment: ""))
175+
row.cellClass = TextTableViewCell.self
176+
row.cellConfigAtConfigure["backgroundColor"] = UIColor.secondarySystemGroupedBackground;
177+
row.cellConfig["fileNameTextField.textAlignment"] = NSTextAlignment.left.rawValue
178+
row.cellConfig["fileNameTextField.font"] = UIFont.systemFont(ofSize: 15.0)
179+
row.cellConfig["fileNameTextField.textColor"] = UIColor.label
180+
row.cellConfig["fileNameTextField.text"] = self.fileName
181+
section.addFormRow(row)
185182

186183
section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_save_with_text_recognition_", comment: ""))
187184
form.addFormSection(section)
@@ -309,7 +306,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
309306
let fileNameNew = newValue as? String
310307

311308
if let fileNameNew = newValue as? String {
312-
self.fileName = utility.removeForbiddenCharacters(fileNameNew)
309+
self.fileName = FileAutoRenamer.rename(fileNameNew, account: session.account)
313310
} else {
314311
self.fileName = ""
315312
}
@@ -456,7 +453,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
456453
var newFileName: String = ""
457454

458455
if fileName == nil || fileName == "" {
459-
name = utilityFileSystem.createFileNameDate("scan", ext: "pdf")
456+
name = utilityFileSystem.createFileNameDate("scan", ext: "pdf")
460457
} else {
461458
name = fileName!
462459
}
@@ -717,8 +714,9 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
717714
metadataForUpload.session = NCNetworking.shared.sessionUploadBackground
718715
metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile
719716
metadataForUpload.status = NCGlobal.shared.metadataStatusWaitUpload
720-
717+
721718
if NCManageDatabase.shared.getMetadataConflict(account: session.account, serverUrl: serverUrl, fileNameView: fileNameSave, nativeFormat: false) != nil {
719+
722720

723721
guard let conflictViewController = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict else { return }
724722
conflictViewController.textLabelDetailNewFile = NSLocalizedString("_now_", comment: "")
@@ -771,7 +769,6 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
771769
}
772770
}
773771

774-
775772
let metadataForUpload = NCManageDatabase.shared.createMetadata(fileName: fileNameSave, fileNameView: fileNameSave, ocId: UUID().uuidString, serverUrl: serverUrl, url: "", contentType: "", session: session, sceneIdentifier: self.appDelegate?.sceneIdentifier)
776773

777774
metadataForUpload.session = NCNetworking.shared.sessionUploadBackground
@@ -849,8 +846,9 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
849846
metadataForUpload.session = NCNetworking.shared.sessionUploadBackground
850847
metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile
851848
metadataForUpload.status = NCGlobal.shared.metadataStatusWaitUpload
852-
849+
853850
if NCManageDatabase.shared.getMetadataConflict(account: session.account, serverUrl: serverUrl, fileNameView: fileNameSave, nativeFormat: false) != nil {
851+
854852

855853
guard let conflictViewController = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict else { return }
856854
conflictViewController.textLabelDetailNewFile = NSLocalizedString("_now_", comment: "")
@@ -1060,6 +1058,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
10601058
// let image = changeCompressionImage(self.arrayImages[0])
10611059
guard let data = image.jpegData(compressionQuality: CGFloat(0.5)) else {
10621060
NCActivityIndicator.shared.stop()
1061+
contentPresenter.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_"), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
10631062
contentPresenter.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: NSLocalizedString("_error_creation_file_", comment: "")), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
10641063
return
10651064
}
@@ -1068,6 +1067,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
10681067
try data.write(to: fileUrl, options: .atomic)
10691068
} catch {
10701069
NCActivityIndicator.shared.stop()
1070+
contentPresenter.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_"), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
10711071
contentPresenter.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: NSLocalizedString("_error_creation_file_", comment: "")), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
10721072
return
10731073
}
@@ -1084,6 +1084,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
10841084
// let image = changeCompressionImage(self.arrayImages[0])
10851085
guard let data = image.jpegData(compressionQuality: CGFloat(0.5)) else {
10861086
NCActivityIndicator.shared.stop()
1087+
contentPresenter.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_"), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
10871088
contentPresenter.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: NSLocalizedString("_error_creation_file_", comment: "")), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
10881089
return
10891090
}
@@ -1092,6 +1093,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
10921093
try data.write(to: NSURL.fileURL(withPath: fileNameGenerateExport), options: .atomic)
10931094
} catch {
10941095
NCActivityIndicator.shared.stop()
1096+
contentPresenter.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: "_error_creation_file_"), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
10951097
contentPresenter.messageNotification("_error_", error: NKError(errorCode: NCGlobal.shared.errorCreationFile, errorDescription: NSLocalizedString("_error_creation_file_", comment: "")), delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info)
10961098
return
10971099
}
@@ -1265,4 +1267,3 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
12651267
return nil
12661268
}
12671269
}
1268-

iOSClient/Scan document/NCDocumentCamera.swift

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ class NCDocumentCamera: NSObject, VNDocumentCameraViewControllerDelegate {
3333
}()
3434
var viewController: UIViewController?
3535
let utilityFileSystem = NCUtilityFileSystem()
36-
var controller: NCMainTabBarController!
37-
var session: NCSession.Session {
38-
NCSession.shared.getSession(controller: controller)
39-
}
4036

4137
func openScannerDocument(viewController: UIViewController?) {
4238
guard VNDocumentCameraViewController.isSupported else { return }
@@ -50,7 +46,7 @@ class NCDocumentCamera: NSObject, VNDocumentCameraViewControllerDelegate {
5046
func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
5147
for pageNumber in 0..<scan.pageCount {
5248
let fileName = utilityFileSystem.createFileName("scan.png", fileDate: Date(), fileType: PHAssetMediaType.image, notUseMask: true)
53-
let fileNamePath = utilityFileSystem.createServerUrl(serverUrl: utilityFileSystem.directoryScan, fileName: fileName)
49+
let fileNamePath = utilityFileSystem.directoryScan + "/" + fileName
5450
let image = scan.imageOfPage(at: pageNumber)
5551
do {
5652
try image.pngData()?.write(to: NSURL.fileURL(withPath: fileNamePath))
@@ -60,68 +56,20 @@ class NCDocumentCamera: NSObject, VNDocumentCameraViewControllerDelegate {
6056
controller.dismiss(animated: true) {
6157
if let viewController = self.viewController as? NCScan {
6258
viewController.loadImage()
63-
} else {
64-
self.reDirectToSave()
59+
} else if let controller = self.viewController as? NCMainTabBarController {
60+
if let navigationController = UIStoryboard(name: "NCScan", bundle: nil).instantiateInitialViewController() {
61+
navigationController.modalPresentationStyle = UIModalPresentationStyle.pageSheet
62+
if let viewController = navigationController.topMostViewController() as? NCScan {
63+
viewController.serverUrl = controller.currentServerUrl()
64+
viewController.controller = controller
65+
}
66+
self.viewController?.present(navigationController, animated: true, completion: nil)
67+
}
6568
}
6669
}
6770
}
6871

6972
func documentCameraViewControllerDidCancel(_ controller: VNDocumentCameraViewController) {
7073
controller.dismiss(animated: true, completion: nil)
7174
}
72-
73-
func reDirectToSave(){
74-
var itemsSource: [String] = []
75-
76-
//Data Source for collectionViewDestination
77-
var imagesDestination: [UIImage] = []
78-
var itemsDestination: [String] = []
79-
80-
do {
81-
let atPath = utilityFileSystem.directoryScan
82-
let directoryContents = try FileManager.default.contentsOfDirectory(atPath: atPath)
83-
for fileName in directoryContents {
84-
if fileName.first != "." {
85-
itemsSource.append(fileName)
86-
}
87-
}
88-
} catch {
89-
print(error.localizedDescription)
90-
}
91-
92-
itemsSource = itemsSource.sorted()
93-
94-
for fileName in itemsSource {
95-
96-
if !itemsDestination.contains(fileName) {
97-
98-
let fileNamePathAt = utilityFileSystem.directoryScan + "/" + fileName
99-
100-
guard let data = try? Data(contentsOf: URL(fileURLWithPath: fileNamePathAt)) else { return }
101-
guard let image = UIImage(data: data) else { return }
102-
103-
imagesDestination.append(image)
104-
itemsDestination.append(fileName)
105-
}
106-
}
107-
108-
if imagesDestination.count > 0 {
109-
110-
var images: [UIImage] = []
111-
let controller = self.viewController as? NCMainTabBarController
112-
let serverUrl = controller?.currentServerUrl() ?? ""
113-
114-
for image in imagesDestination {
115-
images.append(image)
116-
}
117-
118-
let formViewController = NCCreateFormUploadScanDocument.init(serverUrl: serverUrl, arrayImages: images)
119-
120-
formViewController.modalPresentationStyle = UIModalPresentationStyle.pageSheet
121-
122-
let navigationController = UINavigationController(rootViewController: formViewController)
123-
124-
self.viewController?.present(navigationController, animated: true, completion: nil)
125-
}
126-
}
12775
}

0 commit comments

Comments
 (0)