From a8cc8763b00a9c4d478dbd376694b8f416b4515e Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Thu, 10 Jan 2019 18:49:26 +0000 Subject: [PATCH] Android: Fixes #321: Removed dependency to Firebase --- ReactNativeClient/android/app/build.gradle | 7 +- .../android/app/google-services.json | 42 --------- .../android/app/src/main/AndroidManifest.xml | 87 ++++++++----------- .../net/cozic/joplin/MainApplication.java | 8 +- .../app/src/main/res/values/colors.xml | 3 + ReactNativeClient/android/build.gradle | 1 - ReactNativeClient/android/settings.gradle | 5 +- .../services/AlarmServiceDriver.android.js | 55 ++++++------ ReactNativeClient/package-lock.json | 30 ++----- ReactNativeClient/package.json | 2 +- 10 files changed, 77 insertions(+), 163 deletions(-) delete mode 100644 ReactNativeClient/android/app/google-services.json create mode 100644 ReactNativeClient/android/app/src/main/res/values/colors.xml diff --git a/ReactNativeClient/android/app/build.gradle b/ReactNativeClient/android/app/build.gradle index d0e1bc9ccb9..61416060c2b 100644 --- a/ReactNativeClient/android/app/build.gradle +++ b/ReactNativeClient/android/app/build.gradle @@ -137,7 +137,7 @@ android { } dependencies { - implementation project(':react-native-firebase') + compile project(':react-native-push-notification') implementation (project(':react-native-camera')) { // This is required because com.google.firebase requires v16.0.x of com.google.android.gms // while react-native-camera requires v15.x, which results in broken dependencies with @@ -167,8 +167,6 @@ dependencies { implementation "com.facebook.react:react-native:+" implementation "com.google.android.gms:play-services-base:16.0.1" // For Firebase - implementation "com.google.firebase:firebase-core:16.0.4" // For Firebase - implementation "com.google.firebase:firebase-messaging:17.3.4" // For Firebase implementation 'me.leolin:ShortcutBadger:1.1.21@aar' // For Firebase - this line if you wish to use badge on Android // To fix the error below, which happened after adding react-native-camera. @@ -197,5 +195,4 @@ task copyDownloadableDepsToLibs(type: Copy) { into 'libs' } -apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" -apply plugin: 'com.google.gms.google-services' // For Firebase \ No newline at end of file +apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" \ No newline at end of file diff --git a/ReactNativeClient/android/app/google-services.json b/ReactNativeClient/android/app/google-services.json deleted file mode 100644 index 73f25d388fb..00000000000 --- a/ReactNativeClient/android/app/google-services.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "project_info": { - "project_number": "790045682275", - "firebase_url": "https://joplin-b5b20.firebaseio.com", - "project_id": "joplin-b5b20", - "storage_bucket": "joplin-b5b20.appspot.com" - }, - "client": [ - { - "client_info": { - "mobilesdk_app_id": "1:790045682275:android:8b68903cf881e9f7", - "android_client_info": { - "package_name": "net.cozic.joplin" - } - }, - "oauth_client": [ - { - "client_id": "790045682275-fkusmvsm7gv3nve7h0sg0uuor9njf4sm.apps.googleusercontent.com", - "client_type": 3 - } - ], - "api_key": [ - { - "current_key": "AIzaSyCbHjUWAKcbldLTuoN7JybJ8dfznwBG_gM" - } - ], - "services": { - "analytics_service": { - "status": 1 - }, - "appinvite_service": { - "status": 1, - "other_platform_oauth_client": [] - }, - "ads_service": { - "status": 2 - } - } - } - ], - "configuration_version": "1" -} \ No newline at end of file diff --git a/ReactNativeClient/android/app/src/main/AndroidManifest.xml b/ReactNativeClient/android/app/src/main/AndroidManifest.xml index 8b0032397b4..f0011cc6794 100644 --- a/ReactNativeClient/android/app/src/main/AndroidManifest.xml +++ b/ReactNativeClient/android/app/src/main/AndroidManifest.xml @@ -11,18 +11,18 @@ - - + - - + + + + + - + - - @@ -39,56 +39,41 @@ android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme"> - - - + - - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - + - - - - diff --git a/ReactNativeClient/android/app/src/main/java/net/cozic/joplin/MainApplication.java b/ReactNativeClient/android/app/src/main/java/net/cozic/joplin/MainApplication.java index c7128fd9111..dd1dade1950 100644 --- a/ReactNativeClient/android/app/src/main/java/net/cozic/joplin/MainApplication.java +++ b/ReactNativeClient/android/app/src/main/java/net/cozic/joplin/MainApplication.java @@ -3,9 +3,7 @@ import android.app.Application; import com.facebook.react.ReactApplication; -import io.invertase.firebase.RNFirebasePackage; -import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage; -import io.invertase.firebase.messaging.RNFirebaseMessagingPackage; +import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage; import org.reactnative.camera.RNCameraPackage; import com.vinzscam.reactnativefileviewer.RNFileViewerPackage; import net.rhogan.rnsecurerandom.RNSecureRandomPackage; @@ -41,10 +39,8 @@ public boolean getUseDeveloperSupport() { protected List getPackages() { return Arrays.asList( new MainReactPackage(), + new ReactNativePushNotificationPackage(), new ImageResizerPackage(), - new RNFirebasePackage(), - new RNFirebaseMessagingPackage(), - new RNFirebaseNotificationsPackage(), new RNCameraPackage(), new RNFileViewerPackage(), new RNSecureRandomPackage(), diff --git a/ReactNativeClient/android/app/src/main/res/values/colors.xml b/ReactNativeClient/android/app/src/main/res/values/colors.xml new file mode 100644 index 00000000000..6699fd6d3f7 --- /dev/null +++ b/ReactNativeClient/android/app/src/main/res/values/colors.xml @@ -0,0 +1,3 @@ + + #FFF + \ No newline at end of file diff --git a/ReactNativeClient/android/build.gradle b/ReactNativeClient/android/build.gradle index 5065c724837..2d474feb858 100644 --- a/ReactNativeClient/android/build.gradle +++ b/ReactNativeClient/android/build.gradle @@ -14,7 +14,6 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.2.0' // Upgraded from 3.1.4 to 3.2.0 for Firebase - classpath 'com.google.gms:google-services:4.0.1' // For Firebase // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/ReactNativeClient/android/settings.gradle b/ReactNativeClient/android/settings.gradle index a9dd90dd6a0..384eae03053 100644 --- a/ReactNativeClient/android/settings.gradle +++ b/ReactNativeClient/android/settings.gradle @@ -1,6 +1,4 @@ rootProject.name = 'Joplin' -include ':react-native-firebase' -project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android') include ':react-native-camera' project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android') include ':react-native-file-viewer' @@ -33,3 +31,6 @@ include ':app', ':react-native-share-extension' project(':react-native-share-extension').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-share-extension/android') include ':react-native-version-info' project(':react-native-version-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-version-info/android') + +include ':react-native-push-notification' +project(':react-native-push-notification').projectDir = file('../node_modules/react-native-push-notification/android') \ No newline at end of file diff --git a/ReactNativeClient/lib/services/AlarmServiceDriver.android.js b/ReactNativeClient/lib/services/AlarmServiceDriver.android.js index 6976f1bc3bf..6c0254472a4 100644 --- a/ReactNativeClient/lib/services/AlarmServiceDriver.android.js +++ b/ReactNativeClient/lib/services/AlarmServiceDriver.android.js @@ -1,17 +1,23 @@ -// Note: currently, if Play Services aren't available, notifications will not work at all -// There won't be any warning or error message. - -import firebase from 'react-native-firebase'; +const PushNotification = require('react-native-push-notification'); class AlarmServiceDriver { - constructor() { - this.playServiceAvailable_ = firebase.utils().playServicesAvailability.isAvailable; - if (!this.playServiceAvailable_) return; - - this.channel_ = new firebase.notifications.Android.Channel('net.cozic.joplin.notification', 'Joplin Alarm',firebase.notifications.Android.Importance.Max) - .setDescription('Displays a notification for alarms associated with to-dos.'); - firebase.notifications().android.createChannel(this.channel_); + PushNotificationHandler_() { + if (!this.PushNotification_) { + PushNotification.configure({ + // (required) Called when a remote or local notification is opened or received + onNotification: function(notification) { + console.info('Notification was opened: ', notification ); + // process the notification + }, + popInitialNotification: true, + requestPermissions: true, + }); + + this.PushNotification_ = PushNotification; + } + + return this.PushNotification_; } hasPersistentNotifications() { @@ -22,29 +28,18 @@ class AlarmServiceDriver { throw new Error('Available only for non-persistent alarms'); } - firebaseNotificationId_(joplinNotificationId) { - return 'net.cozic.joplin-' + joplinNotificationId; - } - async clearNotification(id) { - if (!this.playServiceAvailable_) return; - - return firebase.notifications().cancelNotification(this.firebaseNotificationId_(id)) + return this.PushNotificationHandler_().cancelLocalNotifications({id: id+''}); } async scheduleNotification(notification) { - if (!this.playServiceAvailable_) return; - - const firebaseNotification = new firebase.notifications.Notification() - firebaseNotification.setNotificationId(this.firebaseNotificationId_(notification.id)); - firebaseNotification.setTitle(notification.title) - if ('body' in notification) firebaseNotification.body = notification.body; - firebaseNotification.android.setChannelId('net.cozic.joplin.notification'); - firebaseNotification.android.setSmallIcon('ic_stat_access_alarm'); - - await firebase.notifications().scheduleNotification(firebaseNotification, { - fireDate: notification.date.getTime(), - }); + const config = { + id: notification.id + '', + message: notification.title, + date: notification.date, + }; + + this.PushNotificationHandler_().localNotificationSchedule(config); } } diff --git a/ReactNativeClient/package-lock.json b/ReactNativeClient/package-lock.json index e29ca890d03..201be08b4fa 100644 --- a/ReactNativeClient/package-lock.json +++ b/ReactNativeClient/package-lock.json @@ -5981,11 +5981,6 @@ "mimic-fn": "^1.0.0" } }, - "opencollective-postinstall": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.1.tgz", - "integrity": "sha512-saQQ9hjLwu/oS0492eyYotoh+bra1819cfAT5rjY/e4REWwuc8IgZ844Oo44SiftWcJuBiqp0SA0BFVbmLX0IQ==" - }, "opn": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/opn/-/opn-3.0.3.tgz", @@ -6819,26 +6814,6 @@ "resolved": "https://registry.npmjs.org/react-native-file-viewer/-/react-native-file-viewer-1.0.5.tgz", "integrity": "sha512-/5lwmVPliEOIJMoRby9tb1s9VPxUH1ru7BfdCKxZAwZI5LoOY1qHZuUMtCHAlIKLH1DHu8fhjleJuXbRHaCuLQ==" }, - "react-native-firebase": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/react-native-firebase/-/react-native-firebase-5.1.1.tgz", - "integrity": "sha512-Iv+GKsk7pSX88BcDZUEyR02T4XjVqhQaGMmpzyDZ0cBc/Dpo7XxPfUc8M3z8hKFGPLJwvyFa6rMYTtz6RcJYEw==", - "requires": { - "opencollective-postinstall": "^2.0.0", - "prop-types": "^15.6.2" - }, - "dependencies": { - "prop-types": { - "version": "15.6.2", - "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz", - "integrity": "sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==", - "requires": { - "loose-envify": "^1.3.1", - "object-assign": "^4.1.1" - } - } - } - }, "react-native-fs": { "version": "2.11.17", "resolved": "https://registry.npmjs.org/react-native-fs/-/react-native-fs-2.11.17.tgz", @@ -6908,6 +6883,11 @@ "resolved": "https://registry.npmjs.org/react-native-popup-menu/-/react-native-popup-menu-0.10.0.tgz", "integrity": "sha1-zhU2eo1WKIfVypB+IyMB1BLd5+c=" }, + "react-native-push-notification": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/react-native-push-notification/-/react-native-push-notification-3.1.2.tgz", + "integrity": "sha512-MjjPNXb2Cw7g1D41DtVbTVuGFCAtADxb91pAEFSkQ0AZ2gIooqYkWFHBL6woc15QHhtaZS8VT2GQoyW5OWlxIg==" + }, "react-native-securerandom": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/react-native-securerandom/-/react-native-securerandom-0.1.1.tgz", diff --git a/ReactNativeClient/package.json b/ReactNativeClient/package.json index b9f3135e242..6472f6ba3f6 100644 --- a/ReactNativeClient/package.json +++ b/ReactNativeClient/package.json @@ -32,13 +32,13 @@ "react-native-document-picker": "^2.1.0", "react-native-dropdownalert": "^3.1.2", "react-native-file-viewer": "^1.0.5", - "react-native-firebase": "^5.1.1", "react-native-fs": "^2.11.17", "react-native-image-picker": "^0.26.7", "react-native-image-resizer": "^1.0.0", "react-native-material-dropdown": "^0.5.2", "react-native-popup-dialog": "^0.9.35", "react-native-popup-menu": "^0.10.0", + "react-native-push-notification": "^3.1.2", "react-native-securerandom": "^0.1.1", "react-native-share-extension": "^1.2.1", "react-native-side-menu": "^1.1.3",