diff --git a/libnymea-app-core/discovery/nymeadiscovery.cpp b/libnymea-app-core/discovery/nymeadiscovery.cpp index 26b90d31..c395cc22 100644 --- a/libnymea-app-core/discovery/nymeadiscovery.cpp +++ b/libnymea-app-core/discovery/nymeadiscovery.cpp @@ -14,24 +14,24 @@ NymeaDiscovery::NymeaDiscovery(QObject *parent) : QObject(parent) { m_discoveryModel = new DiscoveryModel(this); connect(m_discoveryModel, &DiscoveryModel::deviceAdded, this, [this](DiscoveryDevice *device) { - if (device->uuid() != m_pendingHostResolution) { + if (!m_pendingHostResolutions.contains(device->uuid())) { return; } Connection *c = device->connections()->bestMatch(); if (!c) { qDebug() << "Host found but there isn't a valid candidate yet?"; connect(device->connections(), &Connections::connectionAdded, this, [this, device](Connection *connection) { - if (device->uuid() == m_pendingHostResolution) { - qDebug() << "Host" << m_pendingHostResolution << "resolved to" << connection->url().toString(); - m_pendingHostResolution = QUuid(); - emit serverUuidResolved(connection->url().toString()); + if (m_pendingHostResolutions.contains(device->uuid())) { + qDebug() << "Host" << device->uuid() << "resolved to" << connection->url().toString(); + m_pendingHostResolutions.removeAll(device->uuid()); + emit serverUuidResolved(device->uuid(), connection->url().toString()); } }); return; } - qDebug() << "Host" << m_pendingHostResolution << "appeared! Best match is" << c->url(); - m_pendingHostResolution = QUuid(); - emit serverUuidResolved(c->url().toString()); + qDebug() << "Host" << device->uuid() << "appeared! Best match is" << c->url(); + m_pendingHostResolutions.removeAll(device->uuid()); + emit serverUuidResolved(device->uuid(), c->url().toString()); }); m_upnp = new UpnpDiscovery(m_discoveryModel, this); @@ -133,6 +133,7 @@ void NymeaDiscovery::setAwsClient(AWSClient *awsClient) } if (m_awsClient) { + m_awsClient->fetchDevices(); connect(m_awsClient, &AWSClient::devicesFetched, this, &NymeaDiscovery::syncCloudDevices); syncCloudDevices(); } @@ -144,17 +145,17 @@ void NymeaDiscovery::resolveServerUuid(const QUuid &uuid) DiscoveryDevice *dev = m_discoveryModel->find(uuid); if (!dev) { qDebug() << "Host" << uuid << "not known yet..."; - m_pendingHostResolution = uuid; + m_pendingHostResolutions.append(uuid); return; } Connection *c = dev->connections()->bestMatch(); if (!c) { qDebug() << "Host" << uuid << "is known but doesn't have a usable connection option yet."; - m_pendingHostResolution = uuid; + m_pendingHostResolutions.append(uuid); return; } qDebug() << "Host" << uuid << "is known. Best match is" << c->url(); - emit serverUuidResolved(c->url().toString()); + emit serverUuidResolved(uuid, c->url().toString()); } void NymeaDiscovery::syncCloudDevices() diff --git a/libnymea-app-core/discovery/nymeadiscovery.h b/libnymea-app-core/discovery/nymeadiscovery.h index 0a88b994..46aaabac 100644 --- a/libnymea-app-core/discovery/nymeadiscovery.h +++ b/libnymea-app-core/discovery/nymeadiscovery.h @@ -38,7 +38,7 @@ signals: void discoveringChanged(); void awsClientChanged(); - void serverUuidResolved(const QString &url); + void serverUuidResolved(const QUuid &uuid, const QString &url); private slots: void syncCloudDevices(); @@ -54,7 +54,7 @@ private: QTimer m_cloudPollTimer; - QUuid m_pendingHostResolution; + QList m_pendingHostResolutions; }; diff --git a/nymea-app/main.cpp b/nymea-app/main.cpp index a3083e31..39ba3c66 100644 --- a/nymea-app/main.cpp +++ b/nymea-app/main.cpp @@ -119,8 +119,5 @@ int main(int argc, char *argv[]) engine->load(QUrl(QLatin1String("qrc:/ui/Nymea.qml"))); -#ifdef Q_OS_ANDROID - QtAndroid::hideSplashScreen(250); -#endif return application.exec(); } diff --git a/nymea-app/platformhelper.h b/nymea-app/platformhelper.h index a5a4a22e..d5bbbef4 100644 --- a/nymea-app/platformhelper.h +++ b/nymea-app/platformhelper.h @@ -25,6 +25,8 @@ public: Q_INVOKABLE virtual void requestPermissions() = 0; + Q_INVOKABLE virtual void hideSplashScreen() = 0; + virtual bool hasPermissions() const = 0; virtual QString machineHostname() const = 0; virtual QString deviceSerial() const = 0; diff --git a/nymea-app/platformintegration/android/platformhelperandroid.cpp b/nymea-app/platformintegration/android/platformhelperandroid.cpp index cde0ece6..0c7ee1e4 100644 --- a/nymea-app/platformintegration/android/platformhelperandroid.cpp +++ b/nymea-app/platformintegration/android/platformhelperandroid.cpp @@ -16,6 +16,16 @@ void PlatformHelperAndroid::requestPermissions() // Not using any fancy permissions in android yet... } +void PlatformHelperAndroid::hideSplashScreen() +{ + // Android's splash will flicker when fading out twice + static bool alreadyHiding = false; + if (!alreadyHiding) { + QtAndroid::hideSplashScreen(250); + alreadyHiding = true; + } +} + bool PlatformHelperAndroid::hasPermissions() const { // Not using any fancy permissions in android yet... diff --git a/nymea-app/platformintegration/android/platformhelperandroid.h b/nymea-app/platformintegration/android/platformhelperandroid.h index 06dc5053..90231bc4 100644 --- a/nymea-app/platformintegration/android/platformhelperandroid.h +++ b/nymea-app/platformintegration/android/platformhelperandroid.h @@ -13,6 +13,8 @@ public: Q_INVOKABLE void requestPermissions() override; + Q_INVOKABLE void hideSplashScreen() override; + bool hasPermissions() const override; QString machineHostname() const override; QString deviceSerial() const override; diff --git a/nymea-app/platformintegration/generic/platformhelpergeneric.cpp b/nymea-app/platformintegration/generic/platformhelpergeneric.cpp index 9c9c7145..4bb802e6 100644 --- a/nymea-app/platformintegration/generic/platformhelpergeneric.cpp +++ b/nymea-app/platformintegration/generic/platformhelpergeneric.cpp @@ -10,6 +10,11 @@ void PlatformHelperGeneric::requestPermissions() emit permissionsRequestFinished(); } +void PlatformHelperGeneric::hideSplashScreen() +{ + +} + bool PlatformHelperGeneric::hasPermissions() const { return true; diff --git a/nymea-app/platformintegration/generic/platformhelpergeneric.h b/nymea-app/platformintegration/generic/platformhelpergeneric.h index 82bb4461..315ff037 100644 --- a/nymea-app/platformintegration/generic/platformhelpergeneric.h +++ b/nymea-app/platformintegration/generic/platformhelpergeneric.h @@ -12,6 +12,8 @@ public: Q_INVOKABLE virtual void requestPermissions() override; + Q_INVOKABLE virtual void hideSplashScreen() override; + virtual bool hasPermissions() const override; virtual QString machineHostname() const override; virtual QString deviceSerial() const override; diff --git a/nymea-app/ui/Nymea.qml b/nymea-app/ui/Nymea.qml index 8ca953f6..747ece62 100644 --- a/nymea-app/ui/Nymea.qml +++ b/nymea-app/ui/Nymea.qml @@ -38,7 +38,6 @@ ApplicationWindow { property alias windowWidth: app.width property alias windowHeight: app.height property bool returnToHome: false - property bool darkTheme: false property string graphStyle: "bars" property string style: "light" property bool showHiddenOptions: false @@ -56,7 +55,7 @@ ApplicationWindow { id: discovery objectName: "discovery" awsClient: AWSClient - discovering: pageStack.currentItem.objectName === "discoveryPage" +// discovering: pageStack.currentItem.objectName === "discoveryPage" } onClosing: { diff --git a/nymea-app/ui/RootItem.qml b/nymea-app/ui/RootItem.qml index a3b7463f..59a60795 100644 --- a/nymea-app/ui/RootItem.qml +++ b/nymea-app/ui/RootItem.qml @@ -35,6 +35,14 @@ Item { tabbar.currentIndex = swipeView.currentIndex } function removeTab(index) { + if (swipeView.currentIndex === index) { + if (swipeView.currentIndex > 0) { + swipeView.currentIndex--; + } else { + swipeView.currentIndex++; + } + } + remove(index); settings.tabCount--; tabbar.currentIndex = swipeView.currentIndex @@ -89,7 +97,7 @@ Item { } Component.onCompleted: { - pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml")) + pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"), StackView.Immediate) setupPushNotifications(); } @@ -98,6 +106,7 @@ Item { pageStack.clear() if (!engine.connection.connected) { pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml")) + PlatformHelper.hideSplashScreen(); return; } @@ -118,11 +127,10 @@ Item { init(); }) } - } else if (engine.jsonRpcClient.connected) { - pageStack.push(Qt.resolvedUrl("MainPage.qml")) } else { - pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml")) + pageStack.push(Qt.resolvedUrl("MainPage.qml")) } + PlatformHelper.hideSplashScreen(); } function handleCloseEvent(close) { @@ -135,7 +143,7 @@ Item { pageStack.pop(); } } - } + } function setupPushNotifications(askForPermissions) { if (askForPermissions === undefined) { @@ -166,7 +174,7 @@ Item { onConnectedChanged: { print("json client connected changed", engine.jsonRpcClient.connected) if (engine.jsonRpcClient.connected) { - tabSettings.lastConnectedHost = engine.connection.url + tabSettings.lastConnectedHost = engine.jsonRpcClient.serverUuid } init(); } @@ -271,15 +279,23 @@ Item { id: tabbar Layout.fillWidth: true Material.elevation: 2 + position: TabBar.Footer Repeater { - model: mainRepeater.count + model: tabModel.count delegate: TabButton { id: hostTabButton property var engine: mainRepeater.itemAt(index)._engine property string serverName: engine.nymeaConfiguration.serverName Material.elevation: index + width: Math.max(150, tabbar.width / tabbar.count) + + Rectangle { + anchors.fill: parent + color: Material.foreground + opacity: 0.06 + } contentItem: RowLayout { Label { @@ -324,7 +340,6 @@ Item { } } } - } } } diff --git a/nymea-app/ui/connection/ConnectPage.qml b/nymea-app/ui/connection/ConnectPage.qml index cd3c855a..7334f351 100644 --- a/nymea-app/ui/connection/ConnectPage.qml +++ b/nymea-app/ui/connection/ConnectPage.qml @@ -11,9 +11,11 @@ Page { readonly property bool haveHosts: discovery.discoveryModel.count > 0 Component.onCompleted: { - print("completed connectPage. last connected host:", settings.lastConnectedHost) - if (settings.lastConnectedHost.length > 0) { - discovery.resolveServerUuid(settings.lastConnectedHost) + print("completed connectPage. last connected host:", tabSettings.lastConnectedHost) + if (tabSettings.lastConnectedHost.length > 0) { + discovery.resolveServerUuid(tabSettings.lastConnectedHost) + } else { + PlatformHelper.hideSplashScreen(); } // if (settings.lastConnectedHost.length > 0 && Engine.connection.connect(tabSettings.lastConnectedHost)) { @@ -24,19 +26,23 @@ Page { // pageStack.push(discoveryPage) // }) // } else { - pageStack.push(discoveryPage) + pageStack.push(discoveryPage, StackView.Immediate) // } } Connections { target: discovery onServerUuidResolved: { - connectToHost(url); + print("** resolved", uuid, tabSettings.lastConnectedHost) + if (uuid == tabSettings.lastConnectedHost) { + print("yesss") + connectToHost(url, true); + } } } - function connectToHost(url) { - var page = pageStack.push(Qt.resolvedUrl("ConnectingPage.qml")) + function connectToHost(url, noAnimations) { + var page = pageStack.push(Qt.resolvedUrl("ConnectingPage.qml"), noAnimations ? StackView.Immediate : StackView.PushTransition) page.cancel.connect(function() { engine.connection.disconnect() pageStack.pop(root, StackView.Immediate); @@ -124,10 +130,21 @@ Page { } Timer { - id: startupTimer - interval: 5000 + id: splashHideTimeout + interval: 3000 repeat: false running: true + onTriggered: { + PlatformHelper.hideSplashScreen() + startupTimer.start() + } + } + + Timer { + id: startupTimer + interval: 10000 + repeat: false + running: false } diff --git a/packaging/android/AndroidManifest.xml b/packaging/android/AndroidManifest.xml index f59d1f71..a73cc177 100644 --- a/packaging/android/AndroidManifest.xml +++ b/packaging/android/AndroidManifest.xml @@ -2,7 +2,7 @@ - + diff --git a/packaging/android/res/drawable-mdpi/splash.xml b/packaging/android/res/drawable/splash.xml similarity index 73% rename from packaging/android/res/drawable-mdpi/splash.xml rename to packaging/android/res/drawable/splash.xml index 8f4fc965..4d0cdae0 100644 --- a/packaging/android/res/drawable-mdpi/splash.xml +++ b/packaging/android/res/drawable/splash.xml @@ -2,11 +2,11 @@ - + -