Merge pull request #212 from gabrielbazan7/feat/hardwareButton
handle hardware back button action
This commit is contained in:
commit
c54f86d9b0
1 changed files with 23 additions and 33 deletions
|
|
@ -608,7 +608,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.state('amazon', {
|
.state('amazon', {
|
||||||
url: '/amazon',
|
url: '/amazon',
|
||||||
abstract: true,
|
abstract: true,
|
||||||
template: '<ion-nav-view name="amazon"></ion-nav-view>'
|
template: '<ion-nav-view name="amazon"></ion-nav-view>'
|
||||||
|
|
@ -630,7 +630,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.run(function($rootScope, $state, $location, $log, $timeout, $ionicPlatform, lodash, platformInfo, profileService, uxLanguage, gettextCatalog) {
|
.run(function($rootScope, $state, $location, $log, $timeout, $ionicHistory, $ionicPlatform, lodash, platformInfo, profileService, uxLanguage, gettextCatalog) {
|
||||||
|
|
||||||
if (platformInfo.isCordova) {
|
if (platformInfo.isCordova) {
|
||||||
if (screen.width < 768) {
|
if (screen.width < 768) {
|
||||||
|
|
@ -678,14 +678,28 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
StatusBar.styleLightContent();
|
StatusBar.styleLightContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
$ionicPlatform.registerBackButtonAction(function(event) {
|
$ionicPlatform.registerBackButtonAction(function(e) {
|
||||||
event.preventDefault();
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
var secondBackButtonPress = false;
|
var fromDisclaimer = $ionicHistory.currentStateName().match(/disclaimer/) ? 'true' : '';
|
||||||
var intval = setInterval(function() {
|
var fromTabs = $ionicHistory.currentStateName().match(/tabs/) ? 'true' : '';
|
||||||
secondBackButtonPress = false;
|
|
||||||
}, 5000);
|
if ($rootScope.backButtonPressedOnceToExit || fromDisclaimer) {
|
||||||
|
ionic.Platform.exitApp();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ($ionicHistory.backView() && !fromTabs) {
|
||||||
|
$ionicHistory.goBack();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$rootScope.backButtonPressedOnceToExit = true;
|
||||||
|
window.plugins.toast.showShortBottom(gettextCatalog.getString('Press again to exit'));
|
||||||
|
setInterval(function() {
|
||||||
|
$rootScope.backButtonPressedOnceToExit = false;
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
},
|
||||||
|
101);
|
||||||
|
|
||||||
$ionicPlatform.on('pause', function() {
|
$ionicPlatform.on('pause', function() {
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
|
|
@ -695,30 +709,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
$rootScope.$emit('Local/Resume');
|
$rootScope.$emit('Local/Resume');
|
||||||
});
|
});
|
||||||
|
|
||||||
$ionicPlatform.on('backbutton', function(event) {
|
|
||||||
|
|
||||||
var loc = window.location;
|
|
||||||
var fromDisclaimer = loc.toString().match(/disclaimer/) ? 'true' : '';
|
|
||||||
var fromHome = loc.toString().match(/index\.html#\/$/) ? 'true' : '';
|
|
||||||
|
|
||||||
if (fromDisclaimer == 'true')
|
|
||||||
navigator.app.exitApp();
|
|
||||||
|
|
||||||
if (platformInfo.isMobile && fromHome == 'true') {
|
|
||||||
if (secondBackButtonPress)
|
|
||||||
navigator.app.exitApp();
|
|
||||||
else
|
|
||||||
window.plugins.toast.showShortBottom(gettextCatalog.getString('Press again to exit'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (secondBackButtonPress)
|
|
||||||
clearInterval(intval);
|
|
||||||
else
|
|
||||||
secondBackButtonPress = true;
|
|
||||||
|
|
||||||
$state.go('tabs.home');
|
|
||||||
});
|
|
||||||
|
|
||||||
$ionicPlatform.on('menubutton', function() {
|
$ionicPlatform.on('menubutton', function() {
|
||||||
window.location = '#/preferences';
|
window.location = '#/preferences';
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue