diff --git a/MiniScanner.xcworkspace/xcuserdata/g.makhoul.xcuserdatad/UserInterfaceState.xcuserstate b/MiniScanner.xcworkspace/xcuserdata/g.makhoul.xcuserdatad/UserInterfaceState.xcuserstate index 4edfe2a03a66e009feb700d877ee697c4199ab6c..4ebdf391b22d71d5fb55a93dbb32af7762d475a6 100644 Binary files a/MiniScanner.xcworkspace/xcuserdata/g.makhoul.xcuserdatad/UserInterfaceState.xcuserstate and b/MiniScanner.xcworkspace/xcuserdata/g.makhoul.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MiniScanner/Modules/EditViewController/EditViewController.swift b/MiniScanner/Modules/EditViewController/EditViewController.swift index b8f250eb6d136bd9845d969b477333c6cb552254..865957d5aaf3d935ac0c9e35a2c6889d207b86c2 100644 --- a/MiniScanner/Modules/EditViewController/EditViewController.swift +++ b/MiniScanner/Modules/EditViewController/EditViewController.swift @@ -61,7 +61,6 @@ public class EditViewController: UIViewController { // MARK: - LifeCycle public override func viewDidLoad() { super.viewDidLoad() - if let session = scanSession { banner.set(session: session) banner.delegate = self @@ -75,9 +74,46 @@ public class EditViewController: UIViewController { localFileManager = LocalFileManager() options = ImageScannerOptions() configImageEditor() + let backButton = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(backTapped)) + self.navigationItem.leftBarButtonItem = backButton } + @objc func backTapped() { + if self.navigationItem.rightBarButtonItem == nil { + self.navigationController?.popViewController(animated: true) + } else { + let alertController = UIAlertController(title: "Alert", message: "Do you want to discard the changes you've made?", preferredStyle: .alert) + + let okAction = UIAlertAction(title: "Yes", style: .default) { (action) in + + self.dismiss(animated: true) { + if let items = self.scanSession?.scannedItems { + for item in items { + item.signtureImage = UIImage() + item.rotate = 0 + item.signaturePosition = .zero + item.screenShot = UIImage() + item.size = .zero + } + self.banner.pagerView.reloadData() + self.navigationItem.rightBarButtonItem = nil + self.overlayView.removeFromSuperview() + self.navigationController?.popViewController(animated: true) + } + } + } + + let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in + self.dismiss(animated: true) + } + + alertController.addAction(okAction) + alertController.addAction(cancelAction) + self.present(alertController, animated: true, completion: nil) + } + } + func configImageEditor() { ZLImageEditorConfiguration.default() .imageStickerContainerView(ImageStickerContainerView()) @@ -180,15 +216,54 @@ public class EditViewController: UIViewController { } @IBAction func continueTapped(_ sender: UIButton) { - let popup = ShareSheetViewController() - popup.session = self.scanSession - popup.isShareShown = false - popup.delegate = self - popup.selectedFolder = self.selectedFolder - let configuration = NBBottomSheetConfiguration(animationDuration: 0.4, sheetSize: .fixed(200)) - - let bottomSheetController = NBBottomSheetController(configuration: configuration) - bottomSheetController.present(popup, on: self) + if self.navigationItem.rightBarButtonItem == nil { + let popup = ShareSheetViewController() + popup.session = self.scanSession + popup.isShareShown = false + popup.delegate = self + popup.selectedFolder = self.selectedFolder + let configuration = NBBottomSheetConfiguration(animationDuration: 0.4, sheetSize: .fixed(200)) + + let bottomSheetController = NBBottomSheetController(configuration: configuration) + bottomSheetController.present(popup, on: self) + } else { + let alertController = UIAlertController(title: "Alert", message: "Do you want to discard the changes you've made and continue?", preferredStyle: .alert) + + let okAction = UIAlertAction(title: "Yes", style: .default) { (action) in + + self.dismiss(animated: true) { + if let items = self.scanSession?.scannedItems { + for item in items { + item.signtureImage = UIImage() + item.rotate = 0 + item.signaturePosition = .zero + item.screenShot = UIImage() + item.size = .zero + } + self.banner.pagerView.reloadData() + self.navigationItem.rightBarButtonItem = nil + self.overlayView.removeFromSuperview() + } + let popup = ShareSheetViewController() + popup.session = self.scanSession + popup.isShareShown = false + popup.delegate = self + popup.selectedFolder = self.selectedFolder + let configuration = NBBottomSheetConfiguration(animationDuration: 0.4, sheetSize: .fixed(200)) + + let bottomSheetController = NBBottomSheetController(configuration: configuration) + bottomSheetController.present(popup, on: self) + } + } + + let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in + self.dismiss(animated: true) + } + + alertController.addAction(okAction) + alertController.addAction(cancelAction) + self.present(alertController, animated: true, completion: nil) + } } public init(scanSession: MultiPageScanSession){ @@ -292,8 +367,9 @@ public class EditViewController: UIViewController { } } isCropping = true - let doneButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.done, target: self, action: #selector(self.onTouchDoneButton)) - self.navigationItem.rightBarButtonItem = doneButton + let cropButton = UIBarButtonItem(title: "Crop", style: .plain, target: self, action: #selector(self.onTouchDoneButton)) + + self.navigationItem.rightBarButtonItem = cropButton self.perform(#selector(setUpCropView), with: self, afterDelay: 0.2) } @@ -398,7 +474,6 @@ extension EditViewController: BannerViewDelegate { images.append(url) } } - print("images: \(images)") if let folder = sharedFolder { PDFManager.createMultiPDFPageAndReturn(from: images, localFileManager: localFileManager, folder: folder, name: name, { document in self.payload = [document] @@ -523,8 +598,9 @@ extension EditViewController: EPSignatureDelegate { self.banner.pagerView.reloadData() } - let doneButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.done, target: self, action: #selector(self.onTouchDoneButton)) - self.navigationItem.rightBarButtonItem = doneButton + let addButton = UIBarButtonItem(title: "Add", style: .plain, target: self, action: #selector(self.onTouchDoneButton)) + + self.navigationItem.rightBarButtonItem = addButton self.dismiss(animated: true) } @@ -542,8 +618,8 @@ extension EditViewController: EPSignatureDelegate { self.banner.pagerView.reloadData() } - let doneButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.done, target: self, action: #selector(self.onTouchDoneButton)) - self.navigationItem.rightBarButtonItem = doneButton + let addButton = UIBarButtonItem(title: "Add", style: .plain, target: self, action: #selector(self.onTouchDoneButton)) + self.navigationItem.rightBarButtonItem = addButton self.dismiss(animated: true) } let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in