Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
Implement Search History
Browse files Browse the repository at this point in the history
WIP for #33
  • Loading branch information
tovkal committed Feb 19, 2018
1 parent 5363908 commit a75a8e0
Show file tree
Hide file tree
Showing 513 changed files with 969 additions and 85 deletions.
4 changes: 2 additions & 2 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
opt_in_rules:
- empty_count
included:
- OpenFoodFacts
- OpenFoodFactsTests
- Sources
- Tests
excluded:
- Carthage
line_length:
Expand Down
Binary file removed Fabric.framework/uploadDSYM
Binary file not shown.
122 changes: 90 additions & 32 deletions OpenFoodFacts.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

This file was deleted.

40 changes: 37 additions & 3 deletions OpenFoodFacts/AppDelegate.swift → Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit
import Fabric
import Crashlytics
import XCGLogger
import RealmSwift

let log = XCGLogger(identifier: "advancedLogger", includeDefaultDestinations: false)

Expand All @@ -19,28 +20,41 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

configureRealm()

if ProcessInfo().environment["UITesting"] == nil {
configureLog()
Fabric.with([Crashlytics.self])
} else {
UIApplication.shared.keyWindow?.layer.speed = 100
}

// Inject dependencies
let dataManager = DataManager()
let productApi = ProductService()
setupViewControllers(productApi)

setupViewControllers(productApi, dataManager)

return true
}

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
if shortcutItem.type == "scan" {

// Instantiate main vc
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let rootVC = storyboard.instantiateInitialViewController()
window?.rootViewController = rootVC

// Inject dependencies
let dataManager = DataManager()
let productApi = ProductService()
setupViewControllers(productApi)

setupViewControllers(productApi, dataManager)

// TODO Refactor this taking into account the new flow vc
// Display scan vc
let scanVC = ScannerViewController(productApi: productApi)
if let tab = window?.rootViewController as? UITabBarController {
for child in tab.viewControllers ?? [] {
Expand All @@ -67,13 +81,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

}

fileprivate func setupViewControllers(_ productApi: ProductApi) {
/// Inject dependencies into tab view controllers
///
/// - Parameters:
/// - productApi: API Client
/// - dataManager: Local store client
fileprivate func setupViewControllers(_ productApi: ProductApi, _ dataManager: DataManager) {
if let tab = window?.rootViewController as? UITabBarController {
for child in tab.viewControllers ?? [] {
if var top = child as? ProductApiClient {
top.productApi = productApi
}

if var top = child as? DataManagerClient {
top.dataManager = dataManager
}
}
}
}

private func configureRealm() {
let config = Realm.Configuration(
schemaVersion: 1/*,
migrationBlock: { migration, oldSchemaVersion in
if oldSchemaVersion < 1 {
}
}*/)

Realm.Configuration.defaultConfiguration = config
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "navbar-button-history.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "navbar-button-history@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "navbar-button-history@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
77 changes: 77 additions & 0 deletions Sources/Extensions/UIColor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// UIColor.swift
// OpenFoodFacts
//
// Created by Andrés Pizá Bückmann on 17/12/2017.
// Copyright © 2017 Andrés Pizá Bückmann. All rights reserved.
//

import UIKit

// https://cocoacasts.com/from-hex-to-uicolor-and-back-in-swift/
extension UIColor {

// MARK: - Initialization

convenience init?(hex: String) {
var hexSanitized = hex.trimmingCharacters(in: .whitespacesAndNewlines)
hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "")

var rgb: UInt32 = 0

var r: CGFloat = 0.0
var g: CGFloat = 0.0
var b: CGFloat = 0.0
var a: CGFloat = 1.0

let length = hexSanitized.count

guard Scanner(string: hexSanitized).scanHexInt32(&rgb) else { return nil }

if length == 6 {
r = CGFloat((rgb & 0xFF0000) >> 16) / 255.0
g = CGFloat((rgb & 0x00FF00) >> 8) / 255.0
b = CGFloat(rgb & 0x0000FF) / 255.0

} else if length == 8 {
r = CGFloat((rgb & 0xFF000000) >> 24) / 255.0
g = CGFloat((rgb & 0x00FF0000) >> 16) / 255.0
b = CGFloat((rgb & 0x0000FF00) >> 8) / 255.0
a = CGFloat(rgb & 0x000000FF) / 255.0

} else {
return nil
}

self.init(red: r, green: g, blue: b, alpha: a)
}

// MARK: - Computed Properties

var toHex: String? {
return toHex()
}

// MARK: - From UIColor to String

func toHex(alpha: Bool = false) -> String? {
guard let components = cgColor.components, components.count >= 3 else {
return nil
}

let r = Float(components[0])
let g = Float(components[1])
let b = Float(components[2])
var a = Float(1.0)

if components.count >= 4 {
a = Float(components[3])
}

if alpha {
return String(format: "%02lX%02lX%02lX%02lX", lroundf(r * 255), lroundf(g * 255), lroundf(b * 255), lroundf(a * 255))
} else {
return String(format: "%02lX%02lX%02lX", lroundf(r * 255), lroundf(g * 255), lroundf(b * 255))
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import SafariServices
import NotificationBanner

extension UIViewController {

static func loadFromNib<T: UIViewController>() -> T {
return T(nibName: String(describing: self), bundle: .main)
}

static func loadFromStoryboard<T: UIViewController>() -> T {
let storyboard = UIStoryboard(name: String(describing: self), bundle: .main)
static func loadFromStoryboard<T: UIViewController>(named storyboardName: String? = nil) -> T {
let storyboard = UIStoryboard(name: storyboardName ?? String(describing: self), bundle: .main)
return storyboard.instantiateViewController(withIdentifier: String(describing: self)) as! T
// swiftlint:disable:previous force_cast
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @param itemPriceOrNil The purchased item's price.
* @param currencyOrNil The ISO4217 currency code. Example: USD
* @param purchaseSucceededOrNil Was the purchase succesful or unsuccesful
* @param purchaseSucceededOrNil Was the purchase successful or unsuccessful
* @param itemNameOrNil The human-readable form of the item's name. Example:
* @param itemTypeOrNil The type, or genre of the item. Example: Song
* @param itemIdOrNil The machine-readable, unique item identifier Example: SKU
Expand Down Expand Up @@ -100,7 +100,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @param levelNameOrNil The name of the level completed, E.G. "1" or "Training"
* @param scoreOrNil The score the user completed the level with.
* @param levelCompletedSuccesfullyOrNil A boolean representing whether or not the level was completed succesfully.
* @param levelCompletedSuccesfullyOrNil A boolean representing whether or not the level was completed successfully.
* @param customAttributesOrNil A dictionary of custom attributes to associate with this event.
*/
+ (void)logLevelEnd:(nullable NSString *)levelNameOrNil
Expand Down Expand Up @@ -189,7 +189,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @param eventName The human-readable name for the event.
* @param customAttributesOrNil A dictionary of custom attributes to associate with this event. Attribute keys
* must be <code>NSString</code> and and values must be <code>NSNumber</code> or <code>NSString</code>.
* must be <code>NSString</code> and values must be <code>NSNumber</code> or <code>NSString</code>.
* @discussion How we treat <code>NSNumbers</code>:
* We will provide information about the distribution of values over time.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* The CLSReport exposes an interface to the phsyical report that Crashlytics has created. You can
* use this class to get information about the event, and can also set some values after the
* event has occured.
* event has occurred.
**/
@interface CLSReport : NSObject <CLSCrashReport>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ NS_ASSUME_NONNULL_BEGIN
* Crashlytics.
*
* @param name The name of the custom exception
* @param reason The reason this exception occured
* @param reason The reason this exception occurred
* @param frameArray An array of CLSStackFrame objects
*/
- (void)recordCustomExceptionName:(NSString *)name reason:(nullable NSString *)reason frameArray:(CLS_GENERIC_NSARRAY(CLSStackFrame *) *)frameArray;
Expand Down
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file added Sources/Frameworks/Fabric.framework/uploadDSYM
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ import Foundation
struct AccessibilityIdentifiers {
static let productSearchBar = "Product Search Bar"
static let scanButton = "Scan Button"
static let historyButton = "Search history button"
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a75a8e0

Please sign in to comment.