From 275fff2d227cd8e7784e32b37d56b6f5e60a3759 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Sun, 20 Jun 2021 19:04:36 +0200 Subject: [PATCH] Add propper link handling --- android/AndroidManifest.xml | 17 +++---- .../src/de/itsblue/blueROCK/MainActivity.java | 3 ++ headers/bluerockbackend.h | 6 ++- headers/shareUtils/androidshareutils.h | 1 + headers/shareUtils/platformshareutils.h | 1 + headers/shareUtils/shareutils.h | 2 + resources/qml/Widgets/CalendarWidget.qml | 9 +++- resources/qml/main.qml | 6 ++- sources/bluerockbackend.cpp | 48 +++++++++++++------ sources/shareUtils/androidshareutils.cpp | 27 +++++++++++ sources/shareUtils/shareutils.cpp | 8 ++++ 11 files changed, 101 insertions(+), 27 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 4bc235f..be5f1c5 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -69,17 +69,14 @@ - - - - - - + - - - + + + + + @@ -89,5 +86,5 @@ - + diff --git a/android/src/de/itsblue/blueROCK/MainActivity.java b/android/src/de/itsblue/blueROCK/MainActivity.java index 24d2923..8bf57ae 100755 --- a/android/src/de/itsblue/blueROCK/MainActivity.java +++ b/android/src/de/itsblue/blueROCK/MainActivity.java @@ -39,6 +39,8 @@ public class MainActivity extends QtActivity // native - must be implemented in Cpp via JNI // 'file' scheme or resolved from 'content' scheme: public static native void setFileUrlReceived(String url); + // + public static native void setOtherUrlReceived(String url, String scheme); // InputStream from 'content' scheme: public static native void setFileReceivedAndSaved(String url); // @@ -178,6 +180,7 @@ public class MainActivity extends QtActivity } if(!intentScheme.equals("content")){ Log.d("ekkescorner Intent URI unknown scheme: ", intentScheme); + setOtherUrlReceived(intentUri.toString(), intentScheme); return; } // ok - it's a content scheme URI diff --git a/headers/bluerockbackend.h b/headers/bluerockbackend.h index 0819bb9..fa20efe 100644 --- a/headers/bluerockbackend.h +++ b/headers/bluerockbackend.h @@ -48,8 +48,9 @@ private: ShareUtils* _shareUtils; const QStringList _validBaseDomains = {"digitalrock.de", "bluerock.dev"}; - + bool _pendingIntentsChecked; signals: + Q_INVOKABLE void openedViaUrl(QString url, QString scheme); public slots: @@ -57,6 +58,9 @@ public slots: QVariantMap getParamsFromUrl(QString url); void shareResultsAsUrl(QString url, QString compName); void shareResultsAsPoster(QString url, QString compName); +#if defined(Q_OS_ANDROID) + void onApplicationStateChanged(Qt::ApplicationState applicationState); +#endif }; diff --git a/headers/shareUtils/androidshareutils.h b/headers/shareUtils/androidshareutils.h index 2080ddb..5a3d81a 100755 --- a/headers/shareUtils/androidshareutils.h +++ b/headers/shareUtils/androidshareutils.h @@ -31,6 +31,7 @@ public: public slots: void setFileUrlReceived(const QString &url); + void setOtherUrlReceived(const QString &url, const QString &scheme); void setFileReceivedAndSaved(const QString &url); bool checkFileExits(const QString &url); diff --git a/headers/shareUtils/platformshareutils.h b/headers/shareUtils/platformshareutils.h index 381b0ba..310917d 100644 --- a/headers/shareUtils/platformshareutils.h +++ b/headers/shareUtils/platformshareutils.h @@ -31,6 +31,7 @@ signals: void shareNoAppAvailable(int requestCode); void shareError(int requestCode, QString message); void fileUrlReceived(QString url); + void otherUrlReceived(QString url, QString scheme); void fileReceivedAndSaved(QString url); public: diff --git a/headers/shareUtils/shareutils.h b/headers/shareUtils/shareutils.h index 192d2fd..6eb61df 100755 --- a/headers/shareUtils/shareutils.h +++ b/headers/shareUtils/shareutils.h @@ -32,6 +32,7 @@ signals: void shareNoAppAvailable(int requestCode); void shareError(int requestCode, QString message); void fileUrlReceived(QString url); + void otherUrlReceived(QString url, QString scheme); void fileReceivedAndSaved(QString url); public slots: @@ -40,6 +41,7 @@ public slots: void onShareNoAppAvailable(int requestCode); void onShareError(int requestCode, QString message); void onFileUrlReceived(QString url); + void onOtherUrlReceived(QString url, QString scheme); void onFileReceivedAndSaved(QString url); public: diff --git a/resources/qml/Widgets/CalendarWidget.qml b/resources/qml/Widgets/CalendarWidget.qml index dbbc19d..c332684 100644 --- a/resources/qml/Widgets/CalendarWidget.qml +++ b/resources/qml/Widgets/CalendarWidget.qml @@ -110,10 +110,17 @@ DataListView { initFilters() initFavorites() - if(model){ + console.log(JSON.stringify(widgetData)) + + if(model && widgetData["competitions"].length > 0){ control.status = 200 control.ready = true } + else if(widgetData["competitions"].length === 0) { + control.status = 404 + control.ready = false + } + else { control.ready = false control.status = 901 diff --git a/resources/qml/main.qml b/resources/qml/main.qml index 5f6242d..15b80d0 100644 --- a/resources/qml/main.qml +++ b/resources/qml/main.qml @@ -134,7 +134,7 @@ Window { //app.openAthlete() // dorian: 53139 , rustam: 6933 , helen: 53300 //openWidget({nation:'GER'}) //mainStack.push("Pages/AthleteSearchPage.qml") - openWidget({comp: 11651, cat: 26}) + //openWidget({comp: 11651, cat: 26}) //openWidget({person: 6623}) //console.log(JSON.stringify(serverConn.getParamsFromUrl(""))) } @@ -157,6 +157,10 @@ Window { BlueRockBackend { id: serverConn + + onOpenedViaUrl: { + app.openWidgetFromUrl(url) + } } AppSettings { diff --git a/sources/bluerockbackend.cpp b/sources/bluerockbackend.cpp index 726dcf8..3f6cc03 100644 --- a/sources/bluerockbackend.cpp +++ b/sources/bluerockbackend.cpp @@ -18,26 +18,28 @@ #include "headers/bluerockbackend.h" -BlueRockBackend::BlueRockBackend(QObject *parent) : QObject(parent) +BlueRockBackend::BlueRockBackend(QObject *parent) : QObject(parent), _pendingIntentsChecked(false) { this->_shareUtils = new ShareUtils(this); + connect(this->_shareUtils, &ShareUtils::otherUrlReceived, this, &BlueRockBackend::openedViaUrl); + +#if defined(Q_OS_ANDROID) + connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onApplicationStateChanged(Qt::ApplicationState))); +#endif } QVariant BlueRockBackend::getWidgetData(QVariantMap params) { - QString requestUrl; + QString requestUrl = "https://www.digitalrock.de/egroupware/ranking/json.php?"; + QStringList nations = {"ICC", "GER", "SUI"}; if(params["nation"].toString() == "ICC") { - requestUrl = "https://www.digitalrock.de/egroupware/ranking/json.php?"; params["nation"] = ""; } - else if (params["nation"].toString() == "GER") { - requestUrl = "https://www.digitalrock.de/egroupware/ranking/json.php?"; - } - else if (params["nation"].toString() == "SUI") { - requestUrl = "https://www.digitalrock.de/egroupware/ranking/json.php?"; - } - else { + else if(params["nation"].toString() == "") { params.remove("nation"); - requestUrl = "https://www.digitalrock.de/egroupware/ranking/json.php?"; + } + else if(!nations.contains(params["nation"].toString())) { + // a non-empty nation which ist not one of the above is invalid + return QVariantMap({{"status", 404}}); } for(QVariantMap::const_iterator iter = params.begin(); iter != params.end(); ++iter) { @@ -203,9 +205,27 @@ QVariantMap BlueRockBackend::_senddata(QUrl serviceUrl, QUrlQuery pdata) return(ret); } +#if defined(Q_OS_ANDROID) +void BlueRockBackend::onApplicationStateChanged(Qt::ApplicationState applicationState) +{ + qDebug() << "S T A T E changed into: " << applicationState; + if(applicationState == Qt::ApplicationState::ApplicationSuspended) { + // nothing to do + return; + } + if(applicationState == Qt::ApplicationState::ApplicationActive) { + // if App was launched from VIEW or SEND Intent + // there's a race collision: the event will be lost, + // because App and UI wasn't completely initialized + // workaround: QShareActivity remembers that an Intent is pending + if(!_pendingIntentsChecked) { + _pendingIntentsChecked = true; + _shareUtils->checkPendingIntents(this->_shareUtils->getTemporaryFileLocationPath()); + } + } +} +#endif + // ------------------------- // --- Functions for QML --- // ------------------------- - - - diff --git a/sources/shareUtils/androidshareutils.cpp b/sources/shareUtils/androidshareutils.cpp index bbe9d90..d6a98b8 100755 --- a/sources/shareUtils/androidshareutils.cpp +++ b/sources/shareUtils/androidshareutils.cpp @@ -236,6 +236,18 @@ void AndroidShareUtils::setFileUrlReceived(const QString &url) } } +void AndroidShareUtils::setOtherUrlReceived(const QString &url, const QString &scheme) +{ + if(url.isEmpty()) { + qWarning() << "setFileUrlReceived: we got an empty URL"; + emit shareError(0, tr("Empty URL received")); + return; + } + qDebug() << "AndroidShareUtils setOtherUrlReceived: we got the Other URL from JAVA: " << url; + + emit otherUrlReceived(url, scheme); +} + void AndroidShareUtils::setFileReceivedAndSaved(const QString &url) { if(url.isEmpty()) { @@ -311,6 +323,21 @@ Java_de_itsblue_blueROCK_MainActivity_setFileUrlReceived(JNIEnv *env, return; } +JNIEXPORT void JNICALL +Java_de_itsblue_blueROCK_MainActivity_setOtherUrlReceived(JNIEnv *env, + jobject obj, + jstring url, + jstring scheme) +{ + const char *urlStr = env->GetStringUTFChars(url, NULL); + const char *schemeStr = env->GetStringUTFChars(scheme, NULL); + Q_UNUSED (obj) + AndroidShareUtils::getInstance()->setOtherUrlReceived(urlStr, schemeStr); + env->ReleaseStringUTFChars(url, urlStr); + env->ReleaseStringUTFChars(scheme, schemeStr); + return; +} + JNIEXPORT void JNICALL Java_de_itsblue_blueROCK_MainActivity_setFileReceivedAndSaved(JNIEnv *env, jobject obj, diff --git a/sources/shareUtils/shareutils.cpp b/sources/shareUtils/shareutils.cpp index d87a500..78a3f0a 100755 --- a/sources/shareUtils/shareutils.cpp +++ b/sources/shareUtils/shareutils.cpp @@ -38,6 +38,9 @@ ShareUtils::ShareUtils(QObject *parent) connectResult = connect(mPlatformShareUtils, &PlatformShareUtils::fileUrlReceived, this, &ShareUtils::onFileUrlReceived); Q_ASSERT(connectResult); + connectResult = connect(mPlatformShareUtils, &PlatformShareUtils::otherUrlReceived, this, &ShareUtils::onOtherUrlReceived); + Q_ASSERT(connectResult); + connectResult = connect(mPlatformShareUtils, &PlatformShareUtils::fileReceivedAndSaved, this, &ShareUtils::onFileReceivedAndSaved); Q_ASSERT(connectResult); @@ -109,6 +112,11 @@ void ShareUtils::onFileUrlReceived(QString url) emit fileUrlReceived(url); } +void ShareUtils::onOtherUrlReceived(QString url, QString scheme) +{ + emit otherUrlReceived(url, scheme); +} + void ShareUtils::onFileReceivedAndSaved(QString url) { emit fileReceivedAndSaved(url);