Skip to content

Commit

Permalink
Update to the Anyline Tire Tread SDK v9.0.0
Browse files Browse the repository at this point in the history
Co-authored-by: Measure Team - Anyline <[email protected]>
  • Loading branch information
patrickAnyline and measure-team-anyline authored Nov 15, 2024
1 parent 25b3416 commit 1b5cf65
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 59 deletions.
10 changes: 7 additions & 3 deletions Anyline Tire Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
FA806DEF9791249E298CA64D /* tiretread_sound_beep_too_far.wav in Resources */ = {isa = PBXBuildFile; fileRef = B97D72540717494221B2D968 /* tiretread_sound_beep_too_far.wav */; };
FDF60A693E95780FFB708213 /* default_config.json in Resources */ = {isa = PBXBuildFile; fileRef = 3C29DEB55C2E3EA584BCBFE0 /* default_config.json */; };
FE1F9B0BF324FAB9B95F0C81 /* ErrorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58DC8214D152A69BF6BE2BFA /* ErrorViewController.swift */; };
FF035959932267090193E132 /* CustomTagSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD2EA2E99266C509876922A0 /* CustomTagSettingsView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -135,6 +136,7 @@
9E205BE38F7CF6F2E673D73B /* MeasurementView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeasurementView.swift; sourceTree = "<group>"; };
A9CB99471900809461B83691 /* TextLandingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLandingView.swift; sourceTree = "<group>"; };
AA0D513A072F0FA35EEED2BE /* ATDTextLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ATDTextLabel.swift; sourceTree = "<group>"; };
AD2EA2E99266C509876922A0 /* CustomTagSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTagSettingsView.swift; sourceTree = "<group>"; };
B31331DE50C6CDAD5AEA836F /* ButtonsResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonsResultView.swift; sourceTree = "<group>"; };
B5F46F97960F579993C41507 /* SystemInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemInfo.swift; sourceTree = "<group>"; };
B64E5BEDEA3ABD3A59F22090 /* ResultDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResultDetailsView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -457,6 +459,7 @@
94B3EE586C5AEFFD0946C9B5 /* AccuracySpeedSettingsView.swift */,
203FEF3A731C7A34F6109D47 /* ButtonsSettingsView.swift */,
39FB6DAFECFCBA5FFF7D488D /* CaptureSpeedView.swift */,
AD2EA2E99266C509876922A0 /* CustomTagSettingsView.swift */,
3F4512E39D68A2ECC6176D69 /* ImperialSystemSettingsView.swift */,
98E054DE5275CFBA5F059FFD /* InfoSettingsView.swift */,
1082146CA856FECC9AE1C392 /* LicenseSettingsView.swift */,
Expand Down Expand Up @@ -659,6 +662,7 @@
4315EDFF1D1D482EB86C2AC6 /* ButtonsSettingsView.swift in Sources */,
CABBA4922CFF9C7D20F87DF6 /* CaptureSpeedView.swift in Sources */,
CE2BF07B703E436BCF4A75D0 /* ColorStruct.swift in Sources */,
FF035959932267090193E132 /* CustomTagSettingsView.swift in Sources */,
1D17BE143196523D2031D216 /* DescriptionErrorView.swift in Sources */,
38DB3D561F4C43FB5A8B9727 /* ErrorButtonActionsDelegate.swift in Sources */,
84C5DAAA08E0024CCBC9F586 /* ErrorView.swift in Sources */,
Expand Down Expand Up @@ -806,7 +810,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.11.0;
MARKETING_VERSION = 2.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.anyline.showcase.tiretread;
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
Expand Down Expand Up @@ -899,7 +903,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.11.0;
MARKETING_VERSION = 2.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.anyline.showcase.tiretread;
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
Expand Down Expand Up @@ -940,7 +944,7 @@
repositoryURL = "https://github.com/Anyline/anyline-tiretread-spm-module";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 8.0.0;
minimumVersion = 9.0.0;
};
};
4B5AEA5F9FCA6152FDAB044B /* XCRemoteSwiftPackageReference "SnapKit" */ = {
Expand Down
33 changes: 9 additions & 24 deletions Anyline Tire Demo/DataStorage/UserDefaultsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,6 @@ struct UserDefaultsManager {
static var shared = UserDefaultsManager()
private init() {}

var imageQuality: Int {
get {
if UserDefaults.standard.object(forKey: "imageQuality") == nil {
UserDefaults.standard.set(50, forKey: "imageQuality")
}
return UserDefaults.standard.integer(forKey: "imageQuality")
}
set {
UserDefaults.standard.set(newValue, forKey: "imageQuality")
}
}

var imageQualitySwitchValue: Bool {
get {
if UserDefaults.standard.object(forKey: "imageQualitySwitchButton") == nil {
UserDefaults.standard.set(false, forKey: "imageQualitySwitchButton")
}
return UserDefaults.standard.bool(forKey: "imageQualitySwitchButton")
}
set {
UserDefaults.standard.set(newValue, forKey: "imageQualitySwitchButton")
}
}

var imperialSystem: Bool {
get {
if UserDefaults.standard.object(forKey: "imperialSystem") == nil {
Expand Down Expand Up @@ -70,6 +46,15 @@ struct UserDefaultsManager {
UserDefaults.standard.setValue(newValue, forKey: "showGuidance")
}
}

var customTag: String? {
get {
return UserDefaults.standard.string(forKey: "customTag")
}
set {
UserDefaults.standard.setValue(newValue, forKey: "customTag")
}
}

func addNewTireRegistration(tireId: String) {
let keychainManager = KeychainManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class LandingViewModel {
return
}

try AnylineTireTreadSdk.shared.doInit(licenseKey: licenseString)
// The customTag is meant for internal use only. Simply omit this parameter in your implementation.
try AnylineTireTreadSdk.shared.doInit(licenseKey: licenseString, customTag: UserDefaultsManager.shared.customTag)

if isInitialized {
completion(true, nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ private extension ScanViewController {

let shouldShowGuidance = UserDefaultsManager.shared.showGuidance

customUiConfig.howToScanTooltipConfig.visible = shouldShowGuidance
customUiConfig.tireOverlayConfig.visible = shouldShowGuidance
customUiConfig.lineProgressBarConfig.visible = shouldShowGuidance
customUiConfig.countdownConfig.visible = shouldShowGuidance
customUiConfig.scanDirectionConfig.visible = shouldShowGuidance

let config = TireTreadScanViewConfig()
config.measurementSystem = userDefaults.imperialSystem ? .imperial : .metric
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class SettingsViewController: UIViewController {
}()

// MARK: - Private Properties
private var switchValueButton: Bool = UserDefaultsManager.shared.imageQualitySwitchValue
private var imperialSystem: Bool = UserDefaultsManager.shared.imperialSystem
private var showGuidance: Bool = UserDefaultsManager.shared.showGuidance
private var scanSpeed: ScanSpeed = UserDefaultsManager.shared.scanSpeed
private var customTag: String? = UserDefaultsManager.shared.customTag

private lazy var settingsViewModel: SettingsViewModel = {
return SettingsViewModel(delegate: self)
Expand Down Expand Up @@ -50,18 +50,6 @@ class SettingsViewController: UIViewController {
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
}

// MARK: - Actions
func saveImageQuality() {
if switchValueButton {
// High accuracy
UserDefaultsManager.shared.imageQuality = 95
} else {
// High speed
UserDefaultsManager.shared.imageQuality = 50
}
UserDefaultsManager.shared.imageQualitySwitchValue = switchValueButton
}

func saveImperialSystem() {
if imperialSystem {
// Use inch
Expand Down Expand Up @@ -96,6 +84,13 @@ class SettingsViewController: UIViewController {
}
}

func saveCustomTag() {
let text = settingsView.customTagView.customTagTextField.text

if(text != nil) {
UserDefaultsManager.shared.customTag = text
}
}
}

// MARK: - Private UI Functions
Expand Down Expand Up @@ -233,7 +228,7 @@ extension SettingsViewController: SettingsButtonActionsDelegate {
saveImperialSystem()
saveShowGuidance()
saveLicenseID()
saveImageQuality()
saveCustomTag()
navigationController?.popViewController(animated: true)
}

Expand Down Expand Up @@ -268,10 +263,6 @@ extension SettingsViewController: SettingsButtonActionsDelegate {
}
}

func switchChanged(mySwitch: UISwitch) {
self.switchValueButton = mySwitch.isOn
}

}

extension SettingsViewController: SettingsViewModelDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ protocol SettingsButtonActionsDelegate: AnyObject {
func cancelButtonTapped()
func imperialSystemImageTapped(tapGestureRecognizer: UITapGestureRecognizer)
func showGuidanceImageTapped(tapGestureRecognizer: UITapGestureRecognizer)
func switchChanged(mySwitch: UISwitch)

func scanQRCodeTapped()
func scanSpeedDialogRequested(sender: UIButton, options: [ScanSpeed], completion: (ScanSpeed?) -> Void)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class AccuracySpeedSettingsView: UIView {
mySwitch.thumbTintColor = ColorStruct.anylineBlue
mySwitch.tintColor = ColorStruct.skyGrey
mySwitch.onTintColor = ColorStruct.skyGrey
mySwitch.isOn = UserDefaultsManager.shared.imageQualitySwitchValue
mySwitch.addTarget(AccuracySpeedSettingsView.self, action: #selector(switchChanged), for: UIControl.Event.valueChanged)
return mySwitch
}()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//
// LicenseSettingsView 2.swift
// Anyline Tire Demo
//
// Created by Patrick Fekete on 15.11.24.
//


import UIKit

class CustomTagSettingsView: UIView {

// MARK: - UI properties
private lazy var customTagLabel: ATDTextLabel = {
let label = ATDTextLabel(text: "settings.label.custom_tag".localized())
return label
}()

lazy var customTagTextField: ATDTextField = {
let textField = ATDTextField(backgroundColor: ColorStruct.snowWhite)
textField.placeholder = "settings.label.custom_tag.placeholer".localized()
textField.returnKeyType = .done
return textField
}()

private lazy var licenseHStackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .horizontal
stackView.alignment = .leading
stackView.spacing = 20
return stackView
}()

private lazy var contentVStackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .vertical
stackView.alignment = .leading
stackView.distribution = .fillProportionally
stackView.spacing = 10
return stackView
}()

// MARK: - Private Properties

// MARK: - Public properties

// MARK: - Init
override init(frame: CGRect) {
super.init(frame: frame)
configureView()
addSubviews()
setupLayout()
customTagTextField.delegate = self
}

required init?(coder: NSCoder) {
super.init(coder: coder)
}

}

// MARK: - Private functions
private extension CustomTagSettingsView {

// MARK: - Setup UI
func configureView() {
backgroundColor = ColorStruct.snowWhite
customTagTextField.text = UserDefaultsManager.shared.customTag ?? ""
}

func addSubviews() {
self.addSubview(contentVStackView)
self.contentVStackView.addArrangedSubview(licenseHStackView)
self.licenseHStackView.addArrangedSubview(customTagLabel)
self.licenseHStackView.addArrangedSubview(customTagTextField)
}

func setupLayout() {

contentVStackView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}

customTagLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
customTagLabel.snp.makeConstraints { make in
make.centerY.equalTo(customTagTextField.snp.centerY)
}

customTagTextField.snp.makeConstraints { make in
make.height.equalTo(40)
make.width.lessThanOrEqualTo(280)
}
}
}

// MARK: - UITextFieldDelegate
extension CustomTagSettingsView: UITextFieldDelegate {

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
self.customTagTextField.resignFirstResponder()
return true
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SettingsView: UIView {

private lazy var contentScrollView: UIScrollView = {
let scrollView = UIScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
return scrollView
}()

Expand All @@ -43,6 +44,11 @@ class SettingsView: UIView {
return view
}()

lazy var customTagView: CustomTagSettingsView = {
let view = CustomTagSettingsView()
return view
}()

lazy var infoView: InfoSettingsView = {
let view = InfoSettingsView()
return view
Expand Down Expand Up @@ -91,28 +97,30 @@ private extension SettingsView {

func addSubviews() {
self.addSubview(buttonsView)
self.addSubview(contentVStackView)
self.addSubview(contentScrollView)
contentScrollView.addSubview(contentVStackView)

contentVStackView.addArrangedSubview(settingsLabel)
contentVStackView.addArrangedSubview(imperialSystemView)
contentVStackView.addArrangedSubview(licenseView)
contentVStackView.addArrangedSubview(imperialSystemView)
contentVStackView.addArrangedSubview(captureSpeedView)
contentVStackView.addArrangedSubview(showGuidanceView)
contentVStackView.addArrangedSubview(customTagView)
contentVStackView.addArrangedSubview(infoView)
}

func setupLayout() {
buttonsView.snp.makeConstraints { make in
make.trailing.bottom.top.equalToSuperview()
make.width.equalTo(200).priority(.low)
}

contentVStackView.snp.makeConstraints { make in
contentScrollView.snp.makeConstraints { make in
make.leading.equalTo(80)
make.width.equalTo(500)
make.top.equalTo(20)
make.bottom.equalTo(0)
}

buttonsView.snp.makeConstraints { make in
make.trailing.bottom.top.equalToSuperview()
make.width.equalTo(200).priority(.low)
}

captureSpeedView.snp.makeConstraints { make in
make.height.equalTo(35)
Expand All @@ -124,6 +132,11 @@ private extension SettingsView {
make.top.equalTo(self.safeAreaInsets.top)
make.centerX.equalTo(self)
}

contentVStackView.snp.makeConstraints { make in
make.edges.equalToSuperview()
make.width.equalTo(contentScrollView.snp.width)
}
}

func setDelegates() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class SettingsViewModel {

func testLicenseKey(_ licenseKey: String, context: UIViewController) {
do {
try AnylineTireTreadSdk.shared.doInit(licenseKey: licenseKey)
// customTag is an internal feature and should not be used
try AnylineTireTreadSdk.shared.doInit(licenseKey: licenseKey, customTag: UserDefaultsManager.shared.customTag)
requestPermissionsAndProceed(context: context)
} catch {
let errorMessage = "error.invalid_license".localized() + " (\(error.localizedDescription))"
Expand Down
Loading

0 comments on commit 1b5cf65

Please sign in to comment.