Commit 2d4545fd authored by Volker Krause's avatar Volker Krause

Remove the remaining Intent-related JNI code from the app

parent 150c903a
...@@ -107,9 +107,11 @@ static void importDavDroidJson(JNIEnv *env, jobject that, jstring data) ...@@ -107,9 +107,11 @@ static void importDavDroidJson(JNIEnv *env, jobject that, jstring data)
static void importFromIntent(JNIEnv *env, jobject that, jobject data) static void importFromIntent(JNIEnv *env, jobject that, jobject data)
{ {
Q_UNUSED(that); Q_UNUSED(that)
Q_UNUSED(env) Q_UNUSED(env)
ApplicationController::instance()->importFromIntent(data);
KAndroidExtras::Intent intent(data);
ApplicationController::instance()->importFromUrl(intent.getData());
} }
static const JNINativeMethod methods[] = { static const JNINativeMethod methods[] = {
...@@ -175,14 +177,6 @@ void ApplicationController::setDocumentManager(DocumentManager* docMgr) ...@@ -175,14 +177,6 @@ void ApplicationController::setDocumentManager(DocumentManager* docMgr)
m_docMgr = docMgr; m_docMgr = docMgr;
} }
#ifdef Q_OS_ANDROID
void ApplicationController::importFromIntent(const QAndroidJniObject &intent)
{
KAndroidExtras::Intent i(intent);
importFromUrl(i.getData());
}
#endif
void ApplicationController::showImportFileDialog() void ApplicationController::showImportFileDialog()
{ {
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
...@@ -191,7 +185,9 @@ void ApplicationController::showImportFileDialog() ...@@ -191,7 +185,9 @@ void ApplicationController::showImportFileDialog()
intent.setAction(Intent::ACTION_OPEN_DOCUMENT()); intent.setAction(Intent::ACTION_OPEN_DOCUMENT());
intent.addCategory(Intent::CATEGORY_OPENABLE()); intent.addCategory(Intent::CATEGORY_OPENABLE());
intent.setType(QStringLiteral("*/*")); intent.setType(QStringLiteral("*/*"));
QtAndroid::startActivity(intent, 0, new ActivityResultReceiver([this](int, int, const QAndroidJniObject &intent) { importFromIntent(intent); })); QtAndroid::startActivity(intent, 0, new ActivityResultReceiver([this](int, int, const QAndroidJniObject &intent) {
importFromUrl(KAndroidExtras::Intent(intent).getData());
}));
#else #else
const auto url = QFileDialog::getOpenFileUrl(nullptr, i18n("Import Reservation"), const auto url = QFileDialog::getOpenFileUrl(nullptr, i18n("Import Reservation"),
QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)), QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)),
......
...@@ -69,10 +69,6 @@ public: ...@@ -69,10 +69,6 @@ public:
Q_INVOKABLE void addDocument(const QString &batchId); Q_INVOKABLE void addDocument(const QString &batchId);
Q_INVOKABLE void removeDocument(const QString &batchId, const QString &docId); Q_INVOKABLE void removeDocument(const QString &batchId, const QString &docId);
// for internal use
#ifdef Q_OS_ANDROID
void importFromIntent(const QAndroidJniObject &intent);
#endif
Q_SIGNALS: Q_SIGNALS:
void clipboardContentChanged(); void clipboardContentChanged();
......
...@@ -64,6 +64,9 @@ ...@@ -64,6 +64,9 @@
#include <QQmlContext> #include <QQmlContext>
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
#include <kandroidextras/activity.h>
#include <kandroidextras/intent.h>
#include "androidcontentfileengine.h" #include "androidcontentfileengine.h"
#include <QtAndroid> #include <QtAndroid>
#include <QAndroidJniObject> #include <QAndroidJniObject>
...@@ -82,12 +85,8 @@ void handleViewIntent(ApplicationController *appController) ...@@ -82,12 +85,8 @@ void handleViewIntent(ApplicationController *appController)
{ {
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
// handle opened files // handle opened files
const auto activity = QtAndroid::androidActivity(); using namespace KAndroidExtras;
if (!activity.isValid()) appController->importFromUrl(Activity::getIntent().getData());
return;
const auto intent = activity.callObjectMethod("getIntent", "()Landroid/content/Intent;");
appController->importFromIntent(intent);
#else #else
Q_UNUSED(appController); Q_UNUSED(appController);
#endif #endif
......
add_library(KAndroidExtras STATIC add_library(KAndroidExtras STATIC
activity.cpp
contentresolver.cpp contentresolver.cpp
intent.cpp intent.cpp
uri.cpp uri.cpp
......
/*
Copyright (C) 2019 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "activity.h"
#include "intent.h"
#include <QtAndroid>
using namespace KAndroidExtras;
Intent Activity::getIntent()
{
const auto activity = QtAndroid::androidActivity();
if (!activity.isValid())
return {};
const auto intent = activity.callObjectMethod("getIntent", "()Landroid/content/Intent;");
return Intent(intent);
}
/*
Copyright (C) 2019 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef KANDROIDEXTRAS_ACTIVITY_H
#define KANDROIDEXTRAS_ACTIVITY_H
namespace KAndroidExtras {
class Intent;
/** Methods around android.app.Activity. */
namespace Activity
{
/** Returns the Intent that started the activity. */
Intent getIntent();
}
}
#endif // KANDROIDEXTRAS_ACTIVITY_H
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