diff --git a/nymea-app/resources.qrc b/nymea-app/resources.qrc index 4af9dcbf..11cbd132 100644 --- a/nymea-app/resources.qrc +++ b/nymea-app/resources.qrc @@ -40,6 +40,7 @@ ui/components/FancyHeader.qml ui/components/MainPageTile.qml ui/components/BusyOverlay.qml + ui/components/SwipeDelegateGroup.qml ui/components/AWSPasswordTextField.qml ui/components/BrightnessSlider.qml ui/components/SegmentedImage.qml diff --git a/nymea-app/ui/components/GroupedListView.qml b/nymea-app/ui/components/GroupedListView.qml index 401cf7ed..85fcebbf 100644 --- a/nymea-app/ui/components/GroupedListView.qml +++ b/nymea-app/ui/components/GroupedListView.qml @@ -1,7 +1,8 @@ import QtQuick 2.9 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.2 ListView { + id: root ScrollBar.vertical: ScrollBar {} @@ -12,4 +13,5 @@ ListView { text: app.interfaceToString(section) } + SwipeDelegateGroup {} } diff --git a/nymea-app/ui/components/SwipeDelegateGroup.qml b/nymea-app/ui/components/SwipeDelegateGroup.qml new file mode 100644 index 00000000..209e945e --- /dev/null +++ b/nymea-app/ui/components/SwipeDelegateGroup.qml @@ -0,0 +1,47 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 + +Item { + id: swipeGroup + + property ListView listView: parent + QtObject { + id: d + property var delegates: swipeGroup.listView.contentItem.children + property var delegateCache: [] + + onDelegatesChanged: { + for (var i = 0; i < d.delegates.length; i++) { + var thisItem = d.delegates[i]; + if (!thisItem.hasOwnProperty("swipe")) { + continue; + } + if (d.delegateCache.indexOf(thisItem) < 0) { + d.delegateCache.push(thisItem); + + print("cache is now", d.delegateCache.length) + + thisItem.Component.destruction.connect(function() { + print("item destroyed", thisItem) + var idx = d.delegateCache.indexOf(thisItem) + d.delegateCache.splice(idx, 1) + print("cache is now", d.delegateCache.length) + }) + + thisItem.swipe.opened.connect(function() { + for (var j = 0; j < d.delegates.length; j++) { + var otherItem = d.delegates[j]; + if (thisItem === otherItem) { + continue; + } + if (!otherItem.hasOwnProperty("swipe")) { + continue; + } + otherItem.swipe.close(); + } + }) + } + } + } + } +} diff --git a/nymea-app/ui/delegates/ThingDelegate.qml b/nymea-app/ui/delegates/ThingDelegate.qml index d38d43d1..8dbfc75b 100644 --- a/nymea-app/ui/delegates/ThingDelegate.qml +++ b/nymea-app/ui/delegates/ThingDelegate.qml @@ -19,5 +19,4 @@ MeaListItemDelegate { readonly property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null readonly property bool batteryCritical: deviceClass && deviceClass.interfaces.indexOf("battery") >= 0 ? device.stateValue(deviceClass.stateTypes.findByName("batteryCritical").id) === true : false readonly property bool disconnected: deviceClass && deviceClass.interfaces.indexOf("connectable") >= 0 ? device.stateValue(deviceClass.stateTypes.findByName("connected").id) === false : false - }