Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Wardrobe assistant #10

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
12 changes: 12 additions & 0 deletions ColorAssistant/ColorAssistant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
67589BD4237EAA7B0087318A /* ColorAssistantTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67589BD3237EAA7B0087318A /* ColorAssistantTests.swift */; };
67589BDB237EAA9F0087318A /* FirstView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ED0160E2379FCE6004B9DD7 /* FirstView.swift */; };
67786D4E238DAB4C009EA7B0 /* CompatabilityCheck.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67786D4D238DAB4C009EA7B0 /* CompatabilityCheck.swift */; };
67786D56238F30F8009EA7B0 /* AppDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67786D55238F30F8009EA7B0 /* AppDatabase.swift */; };
67786D58238F3101009EA7B0 /* Wardrobe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67786D57238F3101009EA7B0 /* Wardrobe.swift */; };
67786D5B238F347D009EA7B0 /* Files in Frameworks */ = {isa = PBXBuildFile; productRef = 67786D5A238F347D009EA7B0 /* Files */; };
67786D5E238F3616009EA7B0 /* GRDB in Frameworks */ = {isa = PBXBuildFile; productRef = 67786D5D238F3616009EA7B0 /* GRDB */; };
678AE1C1237E08B100F9151C /* Example.swift in Sources */ = {isa = PBXBuildFile; fileRef = 678AE1C0237E08B100F9151C /* Example.swift */; };
6E01124A2388677F00DF210B /* OutputVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E0112492388677F00DF210B /* OutputVC.swift */; };
6ED015DD2379FAB2004B9DD7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ED015DC2379FAB2004B9DD7 /* AppDelegate.swift */; };
Expand Down Expand Up @@ -46,6 +50,8 @@
67589BD3237EAA7B0087318A /* ColorAssistantTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorAssistantTests.swift; sourceTree = "<group>"; };
67589BD5237EAA7B0087318A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
67786D4D238DAB4C009EA7B0 /* CompatabilityCheck.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompatabilityCheck.swift; sourceTree = "<group>"; };
67786D55238F30F8009EA7B0 /* AppDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDatabase.swift; sourceTree = "<group>"; };
67786D57238F3101009EA7B0 /* Wardrobe.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Wardrobe.swift; sourceTree = "<group>"; };
678AE1C0237E08B100F9151C /* Example.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Example.swift; sourceTree = "<group>"; };
6E0112492388677F00DF210B /* OutputVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OutputVC.swift; sourceTree = "<group>"; };
6ED015D92379FAB2004B9DD7 /* ColorAssistant.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ColorAssistant.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -125,9 +131,11 @@
isa = PBXGroup;
children = (
6ED015DC2379FAB2004B9DD7 /* AppDelegate.swift */,
67786D55238F30F8009EA7B0 /* AppDatabase.swift */,
678AE1C0237E08B100F9151C /* Example.swift */,
6ED0160E2379FCE6004B9DD7 /* FirstView.swift */,
6ED01615237F7BEE004B9DD7 /* CameraVC.swift */,
67786D57238F3101009EA7B0 /* Wardrobe.swift */,
6E0112492388677F00DF210B /* OutputVC.swift */,
6ED015E22379FAB4004B9DD7 /* Assets.xcassets */,
6ED015E72379FAB4004B9DD7 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -301,9 +309,11 @@
678AE1C1237E08B100F9151C /* Example.swift in Sources */,
67786D4E238DAB4C009EA7B0 /* CompatabilityCheck.swift in Sources */,
6E01124A2388677F00DF210B /* OutputVC.swift in Sources */,
67786D56238F30F8009EA7B0 /* AppDatabase.swift in Sources */,
6ED01616237F7BEE004B9DD7 /* CameraVC.swift in Sources */,
6ED015DD2379FAB2004B9DD7 /* AppDelegate.swift in Sources */,
6ED0160F2379FCE6004B9DD7 /* FirstView.swift in Sources */,
67786D58238F3101009EA7B0 /* Wardrobe.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -449,6 +459,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -510,6 +521,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
"revision": "726f388fea972b55e0bd8673f678c5c0257f98ca",
"version": null
}
},
{
"package": "Files",
"repositoryURL": "https://github.com/JohnSundell/Files.git",
"state": {
"branch": null,
"revision": "6568bfe636f02dfd85dc9d51b3782555b83080d3",
"version": "4.0.2"
}
},
{
"package": "GRDB",
"repositoryURL": "https://github.com/groue/GRDB.swift.git",
"state": {
"branch": null,
"revision": "a67070dd9a08dad455e9f2895a0c40921d31fa1c",
"version": "4.6.2"
}
}
]
},
Expand Down
56 changes: 56 additions & 0 deletions ColorAssistant/ColorAssistant/AppDatabase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import GRDB

/// A type responsible for initializing the application database.
///
/// See AppDelegate.setupDatabase()
struct AppDatabase {

/// Creates a fully initialized database at path
static func openDatabase(atPath path: String) throws -> DatabaseQueue {
// Connect to the database
// See https://github.com/groue/GRDB.swift/blob/master/README.md#database-connections
let dbQueue = try DatabaseQueue(path: path)

// Define the database schema
//try migrator.migrate(dbQueue)
return dbQueue
}
/*
/// The DatabaseMigrator that defines the database schema.
///
/// See https://github.com/groue/GRDB.swift/blob/master/README.md#migrations
static var migrator: DatabaseMigrator {
var migrator = DatabaseMigrator()

migrator.registerMigration("createPlayer") { db in
// Create a table
// See https://github.com/groue/GRDB.swift#create-tables
try db.create(table: "player") { t in
t.autoIncrementedPrimaryKey("id")

// Sort player names in a localized case insensitive fashion by default
// See https://github.com/groue/GRDB.swift/blob/master/README.md#unicode
t.column("name", .text).notNull().collate(.localizedCaseInsensitiveCompare)

t.column("score", .integer).notNull()
}
}

migrator.registerMigration("fixtures") { db in
// Populate the players table with random data
for _ in 0..<8 {
var player = Player(id: nil, name: Player.randomName(), score: Player.randomScore())
try player.insert(db)
}
}

// // Migrations for future application versions will be inserted here:
// migrator.registerMigration(...) { db in
// ...
// }

return migrator
}
*/
}

8 changes: 3 additions & 5 deletions ColorAssistant/ColorAssistant/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
//

import UIKit

import GRDB
// The shared database queue
var dbQueue: DatabaseQueue!
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

Expand All @@ -22,9 +24,5 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}


// MARK: UISceneSession Lifecycle



}

35 changes: 27 additions & 8 deletions ColorAssistant/ColorAssistant/FirstView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//

import UIKit
import Files
import GRDB
import AVFoundation
import WebKit
class FirstView: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
Expand Down Expand Up @@ -310,27 +312,34 @@ class FirstView: UIViewController, UIImagePickerControllerDelegate, UINavigation
//label.textColor = .red

}


let bundle = try! Folder(path: Bundle.main.bundlePath)
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
picker.dismiss(animated: true)

guard let image = info[.editedImage] as? UIImage else {
print("No image found")
return
}



let imageName = UUID().uuidString
let pathToImage = image.save(imageName)
// bundle.createFile(named: "image_\(image.description)")
let centX = Int(image.size.width / 2) - 15
let centY = Int(img.size.height / 2) - 15

let centerColor = image.averageColor(xCoord: centX, yCoord: centY)
let breakColorComp = centerColor!.cgColor.components
let r = breakColorComp![0]
let g = breakColorComp![1]
let b = breakColorComp![2]
let breakColorComponents = centerColor?.cgColor.components
let date = Date()
var war = Wardrobe(id: nil, name: imageName, path: pathToImage, red: breakColorComponents![0], green: breakColorComponents![1], blue: breakColorComponents![2], alpha: 1.0, dateAdded: date)
try! dbQueue.write { db in
try war.insert(db)
}

DispatchQueue.main.async {
self.view.backgroundColor = centerColor
self.setupColorWheel(HTML: self.wheelSetValue(r: r, g: g, b: b))
self.setupColorWheel(HTML: self.wheelSetValue(r: breakColorComponents![0], g: breakColorComponents![1], b: breakColorComponents![2]))
self.label.text = centerColor?.description

}
Expand Down Expand Up @@ -395,6 +404,16 @@ extension UIImage {
let center: CGPoint = CGPoint(x: centerX, y: centerY)
return self.getPixelColor(pos: center)
}
/// Save PNG in the Documents directory
func save(_ name: String) -> String {
let path: String = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
let url = URL(fileURLWithPath: path).appendingPathComponent(name)
try! self.pngData()?.write(to: url)
print("saved image at \(url.description)")
return url.description
}


}
extension UIColor {
var hexString: String {
Expand Down
5 changes: 0 additions & 5 deletions ColorAssistant/ColorAssistant/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
<true/>
<key>NSCameraUsageDescription</key>
<string>COLOR DETECTION</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand Down
59 changes: 59 additions & 0 deletions ColorAssistant/ColorAssistant/Wardrobe.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// Wardrobe.swift
// ColorAssistant
//
// Created by Ian Applebaum on 11/22/19.
// Copyright © 2019 Likhon Gomes. All rights reserved.
//

import Foundation
import GRDB
import UIKit
struct Wardrobe {
var id: Int64?
var name:String?
var path: String?
var red:CGFloat?
var green:CGFloat?
var blue:CGFloat?
var alpha:CGFloat?
var dateAdded: Date?
}
extension Wardrobe: Codable, FetchableRecord, MutablePersistableRecord {
// Define database columns from CodingKeys
private enum Columns {
static let name = Column(CodingKeys.name)
static let path = Column(CodingKeys.path)
static let red = Column(CodingKeys.red)
static let green = Column(CodingKeys.green)
static let blue = Column(CodingKeys.blue)
static let alpha = Column(CodingKeys.alpha)
static let dateAdded = Column(CodingKeys.dateAdded)
}

// Update a Professor id after it has been inserted in the database.
mutating func didInsert(with rowID: Int64, for column: String?) {
id = rowID
}
}

// MARK: - Database access

// Define some useful Professor requests.
// See https://github.com/groue/GRDB.swift/blob/master/README.md#requests
extension Wardrobe {
static func orderedByName() -> QueryInterfaceRequest<Wardrobe> {
return Wardrobe.order(Columns.name)
}

static func orderedByred() -> QueryInterfaceRequest<Wardrobe> {
return Wardrobe.order(Columns.red.desc, Columns.name)
}

static func orderByDateAdded() -> QueryInterfaceRequest<Wardrobe>{
return Wardrobe.order(Columns.dateAdded.desc, Columns.name)
}
// static func orderByNeedEmail() -> QueryInterfaceRequest<Professor>{
// return Professor.order(Columns.emailed)
// }
}