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

View file

@ -475,17 +475,22 @@ angular
}
})
.state('cordova', {
url: '/cordova/:status/:exit',
url: '/cordova/:status/:exit/:secondBackButtonPress',
views: {
'main': {
controller: function($rootScope, $state, $stateParams, $timeout, go, isCordova) {
switch ($stateParams.status) {
case 'resume':
$rootScope.$emit('Local/Resume');
break;
case 'backbutton':
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 {
$rootScope.$emit('closeModal');
}