2018-05-05 08:08:37 +02:00
|
|
|
//
|
|
|
|
// AppDelegate.swift
|
2018-08-16 11:18:27 +02:00
|
|
|
// CapFinder
|
2018-05-05 08:08:37 +02:00
|
|
|
//
|
2018-08-16 11:18:27 +02:00
|
|
|
// Created by User on 31.01.18.
|
|
|
|
// Copyright © 2018 User. All rights reserved.
|
2018-05-05 08:08:37 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2018-08-16 11:18:27 +02:00
|
|
|
import CoreData
|
|
|
|
import SwiftyDropbox
|
2018-05-05 08:08:37 +02:00
|
|
|
|
2019-07-17 11:10:07 +02:00
|
|
|
/**
|
|
|
|
TODO:
|
|
|
|
- Mosaic: Prevent swap of tiles when tapping the free space at the right edge
|
|
|
|
- Show banner with number of unmatched caps when using camera comparison
|
|
|
|
- Feature: Create mosaic from image
|
|
|
|
- Feature: Delete cap
|
|
|
|
- Feature: Delete image of cap
|
|
|
|
*/
|
|
|
|
|
2019-03-15 13:19:19 +01:00
|
|
|
var shouldLaunchCamera = false
|
|
|
|
|
2018-05-05 08:08:37 +02:00
|
|
|
@UIApplicationMain
|
|
|
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
2019-03-15 13:19:19 +01:00
|
|
|
|
|
|
|
enum ShortcutIdentifier: String {
|
|
|
|
case first
|
2018-05-05 08:08:37 +02:00
|
|
|
|
2019-03-15 13:19:19 +01:00
|
|
|
// MARK: - Initializers
|
|
|
|
|
|
|
|
init?(fullType: String) {
|
|
|
|
guard let last = fullType.components(separatedBy: ".").last else { return nil }
|
|
|
|
self.init(rawValue: last)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Properties
|
|
|
|
|
|
|
|
var type: String {
|
|
|
|
return Bundle.main.bundleIdentifier! + ".\(self.rawValue)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Static Properties
|
2018-08-16 11:18:27 +02:00
|
|
|
|
|
|
|
/// Main tint color of the app
|
|
|
|
static let tintColor = UIColor(red: 122/255, green: 155/255, blue: 41/255, alpha: 1)
|
|
|
|
|
2018-05-05 08:08:37 +02:00
|
|
|
var window: UIWindow?
|
|
|
|
|
2018-08-16 11:18:27 +02:00
|
|
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
|
|
|
|
|
|
DropboxClientsManager.setupWithAppKey("n81tx2g638wuffl")
|
|
|
|
DiskManager.setupOnFirstLaunch()
|
|
|
|
return true
|
|
|
|
}
|
2019-03-15 13:19:19 +01:00
|
|
|
|
|
|
|
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
|
|
|
|
DropboxController.shared.handle(url: url)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
private func handleShortCutItem(_ shortcutItem: UIApplicationShortcutItem) -> Bool {
|
|
|
|
event("Shortcut pressed")
|
|
|
|
shouldLaunchCamera = true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func applicationDidBecomeActive(_ application: UIApplication) {
|
|
|
|
Cap.uploadRemainingImages()
|
|
|
|
guard shouldLaunchCamera else { return }
|
|
|
|
shouldLaunchCamera = false
|
|
|
|
if let c = (frontmostViewController as? UINavigationController)?.topViewController as? TableView {
|
|
|
|
c.performSegue(withIdentifier: "showCamera", sender: nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Called when the user activates your application by selecting a shortcut on the home screen, except when
|
|
|
|
application(_:,willFinishLaunchingWithOptions:) or application(_:didFinishLaunchingWithOptions) returns `false`.
|
|
|
|
You should handle the shortcut in those callbacks and return `false` if possible. In that case, this
|
|
|
|
callback is used if your application is already launched in the background.
|
|
|
|
*/
|
|
|
|
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
|
|
|
|
let handledShortCutItem = handleShortCutItem(shortcutItem)
|
|
|
|
completionHandler(handledShortCutItem)
|
|
|
|
}
|
2018-08-16 11:18:27 +02:00
|
|
|
|
|
|
|
var frontmostViewController: UIViewController? {
|
|
|
|
var controller = window?.rootViewController
|
|
|
|
while let presentedViewController = controller?.presentedViewController {
|
|
|
|
controller = presentedViewController
|
|
|
|
}
|
|
|
|
return controller
|
|
|
|
}
|
2018-05-05 08:08:37 +02:00
|
|
|
|
2019-03-15 13:19:19 +01:00
|
|
|
|
2018-05-05 08:08:37 +02:00
|
|
|
}
|
|
|
|
|
2019-03-15 13:19:19 +01:00
|
|
|
extension AppDelegate: Logger {
|
|
|
|
static let logToken = "[AppDelegate]"
|
|
|
|
|
|
|
|
}
|