Skip to content

Commit

Permalink
Merge pull request #3 from AntonAmes/dev-v1.2
Browse files Browse the repository at this point in the history
Dev v1.2
  • Loading branch information
antonlorani authored Mar 8, 2021
2 parents 0241e44 + ea8a76b commit 1436e05
Show file tree
Hide file tree
Showing 21 changed files with 369 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
exports/*

resources/*
40 changes: 32 additions & 8 deletions Jottre.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
A61BB9FA25D0604200E63CF6 /* ShareButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = A61BB9F925D0604200E63CF6 /* ShareButton.swift */; };
A61BB9FE25D0608B00E63CF6 /* CustomButtonBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A61BB9FD25D0608B00E63CF6 /* CustomButtonBarItem.swift */; };
A6330A7F25D05F6700068DE5 /* AddButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6330A7E25D05F6700068DE5 /* AddButton.swift */; };
A6350E5425C9CEFB0059E96E /* NodeExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6350E5325C9CEFB0059E96E /* NodeExtensions.swift */; };
A650EE6825C5819500830112 /* NodeCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A650EE6725C5819500830112 /* NodeCodable.swift */; };
A650EE6B25C585D300830112 /* NodeDecoderExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A650EE6A25C585D300830112 /* NodeDecoderExtension.swift */; };
Expand All @@ -30,7 +33,7 @@
A6E3B7F825B3260300C65157 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A6E3B7F625B3260300C65157 /* LaunchScreen.storyboard */; };
A6E3B82125B32AB400C65157 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E3B82025B32AB400C65157 /* Logger.swift */; };
A6E3B82425B32ABE00C65157 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E3B82325B32ABE00C65157 /* String.swift */; };
A6E3B82825B32AD300C65157 /* NavigationButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E3B82725B32AD300C65157 /* NavigationButton.swift */; };
A6E3B82825B32AD300C65157 /* NavigationTextButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E3B82725B32AD300C65157 /* NavigationTextButton.swift */; };
A6E3B82C25B32AEB00C65157 /* NavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E3B82B25B32AEB00C65157 /* NavigationViewController.swift */; };
A6E3B82F25B32B0700C65157 /* InitialViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E3B82E25B32B0700C65157 /* InitialViewController.swift */; };
A6E3B83425B32BBC00C65157 /* Node.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E3B83325B32BBC00C65157 /* Node.swift */; };
Expand All @@ -44,9 +47,13 @@
A6E3B85E25B3673C00C65157 /* UIDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E3B85D25B3673C00C65157 /* UIDevice.swift */; };
A6E3B86525B372A800C65157 /* ExportActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E3B86425B372A800C65157 /* ExportActions.swift */; };
A6E3B86825B374A200C65157 /* MenuActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E3B86725B374A200C65157 /* MenuActions.swift */; };
A6F60F8525CAA2CC002CAAE4 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6F60F8425CAA2CC002CAAE4 /* Data.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
A61BB9F925D0604200E63CF6 /* ShareButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareButton.swift; sourceTree = "<group>"; };
A61BB9FD25D0608B00E63CF6 /* CustomButtonBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomButtonBarItem.swift; sourceTree = "<group>"; };
A6330A7E25D05F6700068DE5 /* AddButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddButton.swift; sourceTree = "<group>"; };
A6350E5325C9CEFB0059E96E /* NodeExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeExtensions.swift; sourceTree = "<group>"; };
A650EE6725C5819500830112 /* NodeCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeCodable.swift; sourceTree = "<group>"; };
A650EE6A25C585D300830112 /* NodeDecoderExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeDecoderExtension.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -75,7 +82,7 @@
A6E3B80025B3261800C65157 /* Jottre.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Jottre.entitlements; sourceTree = "<group>"; };
A6E3B82025B32AB400C65157 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
A6E3B82325B32ABE00C65157 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
A6E3B82725B32AD300C65157 /* NavigationButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationButton.swift; sourceTree = "<group>"; };
A6E3B82725B32AD300C65157 /* NavigationTextButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationTextButton.swift; sourceTree = "<group>"; };
A6E3B82B25B32AEB00C65157 /* NavigationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationViewController.swift; sourceTree = "<group>"; };
A6E3B82E25B32B0700C65157 /* InitialViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitialViewController.swift; sourceTree = "<group>"; };
A6E3B83325B32BBC00C65157 /* Node.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Node.swift; sourceTree = "<group>"; };
Expand All @@ -89,6 +96,7 @@
A6E3B85D25B3673C00C65157 /* UIDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = UIDevice.swift; path = Jottre/Helpers/UIDevice.swift; sourceTree = SOURCE_ROOT; };
A6E3B86425B372A800C65157 /* ExportActions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExportActions.swift; sourceTree = "<group>"; };
A6E3B86725B374A200C65157 /* MenuActions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuActions.swift; sourceTree = "<group>"; };
A6F60F8425CAA2CC002CAAE4 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -102,6 +110,18 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
A61BBA0125D0634400E63CF6 /* BarButtonItems */ = {
isa = PBXGroup;
children = (
A6E3B82725B32AD300C65157 /* NavigationTextButton.swift */,
A61BB9FD25D0608B00E63CF6 /* CustomButtonBarItem.swift */,
A6BB134725B4A469008C5D8A /* SettingsButton.swift */,
A61BB9F925D0604200E63CF6 /* ShareButton.swift */,
A6330A7E25D05F6700068DE5 /* AddButton.swift */,
);
path = BarButtonItems;
sourceTree = "<group>";
};
A6BB130525B45E52008C5D8A /* SettingsScene */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -182,8 +202,8 @@
isa = PBXGroup;
children = (
A6E3B82B25B32AEB00C65157 /* NavigationViewController.swift */,
A6E3B84925B347AE00C65157 /* DrawScene */,
A6E3B83F25B3349900C65157 /* InitialScene */,
A6E3B84925B347AE00C65157 /* DrawScene */,
A6BB130525B45E52008C5D8A /* SettingsScene */,
);
path = Controllers;
Expand All @@ -192,10 +212,9 @@
A6E3B80F25B3295200C65157 /* Views */ = {
isa = PBXGroup;
children = (
A61BBA0125D0634400E63CF6 /* BarButtonItems */,
A6BB131525B472D9008C5D8A /* SettingsCell */,
A6E3B83925B333EC00C65157 /* NodeCell.swift */,
A6E3B82725B32AD300C65157 /* NavigationButton.swift */,
A6BB134725B4A469008C5D8A /* SettingsButton.swift */,
A6C0D70A25B9F42400336230 /* LoadingView.swift */,
);
path = Views;
Expand All @@ -210,6 +229,7 @@
A6E3B85D25B3673C00C65157 /* UIDevice.swift */,
A6C0D70225B9DB9D00336230 /* URL.swift */,
A6C0D70625B9F21400336230 /* PKDrawing.swift */,
A6F60F8425CAA2CC002CAAE4 /* Data.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -326,6 +346,7 @@
A6E3B86525B372A800C65157 /* ExportActions.swift in Sources */,
A6E3B7EC25B3260200C65157 /* AppDelegate.swift in Sources */,
A6E3B84125B334AF00C65157 /* InitialExtensions.swift in Sources */,
A6330A7F25D05F6700068DE5 /* AddButton.swift in Sources */,
A6E3B85225B34ACB00C65157 /* ThumbnailGenerator.swift in Sources */,
A6BB134825B4A469008C5D8A /* SettingsButton.swift in Sources */,
A6E3B82C25B32AEB00C65157 /* NavigationViewController.swift in Sources */,
Expand All @@ -341,9 +362,11 @@
A6BB131325B46E2D008C5D8A /* SettingsCell.swift in Sources */,
A6E3B7EE25B3260200C65157 /* SceneDelegate.swift in Sources */,
A6E3B83425B32BBC00C65157 /* Node.swift in Sources */,
A61BB9FE25D0608B00E63CF6 /* CustomButtonBarItem.swift in Sources */,
A6E3B82F25B32B0700C65157 /* InitialViewController.swift in Sources */,
A6E3B83A25B333EC00C65157 /* NodeCell.swift in Sources */,
A65F231D25B5C1B000A0E870 /* IconSettingsCell.swift in Sources */,
A6F60F8525CAA2CC002CAAE4 /* Data.swift in Sources */,
A6BB131B25B472F9008C5D8A /* AppearanceSettingsCell.swift in Sources */,
A6E3B83725B32BC500C65157 /* NodeCollector.swift in Sources */,
A6E3B82425B32ABE00C65157 /* String.swift in Sources */,
Expand All @@ -352,7 +375,8 @@
A6BB134C25B4AEFC008C5D8A /* SettingsExtensions.swift in Sources */,
A6A8803E25BAB41E0080DD9D /* Downloader.swift in Sources */,
A6BB131025B46BA2008C5D8A /* SettingsNavigationViewController.swift in Sources */,
A6E3B82825B32AD300C65157 /* NavigationButton.swift in Sources */,
A6E3B82825B32AD300C65157 /* NavigationTextButton.swift in Sources */,
A61BB9FA25D0604200E63CF6 /* ShareButton.swift in Sources */,
A650EE6825C5819500830112 /* NodeCodable.swift in Sources */,
A6E3B86825B374A200C65157 /* MenuActions.swift in Sources */,
A6C0D70B25B9F42400336230 /* LoadingView.swift in Sources */,
Expand Down Expand Up @@ -509,7 +533,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Jottre/Jottre.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 11;
CURRENT_PROJECT_VERSION = 16;
DEVELOPMENT_TEAM = Y78RPE9KK3;
INFOPLIST_FILE = Jottre/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
Expand All @@ -533,7 +557,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Jottre/Jottre.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 11;
CURRENT_PROJECT_VERSION = 16;
DEVELOPMENT_TEAM = Y78RPE9KK3;
INFOPLIST_FILE = Jottre/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
Expand Down
14 changes: 9 additions & 5 deletions Jottre/Controllers/DrawScene/DrawViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ class DrawViewController: UIViewController {
if hasModifiedDrawing {

navigationItem.hidesBackButton = true
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: NavigationButton(title: NSLocalizedString("Save", comment: "Save the document"), target: self, action: #selector(self.writeDrawingHandler)))

navigationItem.leftBarButtonItem = UIBarButtonItem(customView: NavigationTextButton(title: NSLocalizedString("Save", comment: "Save the document"), target: self, action: #selector(self.writeDrawingHandler)))

} else {

navigationItem.leftBarButtonItem = nil
navigationItem.hidesBackButton = false

}

}
Expand Down Expand Up @@ -132,7 +137,7 @@ class DrawViewController: UIViewController {

navigationItem.largeTitleDisplayMode = .never
navigationItem.title = node.name
navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "square.and.arrow.up"), style: .plain, target: self, action: #selector(exportDrawing))
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: ShareButton(target: self, action: #selector(exportDrawing)))

view.addSubview(canvasView)
canvasView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
Expand Down Expand Up @@ -248,10 +253,9 @@ class DrawViewController: UIViewController {
}

func writeDrawing() {
Logger.main.info("Storing document")
DispatchQueue.main.async {
self.hasModifiedDrawing = false
self.node.setDrawing(drawing: self.canvasView.drawing)
self.navigationController?.popViewController(animated: true)
}
}

Expand Down
36 changes: 29 additions & 7 deletions Jottre/Controllers/DrawScene/ExportActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ extension DrawViewController {
self.drawingToPDF { (data, _, _) in

guard let data = data else {
Logger.main.debug("Could not create PDF from canvas")
self.stopLoading()
return
}

let fileURL = Settings.tmpDirectory.appendingPathComponent(self.node.name!).appendingPathExtension("pdf")

let activityViewController = UIActivityViewController(activityItems: [data], applicationActivities: nil)
if !data.writeToReturingBoolean(url: fileURL) {
self.stopLoading()
return
}

let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)

DispatchQueue.main.async {
self.stopLoading()
Expand All @@ -46,9 +52,19 @@ extension DrawViewController {
var bounds = drawing.bounds
bounds.size.height = drawing.bounds.maxY + 100

let image = drawing.image(from: bounds, scale: 1, userInterfaceStyle: .light)
guard let data = drawing.image(from: bounds, scale: 1, userInterfaceStyle: .light).jpegData(compressionQuality: 1) else {
self.stopLoading()
return
}

let activityViewController = UIActivityViewController(activityItems: [image], applicationActivities: nil)
let fileURL = Settings.tmpDirectory.appendingPathComponent(self.node.name!).appendingPathExtension("png")

if !data.writeToReturingBoolean(url: fileURL) {
self.stopLoading()
return
}

let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)

DispatchQueue.main.async {
self.stopLoading()
Expand All @@ -70,13 +86,19 @@ extension DrawViewController {
var bounds = drawing.bounds
bounds.size.height = drawing.bounds.maxY + 100

guard let image = drawing.image(from: bounds, scale: 1, userInterfaceStyle: .light).jpegData(compressionQuality: 1) else {
Logger.main.debug("Could not retrieve jpeg data from drawing")
guard let data = drawing.image(from: bounds, scale: 1, userInterfaceStyle: .light).jpegData(compressionQuality: 1) else {
self.stopLoading()
return
}

let fileURL = Settings.tmpDirectory.appendingPathComponent(self.node.name!).appendingPathExtension("jpg")

if !data.writeToReturingBoolean(url: fileURL) {
self.stopLoading()
return
}

let activityViewController = UIActivityViewController(activityItems: [image], applicationActivities: nil)
let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)

DispatchQueue.main.async {
self.stopLoading()
Expand Down
20 changes: 18 additions & 2 deletions Jottre/Controllers/InitialScene/InitialExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,22 @@ import OSLog

extension InitialViewController: NodeCollectorObserver {

func nodeCollectorDidChange() {
self.collectionView.reloadData()
func didInsertNode(nodeCollector: NodeCollector, at index: Int) {

collectionView.performBatchUpdates({
let indexPath = IndexPath(item: index, section: 0)
self.collectionView.insertItems(at: [indexPath])
}, completion: nil)

}

func didDeleteNode(nodeCollector: NodeCollector, at index: Int) {

collectionView.performBatchUpdates({
let indexPath = IndexPath(item: index, section: 0)
self.collectionView.deleteItems(at: [indexPath])
}, completion: nil)

}

}
Expand Down Expand Up @@ -58,6 +72,8 @@ extension InitialViewController: UICollectionViewDataSource, UICollectionViewDel
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "nodeCell", for: indexPath) as? NodeCell else {
fatalError("Cell is not of type NodeCell.")
}

nodeCollector.nodes[indexPath.row].addObserver(cell)
cell.node = nodeCollector.nodes[indexPath.row]

return cell
Expand Down
40 changes: 12 additions & 28 deletions Jottre/Controllers/InitialScene/InitialViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ class InitialViewController: UIViewController {

var nodeCollector: NodeCollector = NodeCollector()

var hasDocumentsDelayFinished: Bool = false

var hasDocuments: Bool = false {
didSet {
if !hasDocumentsDelayFinished { return }
UIView.animate(withDuration: 0.5) {
self.infoTextView.alpha = self.hasDocuments ? 0 : 1
self.collectionView.alpha = self.hasDocuments ? 1 : 0
Expand Down Expand Up @@ -91,7 +94,7 @@ class InitialViewController: UIViewController {
view.backgroundColor = .systemBackground

if !UIDevice.isLimited() {
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: NavigationButton(title: NSLocalizedString("Add note", comment: ""), target: self, action: #selector(createNode)))
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: NavigationTextButton(title: NSLocalizedString("Add note", comment: ""), target: self, action: #selector(createNode)))
}

if !Downloader.isCloudEnabled {
Expand All @@ -116,15 +119,16 @@ class InitialViewController: UIViewController {


private func setupDelegates() {

nodeCollector.traitCollection = traitCollection

collectionView.delegate = self
collectionView.dataSource = self

nodeCollector.traitCollection = traitCollection
nodeCollector.addObserver(self)
nodeCollector.continueBackgroundFetch()

DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.collectionView.delegate = self
self.collectionView.dataSource = self
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.5) {
self.hasDocumentsDelayFinished = true
self.hasDocuments = !(!self.hasDocuments) /// A simple solution to reassign the value to call didSet
}

settings.addObserver(self)
Expand Down Expand Up @@ -155,27 +159,7 @@ class InitialViewController: UIViewController {
}
name = name == "" ? noteName : name

self.nodeCollector.createNode(name: name) { (node) in
//
// guard let node = node else {
// return
// }
//
// self.nodeCollector.disableObservers()
// self.nodeCollector.nodes.append(node)
//
// DispatchQueue.main.async {
//
// self.collectionView.performBatchUpdates {
// let indexPath = IndexPath(item: self.nodeCollector.nodes.count - 1, section: 0)
// self.collectionView.insertItems(at: [indexPath])
// } completion: { (success) in
// self.nodeCollector.enableObservers()
// }
//
// }

}
self.nodeCollector.createNode(name: name) { (node) in }

}))

Expand Down
Loading

0 comments on commit 1436e05

Please sign in to comment.