Merge pull request #3631 from gabrielbazan7/feat/AvoidAccidentalExit

Second back button press to exit
This commit is contained in:
Gustavo Maximiliano Cortez 2015-12-10 12:52:10 -03:00
commit bc203c5d6f
2 changed files with 22 additions and 5 deletions

View file

@ -25,10 +25,15 @@ angular.element(document).ready(function() {
document.addEventListener('deviceready', function() { document.addEventListener('deviceready', function() {
var secondBackButtonPress = 'false';
var intval = setInterval(function() {
secondBackButtonPress = 'false';
}, 5000);
document.addEventListener('pause', function() { document.addEventListener('pause', function() {
if (!window.ignoreMobilePause) { if (!window.ignoreMobilePause) {
setTimeout(function() { setTimeout(function() {
window.location = '#/cordova/pause/'; window.location = '#/cordova/pause//';
}, 100); }, 100);
} }
}, false); }, false);
@ -36,7 +41,7 @@ angular.element(document).ready(function() {
document.addEventListener('resume', function() { document.addEventListener('resume', function() {
if (!window.ignoreMobilePause) { if (!window.ignoreMobilePause) {
setTimeout(function() { setTimeout(function() {
window.location = '#/cordova/resume/'; window.location = '#/cordova/resume//';
}, 100); }, 100);
} }
setTimeout(function() { setTimeout(function() {
@ -45,13 +50,20 @@ angular.element(document).ready(function() {
}, false); }, false);
// Back button event // Back button event
document.addEventListener('backbutton', function() { document.addEventListener('backbutton', function() {
var loc = window.location; var loc = window.location;
var exit = loc.toString().match(/disclaimer/) ? 'true' : ''; var exit = loc.toString().match(/disclaimer/) ? 'true' : '';
if (exit != 'true') if (exit != 'true')
var exit = loc.toString().match(/index\.html#\/$/) ? 'true' : ''; var exit = loc.toString().match(/index\.html#\/$/) ? 'true' : '';
if (!window.ignoreMobilePause) { if (!window.ignoreMobilePause) {
window.location = '#/cordova/backbutton/' + exit; window.location = '#/cordova/backbutton/' + exit + '/' + secondBackButtonPress;
if (secondBackButtonPress == 'true') {
clearInterval(intval);
} else {
secondBackButtonPress = 'true';
}
} }
setTimeout(function() { setTimeout(function() {
window.ignoreMobilePause = false; window.ignoreMobilePause = false;

View file

@ -475,17 +475,22 @@ angular
} }
}) })
.state('cordova', { .state('cordova', {
url: '/cordova/:status/:exit', url: '/cordova/:status/:exit/:secondBackButtonPress',
views: { views: {
'main': { 'main': {
controller: function($rootScope, $state, $stateParams, $timeout, go, isCordova) { controller: function($rootScope, $state, $stateParams, $timeout, go, isCordova) {
switch ($stateParams.status) { switch ($stateParams.status) {
case 'resume': case 'resume':
$rootScope.$emit('Local/Resume'); $rootScope.$emit('Local/Resume');
break; break;
case 'backbutton': case 'backbutton':
if (isCordova && $stateParams.exit == 'true' && !$rootScope.modalOpened) { if (isCordova && $stateParams.exit == 'true' && !$rootScope.modalOpened) {
navigator.app.exitApp(); if ($stateParams.secondBackButtonPress == 'true') {
navigator.app.exitApp();
} else {
window.plugins.toast.showShortBottom('Press again to exit');
}
} else { } else {
$rootScope.$emit('closeModal'); $rootScope.$emit('closeModal');
} }