Caps-iOS/CapCollector/AppDelegate.swift
Christoph Hagen dceb3ca07d - Remove Xcode and Regnet classifier
- Add MobileNet classifier
- Add average color for each cap
- Add option to show average colors in mosaic
2019-07-17 11:10:07 +02:00

104 lines
3.2 KiB
Swift

//
// AppDelegate.swift
// CapFinder
//
// Created by User on 31.01.18.
// Copyright © 2018 User. All rights reserved.
//
import UIKit
import CoreData
import SwiftyDropbox
/**
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
*/
var shouldLaunchCamera = false
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
enum ShortcutIdentifier: String {
case first
// 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
/// Main tint color of the app
static let tintColor = UIColor(red: 122/255, green: 155/255, blue: 41/255, alpha: 1)
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
DropboxClientsManager.setupWithAppKey("n81tx2g638wuffl")
DiskManager.setupOnFirstLaunch()
return true
}
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)
}
var frontmostViewController: UIViewController? {
var controller = window?.rootViewController
while let presentedViewController = controller?.presentedViewController {
controller = presentedViewController
}
return controller
}
}
extension AppDelegate: Logger {
static let logToken = "[AppDelegate]"
}