feat(scan): first iteration of full scan view implementation
This commit is contained in:
parent
845534c727
commit
c0d4fbe5bb
5 changed files with 106 additions and 50 deletions
|
|
@ -23,57 +23,71 @@ angular.module('copayApp.controllers').controller('tabScanController', function(
|
|||
}
|
||||
|
||||
function _handleCapabilities(){
|
||||
if(!$scope.scannerIsAvailable){
|
||||
$scope.currentState = scannerStates.unavailable;
|
||||
} else if($scope.scannerIsDenied){
|
||||
$scope.currentState = scannerStates.denied;
|
||||
} else if($scope.scannerIsRestricted){
|
||||
$scope.currentState = scannerStates.denied;
|
||||
} else if(!$scope.scannerHasPermission){
|
||||
$scope.currentState = scannerStates.unauthorized;
|
||||
} else if($scope.scannerHasPermission){
|
||||
// always update the view
|
||||
$timeout(function(){
|
||||
if(!scannerService.isInitialized()){
|
||||
$scope.currentState = scannerStates.loading;
|
||||
} else if(!$scope.scannerIsAvailable){
|
||||
$scope.currentState = scannerStates.unavailable;
|
||||
} else if($scope.scannerIsDenied){
|
||||
$scope.currentState = scannerStates.denied;
|
||||
} else if($scope.scannerIsRestricted){
|
||||
$scope.currentState = scannerStates.denied;
|
||||
} else if(!$scope.scannerHasPermission){
|
||||
$scope.currentState = scannerStates.unauthorized;
|
||||
}
|
||||
$log.debug('Scan view state set to: ' + $scope.currentState);
|
||||
});
|
||||
}
|
||||
|
||||
function _refreshScanView(){
|
||||
_updateCapabilities();
|
||||
_handleCapabilities();
|
||||
if($scope.scannerHasPermission){
|
||||
activate();
|
||||
}
|
||||
}
|
||||
|
||||
function _initScanView(){
|
||||
_updateCapabilities();
|
||||
_handleCapabilities();
|
||||
}
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function() {
|
||||
$scope.currentState = scannerStates.loading;
|
||||
});
|
||||
|
||||
// This could be much cleaner with a Promise API
|
||||
// (needs a polyfill for some platforms)
|
||||
$rootScope.$on('scannerServiceInitialized', function(){
|
||||
$log.debug('Scanner initialization finished, reinitializing scan view...');
|
||||
_initScanView();
|
||||
_refreshScanView();
|
||||
});
|
||||
|
||||
$scope.$on("$ionicView.afterEnter", function() {
|
||||
if(scannerService.isInitialized()){
|
||||
_initScanView();
|
||||
}
|
||||
// try initializing and refreshing status any time the view is entered
|
||||
scannerService.gentleInitialize();
|
||||
});
|
||||
|
||||
function activate(){
|
||||
scannerService.activate(function(){
|
||||
_updateCapabilities();
|
||||
_handleCapabilities();
|
||||
$log.debug('Scanner activated, setting to visible...');
|
||||
$scope.currentState = scannerStates.visible;
|
||||
scannerService.scan(function(err, contents){
|
||||
if(err){
|
||||
$log.debug('Scan canceled.');
|
||||
} else if ($state.params.passthroughMode) {
|
||||
$rootScope.scanResult = contents;
|
||||
goBack();
|
||||
} else {
|
||||
handleSuccessfulScan(contents);
|
||||
}
|
||||
});
|
||||
// pause to update the view
|
||||
$timeout(function(){
|
||||
scannerService.scan(function(err, contents){
|
||||
if(err){
|
||||
$log.debug('Scan canceled.');
|
||||
} else if ($state.params.passthroughMode) {
|
||||
$rootScope.scanResult = contents;
|
||||
goBack();
|
||||
} else {
|
||||
handleSuccessfulScan(contents);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
$scope.activate = activate;
|
||||
|
||||
$scope.authorize = function(){
|
||||
scannerService.initialize(function(){
|
||||
_refreshScanView();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.$on("$ionicView.afterLeave", function() {
|
||||
scannerService.deactivate();
|
||||
|
|
@ -84,6 +98,14 @@ angular.module('copayApp.controllers').controller('tabScanController', function(
|
|||
incomingData.redir(contents);
|
||||
}
|
||||
|
||||
$scope.openSettings = function(){
|
||||
scannerService.openSettings();
|
||||
};
|
||||
|
||||
$scope.attemptToReactivate = function(){
|
||||
scannerService.reinitialize();
|
||||
};
|
||||
|
||||
$scope.toggleLight = function(){
|
||||
scannerService.toggleLight(function(lightEnabled){
|
||||
$scope.lightActive = lightEnabled;
|
||||
|
|
@ -98,7 +120,7 @@ angular.module('copayApp.controllers').controller('tabScanController', function(
|
|||
$timeout(function(){
|
||||
$scope.cameraToggleActive = false;
|
||||
$log.debug('Camera toggle control deactivated.');
|
||||
}, 600);
|
||||
}, 200);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -106,6 +128,9 @@ angular.module('copayApp.controllers').controller('tabScanController', function(
|
|||
return $state.params.passthroughMode;
|
||||
}
|
||||
function goBack(){
|
||||
$ionicHistory.nextViewOptions({
|
||||
disableAnimate: true
|
||||
});
|
||||
$ionicHistory.backView().go();
|
||||
}
|
||||
$scope.goBack = goBack;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue