mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Implement notifications on Android
Notify when there are unread messages
This commit is contained in:
parent
d540900df5
commit
5be6094214
10 changed files with 120 additions and 17 deletions
|
@ -27,6 +27,8 @@
|
|||
#endif
|
||||
|
||||
#include "libresapilocalclient.h"
|
||||
#include "notificationsbridge.h"
|
||||
|
||||
#include "retroshare/rsinit.h"
|
||||
|
||||
|
||||
|
@ -42,9 +44,13 @@ int main(int argc, char *argv[])
|
|||
sockPath.append("/libresapi.sock");
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
qmlRegisterType<LibresapiLocalClient>(
|
||||
"org.retroshare.qml_components.LibresapiLocalClient", 1, 0,
|
||||
"LibresapiLocalClient");
|
||||
|
||||
qmlRegisterType<NotificationsBridge>(
|
||||
"org.retroshare.qml_components.NotificationsBridge", 1, 0,
|
||||
"NotificationsBridge");
|
||||
NotificationsBridge notificationsBridge;
|
||||
engine.rootContext()->setContextProperty("notificationsBridge",
|
||||
¬ificationsBridge);
|
||||
|
||||
#ifdef QT_DEBUG
|
||||
engine.rootContext()->setContextProperty("QT_DEBUG", true);
|
||||
|
@ -66,8 +72,12 @@ int main(int argc, char *argv[])
|
|||
|
||||
rsApi.openConnection(sockPath);
|
||||
|
||||
qmlRegisterType<LibresapiLocalClient>(
|
||||
"org.retroshare.qml_components.LibresapiLocalClient", 1, 0,
|
||||
"LibresapiLocalClient");
|
||||
engine.rootContext()->setContextProperty("rsApi", &rsApi);
|
||||
engine.load(QUrl(QLatin1String("qrc:/notify.qml")));
|
||||
|
||||
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
|
||||
|
||||
return app.exec();
|
||||
}
|
|
@ -25,21 +25,24 @@ QtObject
|
|||
id: notifyRoot
|
||||
|
||||
property alias coreReady: coreWatcher.coreReady
|
||||
|
||||
property AutologinManager _aM: AutologinManager { id: coreWatcher }
|
||||
|
||||
onCoreReadyChanged: if(coreReady) refreshUnread()
|
||||
|
||||
property AutologinManager coreWatcher: AutologinManager { id: coreWatcher }
|
||||
|
||||
function refreshUnreadCallback(par)
|
||||
{
|
||||
console.log("notifyRoot.refreshUnreadCB()")
|
||||
var json = JSON.parse(par.response)
|
||||
TokensManager.registerToken(json.statetoken, refreshUnread)
|
||||
if(json.data.length > 0)
|
||||
var convCnt = json.data.length
|
||||
if(convCnt > 0)
|
||||
{
|
||||
console.log("notifyRoot.refreshUnreadCB() got", json.data.length,
|
||||
"unread messages")
|
||||
//TODO: display android notification
|
||||
"unread conversations")
|
||||
notificationsBridge.notify(
|
||||
qsTr("New message!"),
|
||||
qsTr("Unread messages in %1 conversations").arg(convCnt)
|
||||
)
|
||||
}
|
||||
}
|
||||
function refreshUnread()
|
44
retroshare-android-notify-service/src/notificationsbridge.h
Normal file
44
retroshare-android-notify-service/src/notificationsbridge.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
/*
|
||||
* RetroShare Android Service
|
||||
* Copyright (C) 2017 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtAndroidExtras/QAndroidJniObject>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QtAndroid>
|
||||
#include <QDebug>
|
||||
|
||||
struct NotificationsBridge : QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
static void notify(const QString& title, const QString& text = "",
|
||||
const QString& uri = "")
|
||||
{
|
||||
qDebug() << __PRETTY_FUNCTION__ << title << text << uri;
|
||||
|
||||
QtAndroid::androidService().callMethod<void>(
|
||||
"notify",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
|
||||
QAndroidJniObject::fromString(title).object(),
|
||||
QAndroidJniObject::fromString(text).object(),
|
||||
QAndroidJniObject::fromString(uri).object()
|
||||
);
|
||||
}
|
||||
};
|
|
@ -1,6 +1,6 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>notify.qml</file>
|
||||
<file>main.qml</file>
|
||||
<file>TokensManager.qml</file>
|
||||
<file>AutologinManager.qml</file>
|
||||
<file>qmldir</file>
|
||||
|
|
|
@ -10,11 +10,17 @@ CONFIG += dll
|
|||
|
||||
RESOURCES += qml.qrc
|
||||
|
||||
android-g++:TEMPLATE = lib
|
||||
!android-g++:TEMPLATE = app
|
||||
TEMPLATE = app
|
||||
|
||||
android-g++
|
||||
{
|
||||
TEMPLATE = lib
|
||||
QT += androidextras
|
||||
HEADERS += notificationsbridge.h
|
||||
}
|
||||
|
||||
HEADERS += libresapilocalclient.h
|
||||
SOURCES += libresapilocalclient.cpp notify.cpp
|
||||
SOURCES += libresapilocalclient.cpp main.cpp
|
||||
|
||||
DEPENDPATH *= ../../libretroshare/src
|
||||
INCLUDEPATH *= ../../libretroshare/src
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue