diff --git a/MiniScanner.xcodeproj/project.xcworkspace/xcuserdata/g.makhoul.xcuserdatad/UserInterfaceState.xcuserstate b/MiniScanner.xcodeproj/project.xcworkspace/xcuserdata/g.makhoul.xcuserdatad/UserInterfaceState.xcuserstate index 787c067a49dc400b3c3a95141f09412aae430808..e35880c34059704b99e69a882e15e8ab51313bfd 100644 Binary files a/MiniScanner.xcodeproj/project.xcworkspace/xcuserdata/g.makhoul.xcuserdatad/UserInterfaceState.xcuserstate and b/MiniScanner.xcodeproj/project.xcworkspace/xcuserdata/g.makhoul.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MiniScanner.xcodeproj/xcuserdata/g.makhoul.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/MiniScanner.xcodeproj/xcuserdata/g.makhoul.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 41b4c5eb091557c5280fe24930a666f26e5a867f..dbacdbf504f824340ba8bdea436848a886afcf75 100644 --- a/MiniScanner.xcodeproj/xcuserdata/g.makhoul.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/MiniScanner.xcodeproj/xcuserdata/g.makhoul.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -7,113 +7,162 @@ <BreakpointProxy BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> <BreakpointContent - uuid = "37FD8431-0BDC-4C4D-9E3F-970150E09A93" + uuid = "C9F00BF4-C6CA-46CF-88C1-D6C136A99CC8" + shouldBeEnabled = "No" + ignoreCount = "0" + continueAfterRunningActions = "No" + filePath = "MiniScanner/Managers/PDFManager.swift" + startingColumnNumber = "9223372036854775807" + endingColumnNumber = "9223372036854775807" + startingLineNumber = "40" + endingLineNumber = "40" + landmarkName = "createPDFDocument(from:localFileManager:folder:)" + landmarkType = "7"> + </BreakpointContent> + </BreakpointProxy> + <BreakpointProxy + BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> + <BreakpointContent + uuid = "F97C672E-FAE1-41EE-8640-5347A8A2BA71" + shouldBeEnabled = "No" + ignoreCount = "0" + continueAfterRunningActions = "No" + filePath = "MiniScanner/Managers/PDFManager.swift" + startingColumnNumber = "9223372036854775807" + endingColumnNumber = "9223372036854775807" + startingLineNumber = "41" + endingLineNumber = "41" + landmarkName = "createPDFDocument(from:localFileManager:folder:)" + landmarkType = "7"> + </BreakpointContent> + </BreakpointProxy> + <BreakpointProxy + BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> + <BreakpointContent + uuid = "A8D940DE-7CBB-4B92-A0C2-8D5144B0AABE" + shouldBeEnabled = "No" + ignoreCount = "0" + continueAfterRunningActions = "No" + filePath = "MiniScanner/Managers/PDFManager.swift" + startingColumnNumber = "9223372036854775807" + endingColumnNumber = "9223372036854775807" + startingLineNumber = "42" + endingLineNumber = "42" + landmarkName = "createPDFDocument(from:localFileManager:folder:)" + landmarkType = "7"> + </BreakpointContent> + </BreakpointProxy> + <BreakpointProxy + BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> + <BreakpointContent + uuid = "CBC66187-FF67-492E-B004-F82F437F35AE" shouldBeEnabled = "Yes" ignoreCount = "0" continueAfterRunningActions = "No" - filePath = "MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/AllFolderTableViewCell.swift" + filePath = "MiniScanner/Modules/Documents/DocumentsTableViewController.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "53" - endingLineNumber = "53" - landmarkName = "collectionView(_:cellForItemAt:)" + startingLineNumber = "67" + endingLineNumber = "67" + landmarkName = "fetchViewModels()" landmarkType = "7"> - <Locations> - <Location - uuid = "37FD8431-0BDC-4C4D-9E3F-970150E09A93 - a4d5abeef222e8f1" - shouldBeEnabled = "Yes" - ignoreCount = "0" - continueAfterRunningActions = "No" - symbolName = "MiniScanner.AllFolderTableViewCell.collectionView(_: __C.UICollectionView, cellForItemAt: Foundation.IndexPath) -> __C.UICollectionViewCell" - moduleName = "MiniScanner" - usesParentBreakpointCondition = "Yes" - urlString = "file:///Users/g.makhoul/Downloads/miniscanner-1.0.3(6)/MiniScanner/MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/AllFolderTableViewCell.swift" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "57" - endingLineNumber = "57" - offsetFromSymbolStart = "820"> - </Location> - <Location - uuid = "37FD8431-0BDC-4C4D-9E3F-970150E09A93 - a4d5abeef222e875" - shouldBeEnabled = "Yes" - ignoreCount = "0" - continueAfterRunningActions = "No" - symbolName = "MiniScanner.AllFolderTableViewCell.collectionView(_: __C.UICollectionView, cellForItemAt: Foundation.IndexPath) -> __C.UICollectionViewCell" - moduleName = "MiniScanner" - usesParentBreakpointCondition = "Yes" - urlString = "file:///Users/g.makhoul/Downloads/miniscanner-1.0.3(6)/MiniScanner/MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/AllFolderTableViewCell.swift" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "53" - endingLineNumber = "53" - offsetFromSymbolStart = "820"> - </Location> - </Locations> </BreakpointContent> </BreakpointProxy> <BreakpointProxy BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> <BreakpointContent - uuid = "2F53B704-9817-4CEA-8BA8-B5F04FB7260F" + uuid = "C319AF25-4C3B-4E3A-AD5E-CAF918C19CD7" shouldBeEnabled = "Yes" ignoreCount = "0" continueAfterRunningActions = "No" - filePath = "MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/AllFolderTableViewCell.swift" + filePath = "MiniScanner/Modules/Documents/DocumentsTableViewController.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "51" - endingLineNumber = "51" - landmarkName = "collectionView(_:cellForItemAt:)" + startingLineNumber = "68" + endingLineNumber = "68" + landmarkName = "fetchViewModels()" + landmarkType = "7"> + </BreakpointContent> + </BreakpointProxy> + <BreakpointProxy + BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> + <BreakpointContent + uuid = "6A30A7DC-0D3F-4C1B-9797-3264CBB0D81A" + shouldBeEnabled = "Yes" + ignoreCount = "0" + continueAfterRunningActions = "No" + filePath = "MiniScanner/Modules/Documents/DocumentsTableViewController.swift" + startingColumnNumber = "9223372036854775807" + endingColumnNumber = "9223372036854775807" + startingLineNumber = "69" + endingLineNumber = "69" + landmarkName = "fetchViewModels()" landmarkType = "7"> <Locations> <Location - uuid = "2F53B704-9817-4CEA-8BA8-B5F04FB7260F - a4d5abeef222e8b7" - shouldBeEnabled = "Yes" - ignoreCount = "0" - continueAfterRunningActions = "No" - symbolName = "MiniScanner.AllFolderTableViewCell.collectionView(_: __C.UICollectionView, cellForItemAt: Foundation.IndexPath) -> __C.UICollectionViewCell" - moduleName = "MiniScanner" - usesParentBreakpointCondition = "Yes" - urlString = "file:///Users/g.makhoul/Downloads/miniscanner-1.0.3(6)/MiniScanner/MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/AllFolderTableViewCell.swift" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "55" - endingLineNumber = "55" - offsetFromSymbolStart = "848"> - </Location> - <Location - uuid = "2F53B704-9817-4CEA-8BA8-B5F04FB7260F - a4d5abeef222e8b7" + uuid = "6A30A7DC-0D3F-4C1B-9797-3264CBB0D81A - ccf72e1ebd4694bb" shouldBeEnabled = "Yes" ignoreCount = "0" continueAfterRunningActions = "No" - symbolName = "MiniScanner.AllFolderTableViewCell.collectionView(_: __C.UICollectionView, cellForItemAt: Foundation.IndexPath) -> __C.UICollectionViewCell" + symbolName = "MiniScanner.DocumentsTableViewController.fetchViewModels() -> ()" moduleName = "MiniScanner" usesParentBreakpointCondition = "Yes" - urlString = "file:///Users/g.makhoul/Downloads/miniscanner-1.0.3(6)/MiniScanner/MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/AllFolderTableViewCell.swift" + urlString = "file:///Users/g.makhoul/Downloads/miniscanner-1.0.3(6)/MiniScanner/MiniScanner/Modules/Documents/DocumentsTableViewController.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "55" - endingLineNumber = "55" - offsetFromSymbolStart = "168"> + startingLineNumber = "69" + endingLineNumber = "69" + offsetFromSymbolStart = "844"> </Location> <Location - uuid = "2F53B704-9817-4CEA-8BA8-B5F04FB7260F - a4d5abeef222e83b" + uuid = "6A30A7DC-0D3F-4C1B-9797-3264CBB0D81A - ccf72e1ebd4694bb" shouldBeEnabled = "Yes" ignoreCount = "0" continueAfterRunningActions = "No" - symbolName = "MiniScanner.AllFolderTableViewCell.collectionView(_: __C.UICollectionView, cellForItemAt: Foundation.IndexPath) -> __C.UICollectionViewCell" + symbolName = "MiniScanner.DocumentsTableViewController.fetchViewModels() -> ()" moduleName = "MiniScanner" usesParentBreakpointCondition = "Yes" - urlString = "file:///Users/g.makhoul/Downloads/miniscanner-1.0.3(6)/MiniScanner/MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/AllFolderTableViewCell.swift" + urlString = "file:///Users/g.makhoul/Downloads/miniscanner-1.0.3(6)/MiniScanner/MiniScanner/Modules/Documents/DocumentsTableViewController.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "51" - endingLineNumber = "51" - offsetFromSymbolStart = "168"> + startingLineNumber = "69" + endingLineNumber = "69" + offsetFromSymbolStart = "1732"> </Location> </Locations> </BreakpointContent> </BreakpointProxy> + <BreakpointProxy + BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> + <BreakpointContent + uuid = "51B310ED-1E7A-421E-AB99-4CC3C4B646CE" + shouldBeEnabled = "Yes" + ignoreCount = "0" + continueAfterRunningActions = "No" + filePath = "MiniScanner/Modules/Documents/DocumentsTableViewController.swift" + startingColumnNumber = "9223372036854775807" + endingColumnNumber = "9223372036854775807" + startingLineNumber = "70" + endingLineNumber = "70" + landmarkName = "fetchViewModels()" + landmarkType = "7"> + </BreakpointContent> + </BreakpointProxy> + <BreakpointProxy + BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> + <BreakpointContent + uuid = "9CCD7A4D-6524-4B72-9CCD-82FDD07A1FC5" + shouldBeEnabled = "Yes" + ignoreCount = "0" + continueAfterRunningActions = "No" + filePath = "MiniScanner/Modules/Documents/DocumentsTableViewController.swift" + startingColumnNumber = "9223372036854775807" + endingColumnNumber = "9223372036854775807" + startingLineNumber = "71" + endingLineNumber = "71" + landmarkName = "fetchViewModels()" + landmarkType = "7"> + </BreakpointContent> + </BreakpointProxy> </Breakpoints> </Bucket> diff --git a/MiniScanner/Managers/LocalFileManager.swift b/MiniScanner/Managers/LocalFileManager.swift index ca431f559496b38d91f557ab196f3acad2b9a828..3859467babb96642773cd5dfb6d436153177615c 100644 --- a/MiniScanner/Managers/LocalFileManager.swift +++ b/MiniScanner/Managers/LocalFileManager.swift @@ -17,7 +17,7 @@ class LocalFileManager { } var scannerURL: URL { - let iFinderURL = documentsURL.appendingPathComponent(AppConfigurator.DocumentsFolderName, isDirectory: true) + let iFinderURL = documentsURL.appendingPathComponent(AppConfigurator.Folders.AllDocument.rawValue, isDirectory: true) /// Check if file not exist and create if !filesManager.fileExists(atPath: iFinderURL.path) { try? filesManager.createDirectory(at: iFinderURL, withIntermediateDirectories: true, attributes: nil) @@ -25,6 +25,16 @@ class LocalFileManager { return iFinderURL } + + func getFolderUrl(folder: AppConfigurator.Folder) -> URL { + let iFinderURL = documentsURL.appendingPathComponent(folder.savedName, isDirectory: true) + /// Check if file not exist and create + if !filesManager.fileExists(atPath: iFinderURL.path) { + try? filesManager.createDirectory(at: iFinderURL, withIntermediateDirectories: true, attributes: nil) + } + + return iFinderURL + } /// Mapped for case insensitivity var excludesFileExtensions: [String]? { diff --git a/MiniScanner/Managers/PDFManager.swift b/MiniScanner/Managers/PDFManager.swift index c51b863daf1c7d597ca066d925482ffc3b4791f8..623a17da34c1d7c63a8b18d14f272c4b62e7af48 100644 --- a/MiniScanner/Managers/PDFManager.swift +++ b/MiniScanner/Managers/PDFManager.swift @@ -36,8 +36,8 @@ class PDFManager { return page.thumbnail(of: screenSize, for: .mediaBox) } - class func createPDFDocument(from image: UIImage, localFileManager: LocalFileManager?) { - guard let scannerURL = localFileManager?.scannerURL else { return } + class func createPDFDocument(from image: UIImage, localFileManager: LocalFileManager?, folder: AppConfigurator.Folder) { + guard let scannerURL = localFileManager?.getFolderUrl(folder: folder) else { return } let urlPDFtoSave = scannerURL.appendingPathComponent(String.getDocumentName()) let document = PDFDocument() @@ -63,37 +63,9 @@ class PDFManager { print(error.localizedDescription) } } - - // Create PDF from images - // images - array of uiimages - // urlPDFtoSave - it must be a local pdf url with .pdf extension, otherwise it will be saved as data - // url example: let urlPDFtoSave = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("file.pdf") - -// class func createMultiPDFPage(from images: [UIImage], localFileManager: LocalFileManager?, _ completion: @escaping () -> ()) { -// guard let scannerURL = localFileManager?.scannerURL else { return } -// let urlPDFtoSave = scannerURL.appendingPathComponent(String.getDocumentName()) -// -// if images.isEmpty { return } -// let document = PDFDocument() -// -// // Iterrate trough images -// for (index, image) in images.enumerated() { -// if let pdfPage = PDFPage(image: image) { -// document.insert(pdfPage, at: index) -// } -// if document.pageCount == images.count { -// do { -// try document.dataRepresentation()?.write(to: urlPDFtoSave) -// completion() -// } catch { -// print(error.localizedDescription) // handle error -// } -// } -// } -// } - class func createMultiPDFPage(from imageURLs: [URL], localFileManager: LocalFileManager?, _ completion: @escaping () -> ()) { - guard let scannerURL = localFileManager?.scannerURL else { return } + class func createMultiPDFPage(from imageURLs: [URL], localFileManager: LocalFileManager?, folder: AppConfigurator.Folder, _ completion: @escaping () -> ()) { + guard let scannerURL = localFileManager?.getFolderUrl(folder: folder) else { return } let urlPDFtoSave = scannerURL.appendingPathComponent(String.getDocumentName()) if imageURLs.isEmpty { return } diff --git a/MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/AllFolderTableViewCell.swift b/MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/AllFolderTableViewCell.swift index 742127ebf8d3072d3924dff03b51748033827656..bd730315d1c0f46c50f9244388d35f1b9154465c 100644 --- a/MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/AllFolderTableViewCell.swift +++ b/MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/AllFolderTableViewCell.swift @@ -8,11 +8,17 @@ import UIKit +protocol AllFolderTableViewCellDelegate { + func cellTapped(folder: AppConfigurator.Folder) +} + final class AllFolderTableViewCell: UIView { // MARK: - Outlets @IBOutlet weak var collectionView: UICollectionView! // MARK: - Properties + var folders: [AppConfigurator.Folder] = [] + var delegate: AllFolderTableViewCellDelegate? // MARK: - LifeCycle override func awakeFromNib() { @@ -29,7 +35,19 @@ final class AllFolderTableViewCell: UIView { self.collectionView.delegate = self self.collectionView.dataSource = self self.collectionView.register(UINib(nibName: "FolderCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "FolderCollectionViewCell") - + folders = AppConfigurator().getFolders() + self.collectionView.reloadData() + } + + func set(selectedFolder: AppConfigurator.Folder, delegate: AllFolderTableViewCellDelegate? ) { + self.delegate = delegate + for (index, _) in folders.enumerated() { + if folders[index].savedName == selectedFolder.savedName { + folders[index].isSelected = true + } else { + folders[index].isSelected = false + } + } self.collectionView.reloadData() } } @@ -44,16 +62,25 @@ extension AllFolderTableViewCell: UICollectionViewDelegateFlowLayout { extension AllFolderTableViewCell: UICollectionViewDelegate, UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - 5 + folders.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FolderCollectionViewCell", for: indexPath) as? FolderCollectionViewCell { - cell.set(title: "title \(indexPath.row)") + cell.set(folder: folders[indexPath.row]) return cell } return UICollectionViewCell() } + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + for (index, _) in folders.enumerated() { + folders[index].isSelected = false + } + folders[indexPath.row].isSelected = true + collectionView.reloadData() + delegate?.cellTapped(folder: folders[indexPath.row]) + } + } diff --git a/MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/CustomCells/FolderCollectionViewCell.swift b/MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/CustomCells/FolderCollectionViewCell.swift index e6668dd351a88ad6139f5eade32bd7bb5942087a..354beffd59d8852ab392ccf4bb432cc219234c37 100644 --- a/MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/CustomCells/FolderCollectionViewCell.swift +++ b/MiniScanner/Modules/Documents/CustomCells/AllFolderTableViewCell/CustomCells/FolderCollectionViewCell.swift @@ -14,6 +14,7 @@ class FolderCollectionViewCell: UICollectionViewCell { @IBOutlet weak var titleLabel: UILabel! // MARK: - Properties + var isFolderSelected: Bool = false // MARK: - LifeCycle override func awakeFromNib() { @@ -32,7 +33,14 @@ class FolderCollectionViewCell: UICollectionViewCell { } - func set(title: String) { - self.titleLabel.text = title + private func setSelected() { + self.titleLabel.textColor = isFolderSelected ? .white : .black + self.boxView.backgroundColor = isFolderSelected ? .blue : .white + } + + func set(folder: AppConfigurator.Folder) { + self.titleLabel.text = folder.name + isFolderSelected = folder.isSelected + setSelected() } } diff --git a/MiniScanner/Modules/Documents/DocumentsTableViewController.swift b/MiniScanner/Modules/Documents/DocumentsTableViewController.swift index a630bdd24025056d6e80fd4224ab32cfa70e2e98..3c11fa76131ab39694f101dd2460956009db6e03 100644 --- a/MiniScanner/Modules/Documents/DocumentsTableViewController.swift +++ b/MiniScanner/Modules/Documents/DocumentsTableViewController.swift @@ -6,7 +6,6 @@ final class DocumentsTableViewController: UITableViewController { struct Constants { static let reuseIdentifier = String(describing: DocumentsTableViewController.self) static let storyboardName = "Documents" - static let title = Bundle.appName static let rowHeight: CGFloat = 96 static let cellReuseIdentifier = String(describing: DocumentsTableViewCell.self) @@ -27,6 +26,7 @@ final class DocumentsTableViewController: UITableViewController { // private let noDocumentsimageView = UIImageView(image: UIImage(named: "box")) private var renameAlertController: UIAlertController? private var renameFileName: String? + private var selectedFolder: AppConfigurator.Folder? override func viewDidLoad() { super.viewDidLoad() @@ -50,6 +50,12 @@ final class DocumentsTableViewController: UITableViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) + let savedFolders = AppConfigurator().getFolders() + for item in savedFolders { + if item.isSelected == true { + selectedFolder = item + } + } fetchViewModels() } @@ -58,11 +64,12 @@ final class DocumentsTableViewController: UITableViewController { } @objc private func fetchViewModels() { - - guard let directoryURL = localFileManager?.scannerURL, - let viewModels = localFileManager?.filesForDirectory(directoryURL, sortType: sortType) else { return } - self.viewModels = viewModels - tableView.reloadData() + if let folder = selectedFolder { + guard let directoryURL = localFileManager?.getFolderUrl(folder: folder), + let viewModels = localFileManager?.filesForDirectory(directoryURL, sortType: sortType) else { return } + self.viewModels = viewModels + tableView.reloadData() + } } // MARK: - Table view data source @@ -80,6 +87,9 @@ final class DocumentsTableViewController: UITableViewController { override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let nib = UINib(nibName: "AllFolderTableViewCell", bundle: nil) let header = nib.instantiate(withOwner: nil, options: nil).first as? AllFolderTableViewCell + if let folder = selectedFolder { + header?.set(selectedFolder: folder, delegate: self) + } return header } @@ -272,8 +282,10 @@ extension DocumentsTableViewController: UINavigationControllerDelegate, UIImageP picker.dismiss(animated: true) { [weak self] in guard let self = self else { return } guard let image = info[UserDefaults.standard.isPhotoEditigOn ? UIImagePickerController.InfoKey.editedImage : UIImagePickerController.InfoKey.originalImage] as? UIImage else { return } - PDFManager.createPDFDocument(from: image, localFileManager: self.localFileManager) - self.fetchViewModels() + if let folder = selectedFolder { + PDFManager.createPDFDocument(from: image, localFileManager: self.localFileManager, folder: folder) + self.fetchViewModels() + } } } } @@ -288,10 +300,11 @@ extension DocumentsTableViewController: ImageScannerControllerDelegate { } } print("images: \(images)") - - PDFManager.createMultiPDFPage(from: images, localFileManager: localFileManager) { - scanner.dismiss(animated: true) { - self.fetchViewModels() + if let folder = selectedFolder { + PDFManager.createMultiPDFPage(from: images, localFileManager: localFileManager, folder: folder) { + scanner.dismiss(animated: true) { + self.fetchViewModels() + } } } } @@ -315,3 +328,10 @@ extension DocumentsTableViewController: ImageScannerControllerDelegate { renameAlertController?.actions.first?.isEnabled = true } } + +extension DocumentsTableViewController: AllFolderTableViewCellDelegate { + func cellTapped(folder: AppConfigurator.Folder) { + selectedFolder = folder + fetchViewModels() + } +} diff --git a/MiniScanner/Supporting Files/AppDelegate.swift b/MiniScanner/Supporting Files/AppDelegate.swift index 1e90e340a6c401469025a7638376c17fa37397a9..627a6d8e1e4a01e8ebf7a467cfca7beaef189850 100644 --- a/MiniScanner/Supporting Files/AppDelegate.swift +++ b/MiniScanner/Supporting Files/AppDelegate.swift @@ -6,7 +6,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - ThemeManager.shared.setupTheme() + ThemeManager.shared.setupTheme() + if let savedFolders = UserDefaults.standard.object(forKey: "folders") as? Data { + print("nooo!!") + } else { + AppConfigurator().setDefaults() + } return true } @@ -25,16 +30,51 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } + + } struct AppConfigurator { // Privacy policies and term links - enum Settings: String { - case terms = "https://mistergrizzly.com/terms-and-conditions/" - case privacy = "https://mistergrizzly.com/privacy-policy/" - } - - static let DocumentsFolderName = "ScannerApp" + enum Settings: String { + case terms = "https://mistergrizzly.com/terms-and-conditions/" + case privacy = "https://mistergrizzly.com/privacy-policy/" + } + + enum Folders: String { + case AllDocument = "AllDocument" + } + + struct Folder: Codable { + var name: String + var savedName: String + var isSelected: Bool + } + + func setDefaults() { + let allDocs = AppConfigurator.Folder(name: "All Documents", savedName: "all_documents", isSelected: true) + let passports = AppConfigurator.Folder(name: "Passports", savedName: "passports", isSelected: false) + let contracts = AppConfigurator.Folder(name: "Contracts", savedName: "contracts", isSelected: false) + let identifiers = AppConfigurator.Folder(name: "Identifiers", savedName: "identifiers", isSelected: false) + + let folders = [allDocs, passports, contracts, identifiers] + + if let encoded = try? JSONEncoder().encode(folders) { + UserDefaults.standard.set(encoded, forKey: "folders") + } + } + + func getFolders() -> [Folder] { + if let savedFolders = UserDefaults.standard.object(forKey: "folders") as? Data { + if let loadedFolders = try? JSONDecoder().decode([Folder].self, from: savedFolders) { + return loadedFolders + } else { + return [] + } + } + return [] + } + static let ThumbnailsFolderName = ".ThumbnailImages" }