Merge PR #221: Improve back button handling

This commit is contained in:
Jenkins 2019-07-07 21:06:23 +02:00
commit dd489707c5
4 changed files with 38 additions and 17 deletions

@ -1 +1 @@
Subproject commit edc0a6fb19821d59f13087cf38c9a56932798b57
Subproject commit d97317e856d55a2f5399f17888f1852fee8b9553

View File

@ -65,10 +65,6 @@ ApplicationWindow {
}
property alias _discovery: discovery
onClosing: {
rootItem.handleCloseEvent(close)
}
property var supportedInterfaces: ["light", "weather", "media", "garagegate", "awning", "shutter", "blind", "powersocket", "heating", "sensor", "smartmeter", "evcharger", "accesscontrol", "button", "notifications", "inputtrigger", "outputtrigger", "gateway"]
function interfaceToString(name) {
switch(name) {
@ -338,6 +334,32 @@ ApplicationWindow {
return s.substr(s.length-size);
}
// Handle the Android close event that happens when the back button is pressed
// It's hard to handle the key press, because we might not have focus all the time
// So let's handle the window's onClosing signal instad.
// The problem is, we cannot distinguish between the back button being pressed
// or the bottom swipe gesture is being used to switch apps. Let's try to figure that out
// by checking if the app becomes inactive right after the event. If not, it's probably a back
// button press and we close ourselves.
onClosing: {
if (Qt.platform.os == "android") {
var handled = rootItem.handleAndroidBackButton();
if (!handled) {
closeTimer.start()
}
close.accepted = false;
}
}
Timer {
id: closeTimer
interval: 300
onTriggered: Qt.quit();
}
Connections {
target: Qt.application
onStateChanged: closeTimer.stop()
}
KeyboardLoader {
id: keyboardRect

View File

@ -16,8 +16,8 @@ Item {
color: Material.background
}
function handleCloseEvent(close) {
swipeView.currentItem.handleCloseEvent(close)
function handleAndroidBackButton() {
return swipeView.currentItem.handleAndroidBackButton()
}
ListModel {
@ -182,16 +182,15 @@ Item {
})
}
function handleCloseEvent(close) {
if (Qt.platform.os == "android") {
// If we're connected, allow going back up to MainPage
if ((engine.jsonRpcClient.connected && pageStack.depth > 1)
// if we're not connected, only allow using the back button in wizards
|| (!engine.jsonRpcClient.connected && pageStack.depth > 3)) {
close.accepted = false;
pageStack.pop();
}
function handleAndroidBackButton() {
// If we're connected, allow going back up to MainPage
if ((engine.jsonRpcClient.connected && pageStack.depth > 1)
// if we're not connected, only allow using the back button in wizards
|| (!engine.jsonRpcClient.connected && pageStack.depth > 3)) {
pageStack.pop();
return true;
}
return false;
}
function setupPushNotifications(askForPermissions) {

View File

@ -75,7 +75,7 @@
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26"/>
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.