Skip to content

Commit

Permalink
51.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
aldrichanyline committed Mar 12, 2024
1 parent cda3537 commit b73423b
Show file tree
Hide file tree
Showing 566 changed files with 4,055 additions and 2,251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "ALContainerScanViewController.h"
#import "ALVRCScanViewController.h"
#import "ALTINScanViewController.h"
#import "ALTINScanWithUIFeedbackViewController.h"

NSString * const kVehicleRegistrationCertificate = @"Vehicle Registration Certificate DE";

Expand Down Expand Up @@ -45,7 +46,11 @@ - (void)initExampleData {
ALExample *tinScanning = [[ALExample alloc] initWithName:NSLocalizedString(@"Tire DOT/TIN", nil)
image:[UIImage imageNamed:@"tin"]
viewController:[ALTINScanViewController class] title:@"Tire DOT/TIN"];


ALExample *tinScanningUIFeedback = [[ALExample alloc] initWithName:NSLocalizedString(@"Tire DOT/TIN (with UIFeedback)", nil)
image:[UIImage imageNamed:@"tin"]
viewController:[ALTINScanWithUIFeedbackViewController class] title:@"Tire DOT/TIN"];

ALExample *tireSizeScanning = [[ALExample alloc] initWithName:NSLocalizedString(@"Tire Size", nil)
image:[UIImage imageNamed:@"tin"]
viewController:[ALTireSizeViewController class] title:@"Tire Size"];
Expand Down Expand Up @@ -80,6 +85,7 @@ - (void)initExampleData {
licensePlate,
vinScanning,
tinScanning,
tinScanningUIFeedback,
tireSizeScanning,
tireMakeScanning,
commercialTireScanning,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

NSString * const kALTINScanVC_configFilename = @"tire_tin_config";


@interface ALTINScanViewController () <ALScanPluginDelegate, ALConfigurationDialogViewControllerDelegate>

// TODO: most of these can go to a superclass.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import <UIKit/UIKit.h>

#import "ALBaseScanViewController.h"

@interface ALTINScanWithUIFeedbackViewController : ALBaseScanViewController

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
#import "ALTINScanWithUIFeedbackViewController.h"
#import <Anyline/Anyline.h>
#import "ALConfigurationDialogViewController.h"
#import "AnylineExamples-Swift.h" // for ALResultEntry
#import "ALPluginResultHelper.h"

#if __has_include("ALContactUsViewController.h")
#import "ALContactUsViewController.h"
#endif

static const NSUInteger kChoicesCount = 3; // synced with ALTINScanMode

typedef enum {
ALTINScanModeUniversal = 0,
ALTINScanModeDOT,
ALTINScanModeOtherInfo
} ALTINScanMode;

static NSString *kChoiceTitles[kChoicesCount] = { // NOTE: A C-array
@"Universal TIN/DOT",
@"TIN/DOT (North America only)",
@"Other tire sidewall information"
};

NSString * const kALTINScanVC_uiFeedback_configFilename = @"tire_tin_uifeedback_config";

@interface ALTINScanWithUIFeedbackViewController () <ALScanPluginDelegate, ALConfigurationDialogViewControllerDelegate>

// TODO: most of these can go to a superclass.
@property (nonatomic, strong) ALScanViewConfig *scanViewConfig;

@property (nonatomic, readonly) NSDictionary *scanViewConfigDict;

@property (nonatomic, assign) NSUInteger dialogIndexSelected;

+ (NSArray<NSString *> *)recalledDOTs;

@end


@implementation ALTINScanWithUIFeedbackViewController

- (void)dealloc {
// NSLog(@"dealloc ALTINScanWithUIFeedbackViewController");
}

- (void)viewDidLoad {
[super viewDidLoad];

self.title = @"Tire DOT/TIN";
self.controllerType = ALScanHistoryTIN;

self.dialogIndexSelected = 0;

self.scanViewConfig = [[ALScanViewConfig alloc] initWithJSONDictionary:self.scanViewConfigDict error:nil];

if (self.isRegionUnitedStates) {
// https://anyline.atlassian.net/browse/APP-406
self.dialogIndexSelected = 1;
}

[self reloadScanView];

[self setupModeToggle];

[self setupFlipOrientationButton];

[self.scanView startCamera];
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

// starts in landscape mode (APP-383)
self.isOrientationFlipped = YES;
[self enableLandscapeOrientation:YES];

[self startScanning:nil];
}

// detect when a rotation is done
- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
__weak __block typeof(self) weakSelf = self;
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {}
completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
if (weakSelf.scanViewPlugin.isStarted) {
[weakSelf reloadScanView];
}
}];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

// MARK: - Getters and Setters

- (NSDictionary *)scanViewConfigDict {
return [[self configJSONStrWithFilename:kALTINScanVC_uiFeedback_configFilename] asJSONObject];
}

- (BOOL)isRegionUnitedStates {
// checking device region settings. If it's US, the TIN/DOT option needs to be shown.
NSString *countryCode = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
return [countryCode isEqualToString:@"US"];
}

// MARK: - Setup

- (ALScanViewPlugin *)scanViewPluginForScanMode:(ALTINScanMode)scanMode {
NSDictionary *JSONConfigObj = self.scanViewConfigDict;

// Will edit this object before constructing an ALScanViewPlugin with it later
NSError *error;
ALScanViewPluginConfig *scanViewPluginConfig = [[ALScanViewPluginConfig alloc] initWithJSONDictionary:JSONConfigObj error:&error];

if ([self popWithAlertOnError:error]) {
return nil;
}

// Change the mode...
ALTinConfig *tinConfig = scanViewPluginConfig.pluginConfig.tinConfig;
tinConfig.scanMode = ALTinConfigScanMode.universal;
switch (scanMode) {
case ALTINScanModeUniversal:
tinConfig.scanMode = ALTinConfigScanMode.universal;
break;
case ALTINScanModeDOT:
tinConfig.scanMode = ALTinConfigScanMode.dot;
break;
default: break;
}

// Recreate the ScanViewPlugin. Since this is a different ScanViewPlugin than
// the previous one, reset the delegate.
ALScanViewPlugin *scanViewPlugin = [[ALScanViewPlugin alloc] initWithConfig:scanViewPluginConfig error:&error];

if ([self popWithAlertOnError:error]) {
return nil;
}

scanViewPlugin.scanPlugin.delegate = self;
return scanViewPlugin;
}

- (void)changeScanViewMode:(ALTINScanMode)scanMode {
[self stopScanning];
ALScanViewPlugin *scanViewPlugin = [self scanViewPluginForScanMode:scanMode];

NSError *error;
if (!self.scanView) {
self.scanView = [[ALScanView alloc] initWithFrame:CGRectZero
scanViewPlugin:scanViewPlugin
scanViewConfig:self.scanViewConfig
error:&error];
if ([self popWithAlertOnError:error]) {
return;
}
[self installScanView:self.scanView];
} else {
[self.scanView setScanViewPlugin:scanViewPlugin error:&error];
if ([self popWithAlertOnError:error]) {
return;
}
}
[self startScanning:nil];
}

- (void)reloadScanView {
[self changeScanViewMode:(ALTINScanMode)self.dialogIndexSelected];
}

// MARK: - Getters

// A list of recalled DOT values outlined in https://anyline.atlassian.net/browse/SHOW-51
// which should be treated especially with an extra result entry
+ (NSArray<NSString *> *)recalledDOTs {
return @[
@"DOTUTY11M03119",
@"DOTA3E4WBYV2220",
@"DOTNB7T2T8W0403",
@"DOTHCXH03CX4618",
@"DOTFA4FJA90320",
];
}

// MARK: - Handle & present results

- (void)scanPlugin:(ALScanPlugin *)scanPlugin resultReceived:(ALScanResult *)scanResult {

__weak __block typeof(self) weakSelf = self;
[self anylineDidFindResult:scanResult.pluginResult.tinResult.text
barcodeResult:nil
image:[scanResult croppedImage]
scanPlugin:scanPlugin viewPlugin:self.scanViewPlugin completion:^{
NSArray<ALResultEntry *> *resultData = [self.class resultDataFromScanResult:scanResult];

ALResultViewController *vc = [[ALResultViewController alloc]
initWithResults:resultData];
vc.imagePrimary = scanResult.croppedImage;
weakSelf.isOrientationFlipped = NO;
[weakSelf enableLandscapeOrientation:NO];
[weakSelf.navigationController pushViewController:vc animated:YES];
}];
}

+ (NSArray<ALResultEntry *> *)resultDataFromScanResult:(ALScanResult *)scanResult {
NSMutableArray *resultEntries = [NSMutableArray arrayWithArray:scanResult.pluginResult.fieldList.resultEntries];
// would add a Tire on Recall entry if the result falls in one of the few values hardcoded here.
BOOL needsRecalledEntry = NO;
for (ALResultEntry *res in resultEntries) {
if ([res.title isEqualToString:@"Tire Identification Number"]) {
// if result somehow split the scan result string with spaces, remove them first.
NSString *tin = [res.value stringByReplacingOccurrencesOfString:@" " withString:@""];
if ([[self.class recalledDOTs] containsObject:tin]) {
needsRecalledEntry = YES;
}
}
}
if (needsRecalledEntry) {
// add it above the first entry
[resultEntries insertObject:[ALResultEntry withTitle:@"Tire on Recall" value:@"YES"] atIndex:0];
}
return resultEntries;
}

// MARK: - Allow changing the scan mode

- (void)showOptionsSelectionDialog {
NSArray *choices = [NSArray arrayWithObjects:kChoiceTitles count:kChoicesCount];
ALConfigurationDialogViewController *vc = [ALConfigurationDialogViewController singleSelectDialogWithChoices:choices
selectedIndex:self.dialogIndexSelected
delegate:self];
[self presentViewController:vc animated:YES completion:nil];
[self.scanView stopCamera];
}

// MARK: - ALConfigurationDialogViewControllerDelegate

- (void)configDialogCommitted:(BOOL)commited dialog:(ALConfigurationDialogViewController *)dialog {}

- (void)configDialogCancelled:(ALConfigurationDialogViewController *)dialog {
[self.scanView startCamera];
}

- (void)configDialog:(ALConfigurationDialogViewController *)dialog selectedIndex:(NSUInteger)index {

if (index == ALTINScanModeOtherInfo) {
[self presentContactUsDialog];
return;
}
self.dialogIndexSelected = index;
[self.modeSelectButton setTitle:kChoiceTitles[index] forState:UIControlStateNormal];

__weak __block typeof(self) weakSelf = self;
[self dismissViewControllerAnimated:YES completion:^{
[weakSelf.scanView startCamera];
}];

[self reloadScanView];
}

// MARK: - Miscellaneous

- (void)setupModeToggle {
__weak __block typeof(self) weakSelf = self;
[self addModeSelectButtonWithTitle:kChoiceTitles[self.dialogIndexSelected] buttonPressed:^{
[weakSelf showOptionsSelectionDialog];
}];
}

- (void)presentContactUsDialog {
#if __has_include("ALContactUsViewController.h")
ALTINScanWithUIFeedbackViewController __weak *weakSelf = self;
[self dismissViewControllerAnimated:YES completion:^{

ALContactUsViewController *contactVC = [[ALContactUsViewController alloc] init];
contactVC.modalPresentationStyle = UIModalPresentationFormSheet;

[weakSelf presentViewController:contactVC animated:NO completion:^{
// undo forced landscape mode (APP-383)
weakSelf.isOrientationFlipped = NO;
[weakSelf enableLandscapeOrientation:NO];
}];

[contactVC setPresentationBlock:^{ // what happens when dismissed
// undo forced landscape mode (APP-383)
weakSelf.isOrientationFlipped = YES;
[weakSelf enableLandscapeOrientation:YES];

[weakSelf.scanView startCamera];
}];
}];
#endif
}

@end
Loading

0 comments on commit b73423b

Please sign in to comment.