Add background notification checking and display (close #17)

Framework7
Skylar Ittner 6 years ago
parent 27a0904ec7
commit 675248dfd3

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.netsyms.BusinessMobile" version="1.6" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="com.netsyms.BusinessMobile" version="1.7" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Business</name>
<description>
Mobile client for the Netsyms Business Apps.
@ -26,6 +26,10 @@
<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="HeaderColor" value="#2196f3" />
<preference name="StatusBarBackgroundColor" value="#1976d2" />
<preference name="stopOnTerminate" value="false" />
<preference name="startOnBoot" value="true" />
<preference name="forceReload" value="true" />
<preference name="minimumFetchInterval" value="1" />
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" />
</edit-config>
@ -43,6 +47,10 @@
<resource-file src="res/android/mipmap-xxhdpi/ic_launcher_round.png" target="app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png" />
<resource-file src="res/android/mipmap-xxxhdpi/ic_launcher.png" target="app/src/main/res/mipmap-xxxhdpi/ic_launcher.png" />
<resource-file src="res/android/mipmap-xxxhdpi/ic_launcher_round.png" target="app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png" />
<resource-file src="res/android/drawable-hdpi/ic_notification.png" target="app/src/main/res/drawable-hdpi/ic_notification.png" />
<resource-file src="res/android/drawable-mdpi/ic_notification.png" target="app/src/main/res/drawable-mdpi/ic_notification.png" />
<resource-file src="res/android/drawable-xhdpi/ic_notification.png" target="app/src/main/res/drawable-xhdpi/ic_notification.png" />
<resource-file src="res/android/drawable-xxhdpi/ic_notification.png" target="app/src/main/res/drawable-xxhdpi/ic_notification.png" />
<splash density="port-ldpi" src="res/screen/android/splash-port-ldpi.png" />
<splash density="port-mdpi" src="res/screen/android/splash-port-mdpi.png" />
<splash density="port-hdpi" src="res/screen/android/splash-port-hdpi.png" />
@ -72,5 +80,8 @@
<plugin name="cordova-plugin-dialogs" spec="^2.0.1" />
<plugin name="cordova-plugin-inappbrowser" spec="^2.0.2" />
<plugin name="cordova-plugin-splashscreen" spec="^5.0.2" />
<engine name="android" spec="^7.1.0" />
<plugin name="cordova-plugin-nativestorage" spec="^2.3.2" />
<plugin name="cordova-plugin-background-fetch" spec="^5.4.1" />
<plugin name="cordova-plugin-local-notification" spec="^0.9.0-beta.2" />
<engine name="android" spec="^7.1.1" />
</widget>

@ -9,4 +9,7 @@ cordova-plugin-headercolor=https://github.com/tomloprod/cordova-plugin-headercol
cordova-plugin-inappbrowser=https://github.com/apache/cordova-plugin-inappbrowser.git
cordova-plugin-app-version=https://github.com/whiteoctober/cordova-plugin-app-version.git
cordova-plugin-zeroconf=https://github.com/becvert/cordova-plugin-zeroconf.git
cordova-plugin-file=https://github.com/apache/cordova-plugin-file.git
cordova-plugin-file=https://github.com/apache/cordova-plugin-file.git
cordova-plugin-local-notification=https://github.com/katzer/cordova-plugin-local-notifications.git
cordova-plugin-background-fetch=https://github.com/transistorsoft/cordova-plugin-background-fetch.git
cordova-plugin-nativestorage=https://github.com/TheCocoaProject/cordova-plugin-nativestorage.git

@ -1,15 +1,17 @@
{
"name": "com.netsyms.BusinessMobile",
"displayName": "Business for Mobile",
"version": "1.6.0",
"version": "1.7.0",
"description": "Mobile client for the Netsyms Business Apps.",
"main": "index.html",
"author": "Netsyms Technologies",
"license": "MPL-2.0",
"dependencies": {
"cordova-android": "^7.1.0",
"cordova-android": "^7.1.1",
"cordova-plugin-add-swift-support": "^1.7.1",
"cordova-plugin-app-version": "^0.1.9",
"cordova-plugin-background-fetch": "^5.4.1",
"cordova-plugin-badge": "^0.8.7",
"cordova-plugin-console": "^1.1.0",
"cordova-plugin-device": "^2.0.1",
"cordova-plugin-dialog": "0.0.1",
@ -17,6 +19,8 @@
"cordova-plugin-file": "^6.0.1",
"cordova-plugin-headercolor": "^1.0.0",
"cordova-plugin-inappbrowser": "^2.0.2",
"cordova-plugin-local-notification": "^0.9.0-beta.2",
"cordova-plugin-nativestorage": "^2.3.2",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.1",
"cordova-plugin-whitelist": "^1.3.2",
@ -39,7 +43,10 @@
"cordova-plugin-device": {},
"cordova-plugin-dialogs": {},
"cordova-plugin-inappbrowser": {},
"cordova-plugin-splashscreen": {}
"cordova-plugin-splashscreen": {},
"cordova-plugin-nativestorage": {},
"cordova-plugin-background-fetch": {},
"cordova-plugin-local-notification": {}
},
"platforms": [
"android"

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 599 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 727 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 536 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 731 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1021 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 681 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -0,0 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="app_name">Business</string>
<string name="launcher_name">@string/app_name</string>
<string name="activity_name">@string/launcher_name</string>
</resources>

@ -30,6 +30,7 @@ function getaccounts() {
function saveaccounts(accounts) {
localStorage.setItem("accounts", JSON.stringify(accounts));
NativeStorage.setItem("accounts", JSON.stringify(accounts));
}
/**

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var shown_notifications = [];
/**
* Switches the app to the given screen.
* @param {String} screenname The name of the screen to show.
@ -198,6 +200,42 @@ function restartApplication() {
}, 3000);
}
function displayNotifications(callback) {
$.post(localStorage.getItem("syncurl"), {
username: localStorage.getItem("username"),
key: localStorage.getItem("key"),
password: localStorage.getItem("password"),
action: "checknotifications"
}, function (data) {
if (data.status === 'OK') {
for (var i = 0; i < data.notifications.length; i++) {
var n = data.notifications[i];
if (n.seen || shown_notifications.includes(n.id)) {
continue;
}
cordova.plugins.notification.local.schedule([{
title: n.title,
text: n.content,
actions: [
{id: 'mark_read', title: "Mark Read"}
],
id: n.id
}]);
shown_notifications.push(n.id);
}
}
if (typeof callback == 'function') {
callback();
}
}, "json").fail(function () {
if (typeof callback == 'function') {
callback();
}
});
}
// Handle back button to close things
document.addEventListener("backbutton", function (event) {
if (isconfigvalid()) {
@ -225,6 +263,20 @@ document.addEventListener("deviceready", function () {
StatusBar.backgroundColorByHexString("#1976d2");
}
cordova.plugins.notification.local.setDefaults({
led: {color: '#2196F3'},
smallIcon: "res://ic_notification"
});
cordova.plugins.notification.local.on("mark_read", function (notification) {
$.post(localStorage.getItem("syncurl"), {
username: localStorage.getItem("username"),
key: localStorage.getItem("key"),
password: localStorage.getItem("password"),
action: "readnotification",
id: notification.id
});
});
// Enable/disable jQuery animations depending on user preference
$.fx.off = !(localStorage.getItem("animations") === null || localStorage.getItem("animations") === "true");
@ -236,6 +288,32 @@ document.addEventListener("deviceready", function () {
if (isconfigvalid()) {
getuserinfo(function () {
openscreen("home");
setInterval(displayNotifications, 30 * 1000);
if (typeof cordova.plugins.notification.local.launchDetails === 'undefined') {
displayNotifications();
}
var BackgroundFetch = window.BackgroundFetch;
// Your background-fetch handler.
var fetchCallback = function () {
console.log('[js] BackgroundFetch event received');
displayNotifications(function () {
BackgroundFetch.finish();
});
};
var failureCallback = function (error) {
console.log('- BackgroundFetch failed', error);
};
BackgroundFetch.configure(fetchCallback, failureCallback, {
minimumFetchInterval: 1,
stopOnTerminate: false,
startOnBoot: true,
forceReload: true
});
});
} else {
openscreen("setup1");

Loading…
Cancel
Save