Skip to content

Commit 9335a37

Browse files
committed
HomePageDirectoryAdded.
1 parent 009b54b commit 9335a37

6 files changed

Lines changed: 555 additions & 46 deletions

File tree

DocScan.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
BC504CAE2538A57B00DB1870 /* appIconsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC504CAD2538A57B00DB1870 /* appIconsCell.swift */; };
1919
BC504CB32538A5A700DB1870 /* appIconsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC504CB22538A5A700DB1870 /* appIconsVC.swift */; };
2020
BC504CBD2538A8C100DB1870 /* blueIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = BC504CBC2538A8C100DB1870 /* blueIcon.png */; };
21+
BC563F27253F45EC0093C498 /* FileUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC563F26253F45EC0093C498 /* FileUtility.swift */; };
22+
BC563F2C253F49CB0093C498 /* AlertUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC563F2B253F49CB0093C498 /* AlertUtil.swift */; };
23+
BC563F31253F4A290093C498 /* ++UIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC563F30253F4A290093C498 /* ++UIViewController.swift */; };
2124
BC72FAB2253857D50068A286 /* ScanVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC72FAB1253857D50068A286 /* ScanVC.swift */; };
2225
BC72FABB253868C00068A286 /* SettingsTableVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC72FABA253868C00068A286 /* SettingsTableVC.swift */; };
2326
BC911367253870EC0029C0F0 /* ShadowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC911366253870EC0029C0F0 /* ShadowView.swift */; };
@@ -71,6 +74,9 @@
7174
BC504CAD2538A57B00DB1870 /* appIconsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = appIconsCell.swift; sourceTree = "<group>"; };
7275
BC504CB22538A5A700DB1870 /* appIconsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = appIconsVC.swift; sourceTree = "<group>"; };
7376
BC504CBC2538A8C100DB1870 /* blueIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = blueIcon.png; path = "Alternate Icons/blueIcon.png"; sourceTree = SOURCE_ROOT; };
77+
BC563F26253F45EC0093C498 /* FileUtility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUtility.swift; sourceTree = "<group>"; };
78+
BC563F2B253F49CB0093C498 /* AlertUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertUtil.swift; sourceTree = "<group>"; };
79+
BC563F30253F4A290093C498 /* ++UIViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "++UIViewController.swift"; sourceTree = "<group>"; };
7480
BC72FAB1253857D50068A286 /* ScanVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanVC.swift; sourceTree = "<group>"; };
7581
BC72FABA253868C00068A286 /* SettingsTableVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsTableVC.swift; sourceTree = "<group>"; };
7682
BC911366253870EC0029C0F0 /* ShadowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShadowView.swift; sourceTree = "<group>"; };
@@ -177,6 +183,9 @@
177183
BC93B3FD2539A3D800A8DCDB /* PDFCreator.swift */,
178184
BCC5244B25389E0700D717C3 /* AppIconService.swift */,
179185
BCFDF79825384428005F7B99 /* OnboardingVC.swift */,
186+
BC563F26253F45EC0093C498 /* FileUtility.swift */,
187+
BC563F2B253F49CB0093C498 /* AlertUtil.swift */,
188+
BC563F30253F4A290093C498 /* ++UIViewController.swift */,
180189
);
181190
path = "Custom Files";
182191
sourceTree = "<group>";
@@ -578,6 +587,7 @@
578587
BCFDF79925384428005F7B99 /* OnboardingVC.swift in Sources */,
579588
BC72FABB253868C00068A286 /* SettingsTableVC.swift in Sources */,
580589
BC72FAB2253857D50068A286 /* ScanVC.swift in Sources */,
590+
BC563F31253F4A290093C498 /* ++UIViewController.swift in Sources */,
581591
BCFDF79525384428005F7B99 /* AppDelegate.swift in Sources */,
582592
BCFF01D4253A20B00052CBDB /* FoldersCVCell.swift in Sources */,
583593
BCC5244C25389E0700D717C3 /* AppIconService.swift in Sources */,
@@ -586,8 +596,10 @@
586596
BC271E0E2538CC4D009CFA4A /* CustomImageView.swift in Sources */,
587597
BC504CAE2538A57B00DB1870 /* appIconsCell.swift in Sources */,
588598
BC504CB32538A5A700DB1870 /* appIconsVC.swift in Sources */,
599+
BC563F27253F45EC0093C498 /* FileUtility.swift in Sources */,
589600
BC93B3FE2539A3D800A8DCDB /* PDFCreator.swift in Sources */,
590601
BCCED4CC25398FA200E71C0E /* CameraVC.swift in Sources */,
602+
BC563F2C253F49CB0093C498 /* AlertUtil.swift in Sources */,
591603
BCC7727E253A0E3500DF9054 /* CustomTextField.swift in Sources */,
592604
);
593605
runOnlyForDeploymentPostprocessing = 0;

DocScan/Storyboards/Base.lproj/Main.storyboard

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ save any of your data on servers.</string>
159159
</viewController>
160160
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
161161
</objects>
162-
<point key="canvasLocation" x="-248" y="82"/>
162+
<point key="canvasLocation" x="-468" y="82"/>
163163
</scene>
164164
<!--DocScan-->
165165
<scene sceneID="c6O-n8-uKb">
@@ -242,7 +242,9 @@ save any of your data on servers.</string>
242242
</barButtonItem>
243243
</navigationItem>
244244
<connections>
245+
<outlet property="InstructionView" destination="4uk-0x-Pah" id="Re6-0a-jO7"/>
245246
<outlet property="addBttn" destination="fD3-sX-Dtq" id="fre-Qd-d6X"/>
247+
<outlet property="collectionView" destination="CUk-pc-gz0" id="h2D-xU-tmC"/>
246248
<outlet property="emptyView" destination="4uk-0x-Pah" id="6Kz-hp-6HE"/>
247249
</connections>
248250
</viewController>
@@ -491,7 +493,7 @@ save any of your data on servers.</string>
491493
<rect key="frame" x="0.0" y="0.0" width="414" height="759"/>
492494
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
493495
<subviews>
494-
<collectionView hidden="YES" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="T6C-fk-13Y">
496+
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="T6C-fk-13Y">
495497
<rect key="frame" x="0.0" y="462" width="414" height="286"/>
496498
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
497499
<color key="backgroundColor" name="AppGrayColor"/>
@@ -592,7 +594,7 @@ save any of your data on servers.</string>
592594
<connections>
593595
<outlet property="imgView" destination="L7i-hw-ygr" id="SLv-Cv-ULN"/>
594596
<outlet property="imgView2" destination="kIW-hR-5ZX" id="bTk-ZW-8Dy"/>
595-
<outlet property="myCollectionView" destination="T6C-fk-13Y" id="Ipn-kU-E8D"/>
597+
<outlet property="myCollectionView" destination="T6C-fk-13Y" id="qxE-H8-I8V"/>
596598
</connections>
597599
</viewController>
598600
<placeholder placeholderIdentifier="IBFirstResponder" id="DEz-NJ-qgI" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>

DocScan/VCs/1ScanSubVC/ScanVC.swift

Lines changed: 94 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,96 @@ import VisionKit
1212

1313
class ScanVC: UIViewController, UIImagePickerControllerDelegate & UINavigationControllerDelegate,UICollectionViewDelegate,UICollectionViewDataSource{
1414

15+
var workingDirectory : URL?
16+
var allFiles : [File] = []
17+
18+
@IBOutlet var InstructionView: UIView!
19+
@IBOutlet weak var collectionView: UICollectionView!
1520
@IBOutlet var emptyView: UIView!
1621
@IBOutlet weak var addBttn: UIBarButtonItem!
1722

18-
let imgArr = ["FolderIconPurple","FolderIconPink","FolderIconOrange"]
19-
let nameArr = ["Document 1","Document 2","Document 3"]
20-
let dateArr = ["17.10.2020","10.10.2020","11.10.2020"]
23+
//MARK: - Create directory
24+
func gotoDirectory(directory:URL) {
25+
if(directory.lastPathComponent == "DocScanner"){
26+
self.navigationItem.leftBarButtonItem = nil
27+
self.title = "HOME"
28+
}else{
29+
//self.navigationItem.leftBarButtonItem = self.barBackButton
30+
self.title = directory.lastPathComponent.uppercased()
31+
}
32+
self.workingDirectory = directory
33+
reloadTableData()
34+
}
35+
36+
//MARK: -
2137

2238
@IBAction func showaddTapped(_ sender: Any) {
23-
showCamera()
39+
40+
AlertUtil.shared.alertWithTextField(parent: self, title: "Add Folder", message: "Enter folder name to add new folder", placeholder: "Folder Name", value: "", proceedTitle: "Add", cancelTitle: "Later", didProceed: { (folderName) in
41+
let errorMessage = FileUtility.shared.createFolder(directory: self.workingDirectory!, name: folderName)
42+
if(errorMessage != ""){
43+
self.presentAlert(title: "Failed", message: errorMessage)
44+
}else{
45+
// self.presentAlert(title: "Success", message: "Folder added successfully!")
46+
self.reloadTableData()
47+
}
48+
}) {
49+
print("canceled")
50+
}
51+
}
52+
override func viewDidAppear(_ animated: Bool) {
53+
if let directory = self.workingDirectory{
54+
self.allFiles = FileUtility.shared.scanDirectory(directory: directory)
55+
}else{
56+
self.workingDirectory = FileUtility.shared.defaultPath
57+
self.allFiles = FileUtility.shared.scanDirectory(directory: self.workingDirectory!)
58+
}
59+
self.collectionView.reloadData()
60+
}
61+
62+
func reloadTableData() {
63+
self.allFiles.removeAll()
64+
self.allFiles = FileUtility.shared.scanDirectory(directory: self.workingDirectory!)
65+
self.collectionView.reloadData()
66+
}
67+
68+
//MARK:- To create the collectionView on the page
69+
func numberOfSections(in collectionView: UICollectionView) -> Int {
70+
return 1
71+
}
72+
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
73+
return self.allFiles.count
74+
}
75+
76+
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
77+
let cell:FoldersCVCell = collectionView.dequeueReusableCell(withReuseIdentifier: "FoldersCVCell", for: indexPath) as! FoldersCVCell
78+
//cell.imageView.image = UIImage(named: imgArr[indexPath.row])
79+
//cell.dateLabel.text = dateArr[indexPath.row]
80+
//cell.documentName.text = nameArr[indexPath.row]
81+
82+
//cell.imageView?.image = self.allFiles[indexPath.row].image
83+
cell.documentName?.text = self.allFiles[indexPath.row].name
84+
cell.dateLabel?.text = self.allFiles[indexPath.row].size
85+
86+
//cell.menuBttn.addTarget(self, action: #selector(showCamera), for: .touchUpInside)
87+
cell.layer.cornerRadius = 20
88+
return cell
2489
}
2590

91+
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
92+
let selectedFile = self.allFiles[indexPath.row]
93+
switch selectedFile.type{
94+
case .pdf:
95+
self.presentFile(path: selectedFile.path)
96+
break
97+
default:
98+
self.gotoDirectory(directory: selectedFile.url)
99+
break
100+
}
101+
}
102+
103+
// Deprecated
104+
/*
26105
@objc func showCamera(){
27106
let actionSheet = UIAlertController(title: "Select Photo", message: "Where do you want to select a photo?", preferredStyle: .actionSheet)
28107

@@ -48,7 +127,7 @@ class ScanVC: UIViewController, UIImagePickerControllerDelegate & UINavigationCo
48127

49128
self.present(actionSheet, animated: true, completion: nil)
50129
}
51-
130+
*/
52131
override func viewDidLoad() {
53132
super.viewDidLoad()
54133
// To hide the top line
@@ -59,20 +138,7 @@ class ScanVC: UIViewController, UIImagePickerControllerDelegate & UINavigationCo
59138
setUpMenu()
60139
}
61140

62-
//MARK:- To create the collectionView on the page
63-
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
64-
return 3
65-
}
66-
67-
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
68-
let cell:FoldersCVCell = collectionView.dequeueReusableCell(withReuseIdentifier: "FoldersCVCell", for: indexPath) as! FoldersCVCell
69-
cell.imageView.image = UIImage(named: imgArr[indexPath.row])
70-
cell.dateLabel.text = dateArr[indexPath.row]
71-
cell.documentName.text = nameArr[indexPath.row]
72-
cell.menuBttn.addTarget(self, action: #selector(showCamera), for: .touchUpInside)
73-
cell.layer.cornerRadius = 20
74-
return cell
75-
}
141+
76142
//MARK:- Set up uimenu Button
77143

78144
@objc func setUpMenu(){
@@ -103,32 +169,17 @@ class ScanVC: UIViewController, UIImagePickerControllerDelegate & UINavigationCo
103169
}
104170
}
105171

106-
//MARK:- Set up scanner
107-
private func configureDocumentView(){
108-
let scanningDocumentVC = VNDocumentCameraViewController()
109-
scanningDocumentVC.delegate = self
110-
self.present(scanningDocumentVC, animated: true, completion: nil)
111-
}
112-
113172
}
114173

115-
extension ScanVC:VNDocumentCameraViewControllerDelegate {
116-
117-
func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
118-
for pageNumber in 0..<scan.pageCount {
119-
let image = scan.imageOfPage(at: pageNumber)
120-
print(image)
121-
}
122-
controller.dismiss(animated: true, completion: nil)
123-
}
124-
125-
func documentCameraViewControllerDidCancel(_ controller: VNDocumentCameraViewController) {
126-
controller.dismiss(animated: true)
174+
175+
extension ScanVC:UIDocumentInteractionControllerDelegate {
176+
func presentFile(path:String) {
177+
let documentInteractionController = UIDocumentInteractionController(url: URL(fileURLWithPath: path))
178+
documentInteractionController.delegate = self
179+
documentInteractionController.presentPreview(animated: true)
127180
}
128-
129-
func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFailWithError error: Error) {
130-
print(error)
131-
132-
controller.dismiss(animated: true)
181+
//MARK: UIDocumentInteractionController delegates
182+
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
183+
return self
133184
}
134185
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// ++UIViewController.swift
3+
// DocScan
4+
//
5+
// Created by Ankit on 20/10/20.
6+
//
7+
8+
9+
import UIKit
10+
extension UIViewController{
11+
func presentAlert(title:String,message:String) {
12+
let genericAlert = UIAlertController(title: title, message: message, preferredStyle: .alert)
13+
let okAction = UIAlertAction(title: "Ok", style: .destructive, handler: nil)
14+
genericAlert.addAction(okAction)
15+
self.present(genericAlert, animated: true, completion: nil)
16+
}
17+
func presentAlert(title:String,message:String,okAction:@escaping (()->Void)) {
18+
let genericAlert = UIAlertController(title: title, message: message, preferredStyle: .alert)
19+
let okAction = UIAlertAction(title: "Ok", style: .destructive){
20+
(alertAction)in
21+
okAction()
22+
}
23+
genericAlert.addAction(okAction)
24+
self.present(genericAlert, animated: true, completion: nil)
25+
}
26+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// AlertUtil.swift
3+
// DocScan
4+
//
5+
// Created by Ankit on 20/10/20.
6+
//
7+
8+
import UIKit
9+
class AlertUtil : UIViewController,UITextFieldDelegate{
10+
static let shared = AlertUtil()
11+
var alert = UIAlertController(title: "", message: "", preferredStyle: .alert)
12+
var okAction = UIAlertAction(title: "", style: .default, handler: nil)
13+
var cancelAction = UIAlertAction(title: "", style: .default, handler: nil)
14+
var textValue = ""
15+
16+
func alertWithTextField(parent:UIViewController,title:String,message:String,placeholder:String,value:String,proceedTitle:String,cancelTitle:String,didProceed:@escaping ((String)->Void),didCancel:(()->Void)?) {
17+
self.alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
18+
self.okAction = UIAlertAction(title: proceedTitle, style: .default) { (alertAction) in
19+
didProceed(self.textValue)
20+
}
21+
self.cancelAction = UIAlertAction(title: cancelTitle, style: .default){(alertAction) in
22+
if let cancelCallBack = didCancel{
23+
cancelCallBack()
24+
}
25+
}
26+
alert.addTextField { (textField) in
27+
if(value != ""){
28+
textField.text = value
29+
}else{
30+
textField.placeholder = placeholder
31+
}
32+
textField.delegate = self
33+
textField.addTarget(self, action: #selector(self.textFieldDidChange(textField:)), for: UIControl.Event.editingChanged)
34+
}
35+
self.alert.addAction(self.cancelAction)
36+
self.alert.addAction(self.okAction)
37+
38+
okAction.isEnabled = false
39+
parent.present(alert, animated: true, completion: nil)
40+
}
41+
42+
@objc func textFieldDidChange(textField:UITextField){
43+
if let text = textField.text{
44+
if(text == ""){
45+
self.okAction.isEnabled = false
46+
}else{
47+
self.textValue = text
48+
self.okAction.isEnabled = true
49+
}
50+
}else{
51+
self.okAction.isEnabled = false
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)