diff --git a/ReactNativeClient/android/app/build.gradle b/ReactNativeClient/android/app/build.gradle index abebc1b2f6..36bd9ec8e7 100644 --- a/ReactNativeClient/android/app/build.gradle +++ b/ReactNativeClient/android/app/build.gradle @@ -137,24 +137,39 @@ android { } dependencies { - compile project(':react-native-camera') - compile project(':react-native-file-viewer') - compile project(':react-native-securerandom') - compile project(':react-native-push-notification') - compile project(':react-native-fs') - compile project(':react-native-image-picker') - compile project(':react-native-vector-icons') - compile project(':react-native-fs') + implementation project(':react-native-firebase') + 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 + // this error message: + // + // The library com.google.android.gms:play-services-base is being requested by various other libraries at [[15.0.1,15.0.1]], but resolves to 16.0.1 + // + // For the record: found solution by removing all Firebase stuff here and running "gradlew.bat :app:dependencies" + // That shows that react-native-camera was the one requiring v15.0.1. + exclude group: "com.google.android.gms" + } + implementation project(':react-native-file-viewer') + implementation project(':react-native-securerandom') + implementation project(':react-native-fs') + implementation project(':react-native-image-picker') + implementation project(':react-native-vector-icons') + implementation project(':react-native-fs') implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" implementation "com.facebook.react:react-native:+" // From node_modules - compile project(':react-native-sqlite-storage') - compile project(':rn-fetch-blob') - compile project(':react-native-document-picker') - compile project(':react-native-image-resizer') - compile project(':react-native-share-extension') - compile project(':react-native-version-info') - compile "com.facebook.react:react-native:+" + implementation project(':react-native-sqlite-storage') + implementation project(':rn-fetch-blob') + implementation project(':react-native-document-picker') + implementation project(':react-native-image-resizer') + implementation project(':react-native-share-extension') + implementation project(':react-native-version-info') + 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. // Doesn't make any sense since rn-camera neither defines v26 nor 27 but @@ -183,3 +198,4 @@ task copyDownloadableDepsToLibs(type: Copy) { } 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 diff --git a/ReactNativeClient/android/app/google-services.json b/ReactNativeClient/android/app/google-services.json new file mode 100644 index 0000000000..73f25d388f --- /dev/null +++ b/ReactNativeClient/android/app/google-services.json @@ -0,0 +1,42 @@ +{ + "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 25dcf5d971..582c2ee8b0 100644 --- a/ReactNativeClient/android/app/src/main/AndroidManifest.xml +++ b/ReactNativeClient/android/app/src/main/AndroidManifest.xml @@ -11,25 +11,23 @@ + + + + + + + + + + + + - - - - - - - - - - - - @@ -41,27 +39,62 @@ android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme"> - - - - - + + + + + + + + - + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:launchMode="singleTop"> 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 09f49ca70b..c7128fd911 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,10 +3,12 @@ package net.cozic.joplin; 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 org.reactnative.camera.RNCameraPackage; import com.vinzscam.reactnativefileviewer.RNFileViewerPackage; import net.rhogan.rnsecurerandom.RNSecureRandomPackage; -import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage; import com.imagepicker.ImagePickerPackage; import com.facebook.react.ReactInstanceManager; import com.facebook.react.ReactNativeHost; @@ -38,12 +40,14 @@ public class MainApplication extends Application implements ReactApplication { @Override protected List getPackages() { return Arrays.asList( - new ImageResizerPackage(), new MainReactPackage(), - new RNCameraPackage(), - new RNFileViewerPackage(), - new RNSecureRandomPackage(), - new ReactNativePushNotificationPackage(), + new ImageResizerPackage(), + new RNFirebasePackage(), + new RNFirebaseMessagingPackage(), + new RNFirebaseNotificationsPackage(), + new RNCameraPackage(), + new RNFileViewerPackage(), + new RNSecureRandomPackage(), new ImagePickerPackage(), new ReactNativeDocumentPicker(), new RNFetchBlobPackage(), diff --git a/ReactNativeClient/android/app/src/main/res/drawable-hdpi/ic_stat_access_alarm.png b/ReactNativeClient/android/app/src/main/res/drawable-hdpi/ic_stat_access_alarm.png new file mode 100644 index 0000000000..57a61a1b02 Binary files /dev/null and b/ReactNativeClient/android/app/src/main/res/drawable-hdpi/ic_stat_access_alarm.png differ diff --git a/ReactNativeClient/android/app/src/main/res/drawable-mdpi/ic_stat_access_alarm.png b/ReactNativeClient/android/app/src/main/res/drawable-mdpi/ic_stat_access_alarm.png new file mode 100644 index 0000000000..02d3ed6953 Binary files /dev/null and b/ReactNativeClient/android/app/src/main/res/drawable-mdpi/ic_stat_access_alarm.png differ diff --git a/ReactNativeClient/android/app/src/main/res/drawable-xhdpi/ic_stat_access_alarm.png b/ReactNativeClient/android/app/src/main/res/drawable-xhdpi/ic_stat_access_alarm.png new file mode 100644 index 0000000000..3c7d102c41 Binary files /dev/null and b/ReactNativeClient/android/app/src/main/res/drawable-xhdpi/ic_stat_access_alarm.png differ diff --git a/ReactNativeClient/android/app/src/main/res/drawable-xxhdpi/ic_stat_access_alarm.png b/ReactNativeClient/android/app/src/main/res/drawable-xxhdpi/ic_stat_access_alarm.png new file mode 100644 index 0000000000..dab64b5058 Binary files /dev/null and b/ReactNativeClient/android/app/src/main/res/drawable-xxhdpi/ic_stat_access_alarm.png differ diff --git a/ReactNativeClient/android/app/src/main/res/drawable-xxxhdpi/ic_stat_access_alarm.png b/ReactNativeClient/android/app/src/main/res/drawable-xxxhdpi/ic_stat_access_alarm.png new file mode 100644 index 0000000000..1ab6de39dc Binary files /dev/null and b/ReactNativeClient/android/app/src/main/res/drawable-xxxhdpi/ic_stat_access_alarm.png differ diff --git a/ReactNativeClient/android/build.gradle b/ReactNativeClient/android/build.gradle index affc32dc34..5065c72483 100644 --- a/ReactNativeClient/android/build.gradle +++ b/ReactNativeClient/android/build.gradle @@ -13,7 +13,8 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.4' + 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 @@ -23,6 +24,8 @@ buildscript { allprojects { repositories { mavenLocal() + google() + jcenter() // Was added by me - still needed? maven { url "https://maven.google.com" } @@ -30,8 +33,6 @@ allprojects { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } - jcenter() // Was added by me - still needed? - google() } } diff --git a/ReactNativeClient/android/gradle/wrapper/gradle-wrapper.properties b/ReactNativeClient/android/gradle/wrapper/gradle-wrapper.properties index b6517bb1d1..3f0f9be633 100644 --- a/ReactNativeClient/android/gradle/wrapper/gradle-wrapper.properties +++ b/ReactNativeClient/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip diff --git a/ReactNativeClient/android/settings.gradle b/ReactNativeClient/android/settings.gradle index f547592a13..a9dd90dd6a 100644 --- a/ReactNativeClient/android/settings.gradle +++ b/ReactNativeClient/android/settings.gradle @@ -1,12 +1,12 @@ 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' project(':react-native-file-viewer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-file-viewer/android') include ':react-native-securerandom' project(':react-native-securerandom').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-securerandom/android') -include ':react-native-push-notification' -project(':react-native-push-notification').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-push-notification/android') include ':react-native-fs' project(':react-native-fs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fs/android') include ':react-native-image-picker' diff --git a/ReactNativeClient/lib/services/AlarmServiceDriver.android.js b/ReactNativeClient/lib/services/AlarmServiceDriver.android.js index dce6c34a87..3de7ce257e 100644 --- a/ReactNativeClient/lib/services/AlarmServiceDriver.android.js +++ b/ReactNativeClient/lib/services/AlarmServiceDriver.android.js @@ -1,4 +1,4 @@ -const PushNotification = require('react-native-push-notification'); +import firebase from 'react-native-firebase'; class AlarmServiceDriver { @@ -10,25 +10,25 @@ class AlarmServiceDriver { throw new Error('Available only for non-persistent alarms'); } + firebaseNotificationId_(joplinNotificationId) { + return 'net.cozic.joplin-' + joplinNotificationId; + } + async clearNotification(id) { - PushNotification.cancelLocalNotifications({ id: id + '' }); + return firebase.notifications().cancelNotification(this.firebaseNotificationId_(id)) } async scheduleNotification(notification) { - // Arguments must be set in a certain way and certain format otherwise it cannot be - // cancelled later on. See: - // https://github.com/zo0r/react-native-push-notification/issues/570#issuecomment-337642922 - const androidNotification = { - id: notification.id + '', - message: notification.title, - date: notification.date, - userInfo: { id: notification.id + '' }, - number: 0, - }; + 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('com.google.firebase.messaging.default_notification_channel_id'); + firebaseNotification.android.setSmallIcon('ic_stat_access_alarm'); - if ('body' in notification) androidNotification.body = notification.body; - - PushNotification.localNotificationSchedule(androidNotification); + firebase.notifications().scheduleNotification(firebaseNotification, { + fireDate: notification.date.getTime(), + }); } } diff --git a/ReactNativeClient/package-lock.json b/ReactNativeClient/package-lock.json index 312bbe97f3..0dfbd9133b 100644 --- a/ReactNativeClient/package-lock.json +++ b/ReactNativeClient/package-lock.json @@ -5822,6 +5822,11 @@ "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": "http://registry.npmjs.org/opn/-/opn-3.0.3.tgz", @@ -6630,6 +6635,26 @@ "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", @@ -6699,11 +6724,6 @@ "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.0.1", - "resolved": "https://registry.npmjs.org/react-native-push-notification/-/react-native-push-notification-3.0.1.tgz", - "integrity": "sha1-DiPbMC0Du0o/KNwHLcryqaEXjtg=" - }, "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 28579a756f..8378807a5c 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.0.1", "react-native-securerandom": "^0.1.1", "react-native-share-extension": "^1.2.1", "react-native-side-menu": "^1.1.3", diff --git a/ReactNativeClient/root.js b/ReactNativeClient/root.js index d0ef3ee377..809141312b 100644 --- a/ReactNativeClient/root.js +++ b/ReactNativeClient/root.js @@ -65,8 +65,6 @@ SyncTargetRegistry.addClass(SyncTargetOneDriveDev); SyncTargetRegistry.addClass(SyncTargetNextcloud); SyncTargetRegistry.addClass(SyncTargetWebDAV); SyncTargetRegistry.addClass(SyncTargetDropbox); - -// Disabled because not fully working SyncTargetRegistry.addClass(SyncTargetFilesystem); const FsDriverRN = require('lib/fs-driver-rn.js').FsDriverRN;