Skip to content

Commit

Permalink
Merge pull request #22 from veryfi/update_version_to2.1.16.3
Browse files Browse the repository at this point in the history
Update version to 2.1.16.3
  • Loading branch information
alejouribesanchez authored Sep 11, 2023
2 parents 8ec37a5 + cb9f35d commit da1644f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 40 deletions.
61 changes: 38 additions & 23 deletions LensW2Demo/Extensions/Color+Hex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,49 @@ import UIKit

extension UIColor {
class func color(from hex: String) -> UIColor? {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()

if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
var hexSanitized = hex.trimmingCharacters(in: .whitespacesAndNewlines)
hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "")

let scanner = Scanner(string: hexSanitized)
var rgb: UInt64 = 0

guard scanner.scanHexInt64(&rgb) else {
return nil
}

if ((cString.count) != 6) {

var red: CGFloat = 0.0
var green: CGFloat = 0.0
var blue: CGFloat = 0.0
var alpha: CGFloat = 1.0

if hexSanitized.count == 6 {
red = CGFloat((rgb >> 16) & 0xFF) / 255.0
green = CGFloat((rgb >> 8) & 0xFF) / 255.0
blue = CGFloat(rgb & 0xFF) / 255.0
} else if hexSanitized.count == 8 {
red = CGFloat((rgb >> 24) & 0xFF) / 255.0
green = CGFloat((rgb >> 16) & 0xFF) / 255.0
blue = CGFloat((rgb >> 8) & 0xFF) / 255.0
alpha = CGFloat(rgb & 0xFF) / 255.0
} else {
return nil
}

var rgbValue:UInt64 = 0
Scanner(string: cString).scanHexInt64(&rgbValue)

return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)

return UIColor(red: red, green: green, blue: blue, alpha: alpha)
}

func toHexString() -> String {
var r:CGFloat = 0
var g:CGFloat = 0
var b:CGFloat = 0
var a:CGFloat = 1
getRed(&r, green: &g, blue: &b, alpha: &a)
let rgb:Int = (Int)(r*255)<<16 | (Int)(g*255)<<8 | (Int)(b*255)<<0
return String(format:"#%06x", rgb)
var red: CGFloat = 0.0
var green: CGFloat = 0.0
var blue: CGFloat = 0.0
var alpha: CGFloat = 0.0

getRed(&red, green: &green, blue: &blue, alpha: &alpha)

let hexRed = String(format: "%02X", Int(red * 255))
let hexGreen = String(format: "%02X", Int(green * 255))
let hexBlue = String(format: "%02X", Int(blue * 255))
let hexAlpha = String(format: "%02X", Int(alpha * 255))
return "#\(hexRed)\(hexGreen)\(hexBlue)\(hexAlpha)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import UIKit
extension LensSettingsViewController: UIColorPickerViewControllerDelegate {
func colorPickerViewControllerDidFinish(_ viewController: UIColorPickerViewController) {
if let changingColor = changingColor, let indexPath = changingColorIndexPath {
if changingColor.1 == .colorCell {
jsonSettings[changingColor.0.rawValue] = viewController.selectedColor
} else if changingColor.1 == .stringColorCell {
if changingColor.1 == .stringColorCell {
jsonSettings[changingColor.0.rawValue] = viewController.selectedColor.toHexString()
}
settingsTableView.reloadRows(at: [indexPath], with: .automatic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ extension LensSettingsViewController: UITableViewDataSource {
cell?.settingLabel.text = value
cell?.selectionStyle = .none
return cell ?? UITableViewCell()
case .colorCell:
let color = jsonSettings[title] as? UIColor
let cell = tableView.dequeueReusableCell(withIdentifier: "colorCell") as? ColorTableViewCell
cell?.titleLabel.text = title.titlecased()
cell?.settingView.backgroundColor = color ?? UIColor.green.withAlphaComponent(0.3)
cell?.selectionStyle = .none
return cell ?? UITableViewCell()
case .stringColorCell:
let rawColor = jsonSettings[title] as? String ?? ""
let cell = tableView.dequeueReusableCell(withIdentifier: "colorCell") as? ColorTableViewCell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension LensSettingsViewController: UITableViewDelegate {
let type = sections[indexPath.section][indexPath.row].1
if type == .stringValueCell || type == .doubleValueCell || type == .integerValueCell {
handleValueCellTap(indexPath: indexPath)
} else if type == .colorCell || type == .stringColorCell {
} else if type == .stringColorCell {
handleColorCellTap(indexPath: indexPath)
}
}
Expand Down
8 changes: 4 additions & 4 deletions LensW2Demo/LensSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LensSettingsViewController: UIViewController {
]
let generalSection: [(Keys,Types)] = [(.autoLightDetectionIsOn, .switchCell), (.stitchIsOn, .switchCell), (.allowSubmitUndetectedDocsIsOn, .switchCell), (.autoSubmitDocumentOnCapture, .switchCell), (.backupDocsToGallery, .switchCell), (.returnStitchedPDF, .switchCell), (.closeCameraOnSubmit, .switchCell), (.locationServicesIsOn, .switchCell), (.originalImageMaxSizeInMB, .doubleValueCell)]
let imageProcessingSection: [(Keys,Types)] = [(.autoRotateIsOn, .switchCell),(.autoDocDetectionAndCropIsOn,.switchCell),(.blurDetectionIsOn, .switchCell),(.autoSkewCorrectionIsOn,.switchCell),(.autoCropGalleryIsOn, .switchCell), (.gpuIsOn, .switchCell)]
let uiSection: [(Keys,Types)] = [(.docDetectFillUIColor, .colorCell), (.submitButtonBackgroundColor, .stringColorCell),(.submitButtonBorderColor,.stringColorCell),(.submitButtonFontColor,.stringColorCell),(.docDetectStrokeUIColor,.colorCell),(.submitButtonCornerRadius, .integerValueCell),(.manualCropIsOn,.switchCell),(.moreMenuIsOn,.switchCell),(.moreSettingsMenuIsOn,.switchCell),(.galleryIsOn,.switchCell),(.dictateIsOn,.switchCell),(.emailCCIsOn,.switchCell),(.emailCCDomain,.stringValueCell),(.rotateDocIsOn,.switchCell),(.shieldProtectionIsOn,.switchCell)]
let uiSection: [(Keys,Types)] = [(.docDetectFillUIColor, .stringColorCell), (.submitButtonBackgroundColor, .stringColorCell),(.submitButtonBorderColor,.stringColorCell),(.submitButtonFontColor,.stringColorCell),(.docDetectStrokeUIColor,.stringColorCell),(.submitButtonCornerRadius, .integerValueCell),(.manualCropIsOn,.switchCell),(.moreMenuIsOn,.switchCell),(.moreSettingsMenuIsOn,.switchCell),(.galleryIsOn,.switchCell),(.dictateIsOn,.switchCell),(.emailCCIsOn,.switchCell),(.emailCCDomain,.stringValueCell),(.rotateDocIsOn,.switchCell),(.shieldProtectionIsOn,.switchCell)]
let apiSection: [(Keys,Types)] = [(.autoDeleteAfterProcessing, .switchCell),(.boostModeIsOn, .switchCell),(.boundingBoxesIsOn, .switchCell),(.detectBlurResponseIsOn,.switchCell),(.isProduction,.switchCell),(.confidenceDetailsIsOn,.switchCell),(.parseAddressIsOn,.switchCell),(.externalId,.stringValueCell)]
lazy var sections: [[(Keys,Types)]] = [generalSection, imageProcessingSection, uiSection, apiSection]

Expand Down Expand Up @@ -50,9 +50,9 @@ class LensSettingsViewController: UIViewController {
//MARK: Cell values handlers
func handleColorCellTap(indexPath: IndexPath) {
let title = sections[indexPath.section][indexPath.row].0.rawValue
let type = sections[indexPath.section][indexPath.row].1
let rawColor = type == .colorCell ? jsonSettings[title] as? UIColor ?? UIColor.green.withAlphaComponent(0.3) : UIColor.color(from: jsonSettings[title] as? String ?? "")
guard let color = rawColor else { return }
let color = UIColor.color(
from: jsonSettings[title] as? String ?? ""
) ?? UIColor.green.withAlphaComponent(0.3)

changingColor = sections[indexPath.section][indexPath.row]
changingColorIndexPath = indexPath
Expand Down
1 change: 0 additions & 1 deletion LensW2Demo/Utils/Keys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,5 @@ enum Types {
case doubleValueCell
case integerValueCell
case stringValueCell
case colorCell
case stringColorCell
}
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ target 'LensW2Demo' do
use_frameworks!

# Pods for LensW2Demo
pod 'VeryfiLens-W2', '2.1.15.1'
pod 'VeryfiLens-W2', '2.1.16.3'
end

0 comments on commit da1644f

Please sign in to comment.