diff --git a/CapCollector.xcodeproj/project.pbxproj b/CapCollector.xcodeproj/project.pbxproj index b322ab5..e089aac 100644 --- a/CapCollector.xcodeproj/project.pbxproj +++ b/CapCollector.xcodeproj/project.pbxproj @@ -14,7 +14,8 @@ 591832CE21A2A97E00E5987D /* Cap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 591832CD21A2A97E00E5987D /* Cap.swift */; }; 591FDD1E234E151600AA379E /* SearchAndDisplayAccessory.xib in Resources */ = {isa = PBXBuildFile; fileRef = 591FDD1D234E151600AA379E /* SearchAndDisplayAccessory.xib */; }; 591FDD20234E162000AA379E /* SearchAndDisplayAccessory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 591FDD1F234E162000AA379E /* SearchAndDisplayAccessory.swift */; }; - 5970380D225737F800D21B55 /* LogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5970380C225737F800D21B55 /* LogViewController.swift */; }; + CE0A501124752A9800A9E753 /* TileImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE0A501024752A9800A9E753 /* TileImage.swift */; }; + CE0A5013247D745200A9E753 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE0A5012247D745200A9E753 /* Colors.swift */; }; CE56CECE209D81DE00932C01 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE56CECD209D81DE00932C01 /* AppDelegate.swift */; }; CE56CED3209D81DE00932C01 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE56CED1209D81DE00932C01 /* Main.storyboard */; }; CE56CED5209D81E000932C01 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE56CED4209D81E000932C01 /* Assets.xcassets */; }; @@ -37,7 +38,6 @@ CE56CF0F209D83B800932C01 /* UIImage+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE56CEF7209D83B700932C01 /* UIImage+Extensions.swift */; }; CE5B7CFC24562673002E5C06 /* Download.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE5B7CFB24562673002E5C06 /* Download.swift */; }; CE5B7CFE245626D3002E5C06 /* Upload.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE5B7CFD245626D3002E5C06 /* Upload.swift */; }; - CE5B7D0024574CCA002E5C06 /* ServerDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE5B7CFF24574CCA002E5C06 /* ServerDatabase.swift */; }; CE5B7D032458C921002E5C06 /* Reachability in Frameworks */ = {isa = PBXBuildFile; productRef = CE5B7D022458C921002E5C06 /* Reachability */; }; CE6E4828246C304100570CB0 /* CGImagePropertyOrientation+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE6E4827246C304100570CB0 /* CGImagePropertyOrientation+Extensions.swift */; }; CE85AA16246A96C3002D1074 /* UINavigationItem+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE85AA15246A96C3002D1074 /* UINavigationItem+Extensions.swift */; }; @@ -56,7 +56,8 @@ 591832CD21A2A97E00E5987D /* Cap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cap.swift; sourceTree = ""; }; 591FDD1D234E151600AA379E /* SearchAndDisplayAccessory.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SearchAndDisplayAccessory.xib; sourceTree = ""; }; 591FDD1F234E162000AA379E /* SearchAndDisplayAccessory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchAndDisplayAccessory.swift; sourceTree = ""; }; - 5970380C225737F800D21B55 /* LogViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogViewController.swift; sourceTree = ""; }; + CE0A501024752A9800A9E753 /* TileImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TileImage.swift; sourceTree = ""; }; + CE0A5012247D745200A9E753 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = ""; }; CE56CECA209D81DD00932C01 /* CapCollector.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CapCollector.app; sourceTree = BUILT_PRODUCTS_DIR; }; CE56CECD209D81DE00932C01 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; CE56CED2209D81DE00932C01 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -82,7 +83,6 @@ CE56CEF7209D83B700932C01 /* UIImage+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Extensions.swift"; sourceTree = ""; }; CE5B7CFB24562673002E5C06 /* Download.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Download.swift; sourceTree = ""; }; CE5B7CFD245626D3002E5C06 /* Upload.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Upload.swift; sourceTree = ""; }; - CE5B7CFF24574CCA002E5C06 /* ServerDatabase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerDatabase.swift; sourceTree = ""; }; CE6E4827246C304100570CB0 /* CGImagePropertyOrientation+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGImagePropertyOrientation+Extensions.swift"; sourceTree = ""; }; CE85AA15246A96C3002D1074 /* UINavigationItem+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationItem+Extensions.swift"; sourceTree = ""; }; CE85AA17246B012B002D1074 /* Array+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+Extensions.swift"; sourceTree = ""; }; @@ -194,7 +194,6 @@ CE56CEEF209D83B500932C01 /* ImageCell.swift */, 5904C3392199C9FA0046A573 /* SortController.swift */, 59158B1521E37B0200D90CB0 /* GridViewController.swift */, - 5970380C225737F800D21B55 /* LogViewController.swift */, ); path = Presentation; sourceTree = ""; @@ -208,7 +207,8 @@ CE5B7CFB24562673002E5C06 /* Download.swift */, CE5B7CFD245626D3002E5C06 /* Upload.swift */, CEB269582445DB72004B74B3 /* Database.swift */, - CE5B7CFF24574CCA002E5C06 /* ServerDatabase.swift */, + CE0A5012247D745200A9E753 /* Colors.swift */, + CE0A501024752A9800A9E753 /* TileImage.swift */, ); path = Data; sourceTree = ""; @@ -302,6 +302,7 @@ buildActionMask = 2147483647; files = ( CE56CF09209D83B800932C01 /* Classifier.swift in Sources */, + CE0A5013247D745200A9E753 /* Colors.swift in Sources */, 5904C33A2199C9FA0046A573 /* SortController.swift in Sources */, CE56CF0B209D83B800932C01 /* Logger.swift in Sources */, CE56CF04209D83B800932C01 /* UIViewExtensions.swift in Sources */, @@ -319,9 +320,7 @@ CE56CECE209D81DE00932C01 /* AppDelegate.swift in Sources */, CE56CF0D209D83B800932C01 /* ImageSelector.swift in Sources */, CE56CEFF209D83B800932C01 /* CameraController.swift in Sources */, - CE5B7D0024574CCA002E5C06 /* ServerDatabase.swift in Sources */, CE56CF05209D83B800932C01 /* ViewControllerExtensions.swift in Sources */, - 5970380D225737F800D21B55 /* LogViewController.swift in Sources */, CE56CF0E209D83B800932C01 /* PhotoCaptureHandler.swift in Sources */, CE56CEFE209D83B800932C01 /* RoundedButton.swift in Sources */, CE56CF07209D83B800932C01 /* ImageCell.swift in Sources */, @@ -331,6 +330,7 @@ CE85AA16246A96C3002D1074 /* UINavigationItem+Extensions.swift in Sources */, CEB269592445DB72004B74B3 /* Database.swift in Sources */, CE56CF02209D83B800932C01 /* RoundedImageView.swift in Sources */, + CE0A501124752A9800A9E753 /* TileImage.swift in Sources */, CE56CEF8209D83B800932C01 /* CapCell.swift in Sources */, CE6E4828246C304100570CB0 /* CGImagePropertyOrientation+Extensions.swift in Sources */, ); diff --git a/CapCollector/AppDelegate.swift b/CapCollector/AppDelegate.swift index 082a9f2..4cee8b1 100644 --- a/CapCollector/AppDelegate.swift +++ b/CapCollector/AppDelegate.swift @@ -15,15 +15,15 @@ import Reachability #warning("ImageSelector: Show icons for failed downloads") #warning("GridController: Allow sorting of caps by color") #warning("GridController: Reorder caps by dragging") -#warning("GridController: Load and save current mosaic") -#warning("GridController: Add option to specify image width") #warning("TableView: Fix blur background of search bar after transition") #warning("TableView: Add banner to jump down to unmatched caps / bottom") - +#warning("Database: Calculate thumbnails and colors in the background") var shouldLaunchCamera = false var app: AppDelegate! +private let unlockCode = 3849 + @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { @@ -45,13 +45,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var storage: Storage! var reachability: Reachability! - - var needsDownload = false - + var dbUrl: URL { documentsFolder.appendingPathComponent("db.sqlite3") } + /// Indicate if the user has write permissions. + private(set) var isUnlocked: Bool { + get { + UserDefaults.standard.bool(forKey: "unlocked") + } + set { + UserDefaults.standard.set(newValue, forKey: "unlocked") + } + } + let serverUrl = URL(string: "https://cc.ssl443.org")! func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { @@ -62,17 +70,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { //resetToFactoryState() - needsDownload = !FileManager.default.fileExists(atPath: dbUrl.path) database = Database(url: dbUrl, server: serverUrl) - - if needsDownload { - log("New database created") - } else { - let size = (try! FileManager.default.attributesOfItem(atPath: dbUrl.path) as NSDictionary).fileSize() - log("Loaded \(database.capCount) caps, database size: \(size) bytes") - - } - return true } @@ -83,6 +81,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate { UserDefaults.standard.removeObject(forKey: Classifier.userDefaultsKey) } + func lock() { + isUnlocked = false + } + + func checkUnlock(with pin: Int) -> Bool { + isUnlocked = pin == unlockCode + return isUnlocked + } + private func handleShortCutItem(_ shortcutItem: UIApplicationShortcutItem) -> Bool { log("Shortcut pressed") shouldLaunchCamera = true @@ -90,7 +97,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } func applicationDidBecomeActive(_ application: UIApplication) { + app.database?.uploadRemainingCaps() app.database?.uploadRemainingImages() + guard shouldLaunchCamera else { return } shouldLaunchCamera = false if let c = (frontmostViewController as? UINavigationController)?.topViewController as? TableView { diff --git a/CapCollector/Base.lproj/Main.storyboard b/CapCollector/Base.lproj/Main.storyboard index ee3cbde..ddf74e5 100644 --- a/CapCollector/Base.lproj/Main.storyboard +++ b/CapCollector/Base.lproj/Main.storyboard @@ -2,7 +2,7 @@ - + @@ -127,7 +127,7 @@ -