Handle back-button on Android devices

This commit is contained in:
Gustavo Maximiliano Cortez 2015-09-30 14:14:15 -03:00
parent 504a8b10dd
commit 9d816c20f5
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
3 changed files with 60 additions and 10 deletions

View File

@ -104,6 +104,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
var confirm_msg = gettextCatalog.getString('Confirm'); var confirm_msg = gettextCatalog.getString('Confirm');
$scope.openCopayersModal = function(copayers, copayerId) { $scope.openCopayersModal = function(copayers, copayerId) {
$rootScope.modalOpened = true;
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
var ModalInstanceCtrl = function($scope, $modalInstance) { var ModalInstanceCtrl = function($scope, $modalInstance) {
@ -120,7 +121,13 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
controller: ModalInstanceCtrl, controller: ModalInstanceCtrl,
}); });
var disableCloseModal = $rootScope.$on('closeModal', function() {
modalInstance.dismiss('cancel');
});
modalInstance.result.finally(function() { modalInstance.result.finally(function() {
$rootScope.modalOpened = false;
disableCloseModal();
var m = angular.element(document.getElementsByClassName('reveal-modal')); var m = angular.element(document.getElementsByClassName('reveal-modal'));
m.addClass('slideOutDown'); m.addClass('slideOutDown');
}); });
@ -128,9 +135,11 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.openWalletsModal = function(wallets) { $scope.openWalletsModal = function(wallets) {
$rootScope.modalOpened = true;
var ModalInstanceCtrl = function($scope, $modalInstance) { var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.wallets = wallets; $scope.wallets = wallets;
$scope.cancel = function() { $scope.cancel = function() {
$modalInstance.dismiss('cancel'); $modalInstance.dismiss('cancel');
}; };
@ -161,7 +170,13 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
controller: ModalInstanceCtrl, controller: ModalInstanceCtrl,
}); });
var disableCloseModal = $rootScope.$on('closeModal', function() {
modalInstance.dismiss('cancel');
});
modalInstance.result.finally(function() { modalInstance.result.finally(function() {
$rootScope.modalOpened = false;
disableCloseModal();
var m = angular.element(document.getElementsByClassName('reveal-modal')); var m = angular.element(document.getElementsByClassName('reveal-modal'));
m.addClass('slideOutDown'); m.addClass('slideOutDown');
}); });
@ -177,6 +192,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
// isGlidera flag is a security mesure so glidera status is not // isGlidera flag is a security mesure so glidera status is not
// only determined by the tx.message // only determined by the tx.message
this.openTxpModal = function(tx, copayers, isGlidera) { this.openTxpModal = function(tx, copayers, isGlidera) {
$rootScope.modalOpened = true;
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
var refreshUntilItChanges = false; var refreshUntilItChanges = false;
var currentSpendUnconfirmed = $scope.currentSpendUnconfirmed; var currentSpendUnconfirmed = $scope.currentSpendUnconfirmed;
@ -380,7 +396,13 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
controller: ModalInstanceCtrl, controller: ModalInstanceCtrl,
}); });
var disableCloseModal = $rootScope.$on('closeModal', function() {
modalInstance.dismiss('cancel');
});
modalInstance.result.finally(function() { modalInstance.result.finally(function() {
$rootScope.modalOpened = false;
disableCloseModal();
var m = angular.element(document.getElementsByClassName('reveal-modal')); var m = angular.element(document.getElementsByClassName('reveal-modal'));
m.addClass('slideOutRight'); m.addClass('slideOutRight');
}); });
@ -447,6 +469,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}; };
this.openCustomizedAmountModal = function(addr) { this.openCustomizedAmountModal = function(addr) {
$rootScope.modalOpened = true;
var self = this; var self = this;
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
var ModalInstanceCtrl = function($scope, $modalInstance) { var ModalInstanceCtrl = function($scope, $modalInstance) {
@ -536,7 +559,13 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
controller: ModalInstanceCtrl, controller: ModalInstanceCtrl,
}); });
var disableCloseModal = $rootScope.$on('closeModal', function() {
modalInstance.dismiss('cancel');
});
modalInstance.result.finally(function() { modalInstance.result.finally(function() {
$rootScope.modalOpened = false;
disableCloseModal();
var m = angular.element(document.getElementsByClassName('reveal-modal')); var m = angular.element(document.getElementsByClassName('reveal-modal'));
m.addClass('slideOutDown'); m.addClass('slideOutDown');
}); });
@ -926,6 +955,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}; };
this.openPPModal = function(paypro) { this.openPPModal = function(paypro) {
$rootScope.modalOpened = true;
var ModalInstanceCtrl = function($scope, $modalInstance) { var ModalInstanceCtrl = function($scope, $modalInstance) {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
var satToUnit = 1 / self.unitToSatoshi; var satToUnit = 1 / self.unitToSatoshi;
@ -947,7 +977,13 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
controller: ModalInstanceCtrl, controller: ModalInstanceCtrl,
}); });
var disableCloseModal = $rootScope.$on('closeModal', function() {
modalInstance.dismiss('cancel');
});
modalInstance.result.finally(function() { modalInstance.result.finally(function() {
$rootScope.modalOpened = false;
disableCloseModal();
var m = angular.element(document.getElementsByClassName('reveal-modal')); var m = angular.element(document.getElementsByClassName('reveal-modal'));
m.addClass('slideOutDown'); m.addClass('slideOutDown');
}); });
@ -1090,6 +1126,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}; };
this.openTxModal = function(btx) { this.openTxModal = function(btx) {
$rootScope.modalOpened = true;
var self = this; var self = this;
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
var ModalInstanceCtrl = function($scope, $modalInstance) { var ModalInstanceCtrl = function($scope, $modalInstance) {
@ -1129,7 +1166,13 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
controller: ModalInstanceCtrl, controller: ModalInstanceCtrl,
}); });
var disableCloseModal = $rootScope.$on('closeModal', function() {
modalInstance.dismiss('cancel');
});
modalInstance.result.finally(function() { modalInstance.result.finally(function() {
$rootScope.modalOpened = false;
disableCloseModal();
var m = angular.element(document.getElementsByClassName('reveal-modal')); var m = angular.element(document.getElementsByClassName('reveal-modal'));
m.addClass('slideOutRight'); m.addClass('slideOutRight');
}); });

View File

@ -44,11 +44,13 @@ angular.element(document).ready(function() {
// Back button event // Back button event
document.addEventListener('backbutton', function() { document.addEventListener('backbutton', function() {
var loc = window.location; var loc = window.location;
if (loc.toString().match(/index\.html#\/$/)) { var isHome = loc.toString().match(/index\.html#\/$/) ? 'true' : '';
navigator.app.exitApp(); if (!window.ignoreMobilePause) {
} else { window.location = '#/cordova/backbutton/'+isHome;
window.location = '#/cordova/walletHome';
} }
setTimeout(function() {
window.ignoreMobilePause = false;
}, 100);
}, false); }, false);
document.addEventListener('menubutton', function() { document.addEventListener('menubutton', function() {
@ -68,7 +70,6 @@ angular.element(document).ready(function() {
startAngular(); startAngular();
}, false); }, false);
} else { } else {
try { try {
window.handleOpenURL = handleBitcoinURI; window.handleOpenURL = handleBitcoinURI;
window.plugins.webintent.getUri(handleBitcoinURI); window.plugins.webintent.getUri(handleBitcoinURI);

View File

@ -444,13 +444,20 @@ angular
} }
}) })
.state('cordova', { .state('cordova', {
url: '/cordova/:status', url: '/cordova/:status/:isHome',
views: { views: {
'main': { 'main': {
controller: function($rootScope, $stateParams, $timeout, go) { 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;
case 'backbutton':
if (isCordova && $stateParams.isHome == 'true' && !$rootScope.modalOpened) {
navigator.app.exitApp();
} else {
$rootScope.$emit('closeModal');
}
break; break;
}; };
$timeout(function() { $timeout(function() {
@ -528,7 +535,6 @@ angular
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
if (!profileService.profile && toState.needProfile) { if (!profileService.profile && toState.needProfile) {
// Give us time to open / create the profile // Give us time to open / create the profile