Commit 34df2c6b authored by Johannes Schwab's avatar Johannes Schwab

client: clean up

parent c35e7ca0
......@@ -37,9 +37,6 @@ Backend::Backend()
sendSyncKeyAsync(nullptr),
recvSyncKeyAsync(nullptr),
recipes(SqlBackend::getRecipes())
#ifdef Q_OS_ANDROID
, androidResultReceiver(this)
#endif
{
for (auto &r : recipes) r->setParent(this);
sortRecipes();
......@@ -294,7 +291,7 @@ void Backend::setupSyncFromKey(const QString &key) {
}
#ifdef Q_OS_ANDROID
void Backend::AndroidResultReceiver::handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data) {
void Backend::handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data) {
switch (receiverRequestCode) {
case static_cast<int>(AndroidRequestCodes::GetImage):
{
......@@ -303,7 +300,7 @@ void Backend::AndroidResultReceiver::handleActivityResult(int receiverRequestCod
} else {
QAndroidJniObject uri = data.callObjectMethod("getData", "()Landroid/net/Uri;");
QAndroidJniObject img = QAndroidJniObject::callStaticObjectMethod("org/jschwab/openrecipes/Helpers", "readImage", "(Landroid/net/Uri;Landroid/content/Context;)Ljava/lang/String;", uri.object(), QtAndroid::androidContext().object());
emit backend->openImage(img.toString());
emit openImage(img.toString());
}
}
break;
......@@ -314,7 +311,7 @@ void Backend::AndroidResultReceiver::handleActivityResult(int receiverRequestCod
} else {
QAndroidJniObject scanResult = QAndroidJniObject::fromString("SCAN_RESULT");
QString qrcode = data.callObjectMethod("getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;", scanResult.object<jstring>()).toString();
backend->setupSyncFromKey(qrcode);
setupSyncFromKey(qrcode);
}
}
default:
......@@ -331,7 +328,7 @@ void Backend::requestImage() {
QAndroidJniObject category = QAndroidJniObject::getStaticObjectField<jstring>("android/content/Intent", "CATEGORY_OPENABLE");
intent.handle().callObjectMethod("addCategory", "(Ljava/lang/String;)Landroid/content/Intent;", category.object<jstring>());
QtAndroid::startActivity(intent.handle(), static_cast<int>(AndroidRequestCodes::GetImage), &androidResultReceiver);
QtAndroid::startActivity(intent.handle(), static_cast<int>(AndroidRequestCodes::GetImage), this);
QAndroidJniEnvironment jniEnv;
if (jniEnv->ExceptionCheck()) jniEnv->ExceptionClear();
}
......@@ -343,7 +340,7 @@ void Backend::requestQRCode() {
QAndroidJniObject qrCodeMode = QAndroidJniObject::fromString("QR_CODE_MODE");
intent.handle().callObjectMethod("putExtra", "(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;", scanMode.object<jstring>(), qrCodeMode.object<jstring>());
QtAndroid::startActivity(intent.handle(), static_cast<int>(AndroidRequestCodes::GetQRCode), &androidResultReceiver);
QtAndroid::startActivity(intent.handle(), static_cast<int>(AndroidRequestCodes::GetQRCode), this);
QAndroidJniEnvironment jniEnv;
if (jniEnv->ExceptionCheck()) {
......
......@@ -34,7 +34,11 @@ class SynchronizeAsync;
class SendSyncKeyAsync;
class RecvSyncKeyAsync;
#ifdef Q_OS_ANDROID
class Backend : public QObject, public QAndroidActivityResultReceiver {
#else
class Backend : public QObject {
#endif
Q_OBJECT
Q_PROPERTY(QQmlListProperty<Recipe> recipesList READ getRecipesList NOTIFY recipesListChanged)
Q_PROPERTY(QString syncKeyHex READ getSyncKeyHex NOTIFY syncSettingsChanged);
......@@ -61,16 +65,7 @@ class Backend : public QObject {
GetQRCode
};
class AndroidResultReceiver : public QAndroidActivityResultReceiver {
private:
Backend *const backend;
void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data) final;
public:
explicit AndroidResultReceiver(Backend *const backend) : backend(backend) {};
};
AndroidResultReceiver androidResultReceiver;
void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data) override;
#endif
public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment