diff --git a/src/notifybyandroid.h b/src/notifybyandroid.h --- a/src/notifybyandroid.h +++ b/src/notifybyandroid.h @@ -34,14 +34,16 @@ // interface of KNotificationPlugin QString optionName() override; void notify(KNotification *notification, KNotifyConfig *config) override; + void update(KNotification *notification, KNotifyConfig *config) override; void close(KNotification * notification) override; // interface from Java void notificationFinished(int id); void notificationActionInvoked(int id, int action); private: void notifyDeferred(KNotification *notification); + QAndroidJniObject createAndroidNotification(KNotification *notification, KNotifyConfig *config) const; QAndroidJniObject m_backend; QHash> m_notifications; diff --git a/src/notifybyandroid.cpp b/src/notifybyandroid.cpp --- a/src/notifybyandroid.cpp +++ b/src/notifybyandroid.cpp @@ -98,19 +98,17 @@ QMetaObject::invokeMethod(this, [this, notification](){ notifyDeferred(notification); }, Qt::QueuedConnection); } -void NotifyByAndroid::notifyDeferred(KNotification* notification) +QAndroidJniObject NotifyByAndroid::createAndroidNotification(KNotification *notification, KNotifyConfig *config) const { - KNotifyConfig config(notification->appName(), notification->contexts(), notification->eventId()); QAndroidJniEnvironment env; - QAndroidJniObject n("org/kde/knotifications/KNotification", "()V"); n.setField("id", notification->id()); n.setField("text", QAndroidJniObject::fromString(stripRichText(notification->text())).object()); n.setField("title", QAndroidJniObject::fromString(stripRichText(notification->title())).object()); n.setField("channelId", QAndroidJniObject::fromString(notification->eventId()).object()); - n.setField("channelName", QAndroidJniObject::fromString(config.readEntry(QLatin1String("Name"))).object()); - n.setField("channelDescription", QAndroidJniObject::fromString(config.readEntry(QLatin1String("Comment"))).object()); + n.setField("channelName", QAndroidJniObject::fromString(config->readEntry(QLatin1String("Name"))).object()); + n.setField("channelDescription", QAndroidJniObject::fromString(config->readEntry(QLatin1String("Comment"))).object()); // icon QPixmap pixmap; @@ -135,11 +133,24 @@ n.callMethod("addAction", "(Ljava/lang/String;)V", QAndroidJniObject::fromString(action).object()); } + return n; +} + +void NotifyByAndroid::notifyDeferred(KNotification* notification) +{ + KNotifyConfig config(notification->appName(), notification->contexts(), notification->eventId()); + const auto n = createAndroidNotification(notification, &config); m_notifications.insert(notification->id(), notification); m_backend.callMethod("notify", "(Lorg/kde/knotifications/KNotification;)V", n.object()); } +void NotifyByAndroid::update(KNotification *notification, KNotifyConfig *config) +{ + const auto n = createAndroidNotification(notification, config); + m_backend.callMethod("notify", "(Lorg/kde/knotifications/KNotification;)V", n.object()); +} + void NotifyByAndroid::close(KNotification* notification) { m_backend.callMethod("close", "(I)V", notification->id());