Merge PR #221: Improve back button handling
This commit is contained in:
commit
dd489707c5
@ -1 +1 @@
|
|||||||
Subproject commit edc0a6fb19821d59f13087cf38c9a56932798b57
|
Subproject commit d97317e856d55a2f5399f17888f1852fee8b9553
|
||||||
@ -65,10 +65,6 @@ ApplicationWindow {
|
|||||||
}
|
}
|
||||||
property alias _discovery: discovery
|
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"]
|
property var supportedInterfaces: ["light", "weather", "media", "garagegate", "awning", "shutter", "blind", "powersocket", "heating", "sensor", "smartmeter", "evcharger", "accesscontrol", "button", "notifications", "inputtrigger", "outputtrigger", "gateway"]
|
||||||
function interfaceToString(name) {
|
function interfaceToString(name) {
|
||||||
switch(name) {
|
switch(name) {
|
||||||
@ -338,6 +334,32 @@ ApplicationWindow {
|
|||||||
return s.substr(s.length-size);
|
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 {
|
KeyboardLoader {
|
||||||
id: keyboardRect
|
id: keyboardRect
|
||||||
|
|||||||
@ -16,8 +16,8 @@ Item {
|
|||||||
color: Material.background
|
color: Material.background
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCloseEvent(close) {
|
function handleAndroidBackButton() {
|
||||||
swipeView.currentItem.handleCloseEvent(close)
|
return swipeView.currentItem.handleAndroidBackButton()
|
||||||
}
|
}
|
||||||
|
|
||||||
ListModel {
|
ListModel {
|
||||||
@ -182,16 +182,15 @@ Item {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCloseEvent(close) {
|
function handleAndroidBackButton() {
|
||||||
if (Qt.platform.os == "android") {
|
// If we're connected, allow going back up to MainPage
|
||||||
// If we're connected, allow going back up to MainPage
|
if ((engine.jsonRpcClient.connected && pageStack.depth > 1)
|
||||||
if ((engine.jsonRpcClient.connected && pageStack.depth > 1)
|
// if we're not connected, only allow using the back button in wizards
|
||||||
// if we're not connected, only allow using the back button in wizards
|
|| (!engine.jsonRpcClient.connected && pageStack.depth > 3)) {
|
||||||
|| (!engine.jsonRpcClient.connected && pageStack.depth > 3)) {
|
pageStack.pop();
|
||||||
close.accepted = false;
|
return true;
|
||||||
pageStack.pop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupPushNotifications(askForPermissions) {
|
function setupPushNotifications(askForPermissions) {
|
||||||
|
|||||||
@ -75,7 +75,7 @@
|
|||||||
|
|
||||||
</application>
|
</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"/>
|
<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.
|
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
|
||||||
|
|||||||
Reference in New Issue
Block a user