Commit 23574cc6 authored by Volker Krause's avatar Volker Krause

Connect the Android calendar reading code to ReservationManager

parent 0f6845d0
......@@ -38,15 +38,59 @@
using namespace KItinerary;
#ifdef Q_OS_ANDROID
static void importReservation(JNIEnv *env, jobject that, jstring data)
{
Q_UNUSED(that);
ApplicationController::instance()->importData(env->GetStringUTFChars(data, 0));
}
static const JNINativeMethod methods[] = {
{"importReservation", "(Ljava/lang/String;)V", (void*)importReservation}
};
Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void*)
{
static bool initialized = false;
if (initialized)
return JNI_VERSION_1_6;
initialized = true;
JNIEnv *env = nullptr;
if (vm->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK) {
qCWarning(Log) << "Failed to get JNI environment.";
return -1;
}
jclass cls = env->FindClass("org/kde/itinerary/Activity");
if (env->RegisterNatives(cls, methods, sizeof(methods) / sizeof(JNINativeMethod)) < 0) {
qCWarning(Log) << "Failed to register native functions.";
return -1;
}
return JNI_VERSION_1_4;
}
#endif
ApplicationController* ApplicationController::s_instance = nullptr;
ApplicationController::ApplicationController(QObject* parent)
: QObject(parent)
#ifdef Q_OS_ANDROID
, m_activityResultReceiver(this)
#endif
{
s_instance = this;
}
ApplicationController::~ApplicationController()
{
s_instance = nullptr;
}
ApplicationController::~ApplicationController() = default;
ApplicationController* ApplicationController::instance()
{
return s_instance;
}
void ApplicationController::setReservationManager(ReservationManager* resMgr)
{
......@@ -280,6 +324,11 @@ void ApplicationController::importLocalFile(const QUrl &url)
}
}
void ApplicationController::importData(const QByteArray &data)
{
m_resMgr->importReservation(data);
}
void ApplicationController::checkCalendar()
{
#ifdef Q_OS_ANDROID
......
......@@ -49,10 +49,15 @@ public:
void importFromIntent(const QAndroidJniObject &intent);
#endif
void importLocalFile(const QUrl &url);
void importData(const QByteArray &data);
Q_INVOKABLE void checkCalendar();
static ApplicationController* instance();
private:
static ApplicationController *s_instance;
ReservationManager *m_resMgr = nullptr;
PkPassManager *m_pkPassMgr = nullptr;
......
......@@ -113,7 +113,12 @@ void ReservationManager::importReservation(const QUrl& filename)
return;
}
const auto doc = QJsonDocument::fromJson(f.readAll());
importReservation(f.readAll());
}
void ReservationManager::importReservation(const QByteArray& data)
{
const auto doc = QJsonDocument::fromJson(data);
if (!doc.isArray()) {
qCWarning(Log) << "Invalid JSON format.";
return;
......
......@@ -45,6 +45,8 @@ public:
Q_INVOKABLE void addReservation(const QVariant &res);
Q_INVOKABLE void removeReservation(const QString &id);
void importReservation(const QByteArray &data);
signals:
void reservationAdded(const QString &id);
void reservationUpdated(const QString &id);
......
......@@ -71,6 +71,8 @@ public class Activity extends QtActivity
startActivity(mapIntent);
}
public native void importReservation(String data);
/** Check the calendar for with JSON-LD data.
* This assumes the custom property serialization format used by DavDroid.
*/
......@@ -105,8 +107,7 @@ public class Activity extends QtActivity
ObjectInputStream ois = new ObjectInputStream(bis);
Object prop = ois.readObject();
if (prop instanceof XProperty) {
// TODO send this back to the C++ side
Log.i(TAG, ((XProperty)prop).getValue());
importReservation(((XProperty)prop).getValue());
}
} catch (Exception e) {
Log.i(TAG, e.toString());
......
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