Merge PR #136: Fix TabBar and SwipeView in MainView getting out of sync
This commit is contained in:
commit
f08f336c49
@ -243,7 +243,7 @@ void DeviceManager::getConfiguredDevicesResponse(const QVariantMap ¶ms)
|
|||||||
}
|
}
|
||||||
// qDebug() << "Configured Device JSON:" << qUtf8Printable(QJsonDocument::fromVariant(deviceVariant).toJson(QJsonDocument::Indented));
|
// qDebug() << "Configured Device JSON:" << qUtf8Printable(QJsonDocument::fromVariant(deviceVariant).toJson(QJsonDocument::Indented));
|
||||||
devices()->addDevice(device);
|
devices()->addDevice(device);
|
||||||
qDebug() << "*** Added device:" << endl << device;
|
// qDebug() << "*** Added device:" << endl << device;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_fetchingData = false;
|
m_fetchingData = false;
|
||||||
|
|||||||
@ -162,7 +162,7 @@ void RuleManager::getRuleDetailsReply(const QVariantMap ¶ms)
|
|||||||
parseRuleExitActions(ruleMap.value("exitActions").toList(), rule);
|
parseRuleExitActions(ruleMap.value("exitActions").toList(), rule);
|
||||||
parseTimeDescriptor(ruleMap.value("timeDescriptor").toMap(), rule);
|
parseTimeDescriptor(ruleMap.value("timeDescriptor").toMap(), rule);
|
||||||
rule->setStateEvaluator(parseStateEvaluator(ruleMap.value("stateEvaluator").toMap()));
|
rule->setStateEvaluator(parseStateEvaluator(ruleMap.value("stateEvaluator").toMap()));
|
||||||
qDebug() << "** Rule details received:" << rule;
|
// qDebug() << "** Rule details received:" << rule;
|
||||||
// qDebug() << "Rule JSON:" << qUtf8Printable(QJsonDocument::fromVariant(ruleMap).toJson());
|
// qDebug() << "Rule JSON:" << qUtf8Printable(QJsonDocument::fromVariant(ruleMap).toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,26 @@ Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property int currentViewIndex: 0
|
||||||
|
|
||||||
|
property bool swipeViewReady: false
|
||||||
|
property bool tabsReady: false
|
||||||
|
|
||||||
|
readonly property bool viewReady: swipeViewReady && tabsReady
|
||||||
|
onViewReadyChanged: {
|
||||||
|
if (tabSettings.currentMainViewIndex > swipeView.count) {
|
||||||
|
tabSettings.currentMainViewIndex = swipeView.count - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load current index from settings
|
||||||
|
currentViewIndex = tabSettings.currentMainViewIndex;
|
||||||
|
// and set up a binding to sync changes back to the settings
|
||||||
|
tabSettings.currentMainViewIndex = Qt.binding(function() { return root.currentViewIndex; });
|
||||||
|
|
||||||
|
// Tabbar gets a little confused if it's bound to it before the init happened, do it now
|
||||||
|
tabBar.currentIndex = Qt.binding(function() { return root.currentViewIndex; });
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: Currently we don't have any feedback for executeAction
|
// FIXME: Currently we don't have any feedback for executeAction
|
||||||
// we don't want all the results, e.g. on looped calls like "all off"
|
// we don't want all the results, e.g. on looped calls like "all off"
|
||||||
// Connections {
|
// Connections {
|
||||||
@ -48,8 +68,10 @@ Page {
|
|||||||
|
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
|
id: mainColumn
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
@ -60,21 +82,25 @@ Page {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.leftMargin: (systemProductType === "ios" && Screen.width === 812) ? 25 : 0
|
anchors.leftMargin: (systemProductType === "ios" && Screen.width === 812) ? 25 : 0
|
||||||
anchors.rightMargin: anchors.leftMargin
|
anchors.rightMargin: anchors.leftMargin
|
||||||
opacity: engine.deviceManager.fetchingData ? 0 : 1
|
currentIndex: root.currentViewIndex
|
||||||
Behavior on opacity { NumberAnimation { duration: 300 } }
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
print("MainPage Tab index: Component.completed: settings:", tabSettings.currentMainViewIndex)
|
|
||||||
if (engine.jsonRpcClient.ensureServerVersion(1.6)) {
|
if (engine.jsonRpcClient.ensureServerVersion(1.6)) {
|
||||||
swipeView.insertItem(0, favoritesViewComponent.createObject(swipeView))
|
swipeView.insertItem(0, favoritesViewComponent.createObject(swipeView))
|
||||||
}
|
}
|
||||||
if (tabSettings.currentMainViewIndex > swipeView.count) {
|
root.swipeViewReady = true;
|
||||||
print("MainPage Tab index: setting config to", swipeView.count - 1, "(", tabSettings.currentMainViewIndex, swipeView.count, ")")
|
}
|
||||||
tabSettings.currentMainViewIndex = swipeView.count - 1;
|
onCurrentIndexChanged: {
|
||||||
|
root.currentViewIndex = currentIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
opacity: 0
|
||||||
|
Behavior on opacity { NumberAnimation { duration: 300 } }
|
||||||
|
Connections {
|
||||||
|
target: engine.deviceManager
|
||||||
|
onFetchingDataChanged: {
|
||||||
|
swipeView.opacity = engine.deviceManager.fetchingData ? 0 : 1
|
||||||
}
|
}
|
||||||
print("MainPage Tab index: setting tab to", tabSettings.currentMainViewIndex)
|
|
||||||
swipeView.currentIndex = Qt.binding(function() { return tabSettings.currentMainViewIndex; })
|
|
||||||
tabSettings.currentMainViewIndex = Qt.binding(function() { return swipeView.currentIndex; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
@ -178,7 +204,6 @@ Page {
|
|||||||
footer: TabBar {
|
footer: TabBar {
|
||||||
id: tabBar
|
id: tabBar
|
||||||
Material.elevation: 3
|
Material.elevation: 3
|
||||||
// currentIndex: tabSettings.currentMainViewIndex
|
|
||||||
position: TabBar.Footer
|
position: TabBar.Footer
|
||||||
implicitHeight: 70 + (app.landscape ?
|
implicitHeight: 70 + (app.landscape ?
|
||||||
((systemProductType === "ios" && Screen.height === 375) ? -10 : -20) :
|
((systemProductType === "ios" && Screen.height === 375) ? -10 : -20) :
|
||||||
@ -195,15 +220,15 @@ Page {
|
|||||||
}
|
}
|
||||||
tabEntryComponent.createObject(tabBar, {text: qsTr("Things"), iconSource: "../images/share.svg", pageIndex: pi++})
|
tabEntryComponent.createObject(tabBar, {text: qsTr("Things"), iconSource: "../images/share.svg", pageIndex: pi++})
|
||||||
tabEntryComponent.createObject(tabBar, {text: qsTr("Scenes"), iconSource: "../images/slideshow.svg", pageIndex: pi++})
|
tabEntryComponent.createObject(tabBar, {text: qsTr("Scenes"), iconSource: "../images/slideshow.svg", pageIndex: pi++})
|
||||||
initTimer.start()
|
root.tabsReady = true
|
||||||
}
|
}
|
||||||
Timer {
|
|
||||||
id: initTimer
|
opacity: 0
|
||||||
interval: 1
|
Behavior on opacity { NumberAnimation { duration: 300 } }
|
||||||
repeat: false
|
Connections {
|
||||||
onTriggered: {
|
target: engine.deviceManager
|
||||||
print("MainPage Tab index: restoring tab index to:", tabSettings.currentMainViewIndex)
|
onFetchingDataChanged: {
|
||||||
tabBar.currentIndex = Qt.binding(function() {return tabSettings.currentMainViewIndex;})
|
tabBar.opacity = engine.deviceManager.fetchingData ? 0 : 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +237,7 @@ Page {
|
|||||||
MainPageTabButton {
|
MainPageTabButton {
|
||||||
property int pageIndex: 0
|
property int pageIndex: 0
|
||||||
// height: tabBar.height
|
// height: tabBar.height
|
||||||
onClicked: tabSettings.currentMainViewIndex = pageIndex
|
onClicked: root.currentViewIndex = pageIndex
|
||||||
alignment: app.landscape ? Qt.Horizontal : Qt.Vertical
|
alignment: app.landscape ? Qt.Horizontal : Qt.Vertical
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user