Skip to content

Commit

Permalink
Android: Fixes #321: Removed dependency to Firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Jan 10, 2019
1 parent 09b4acf commit a8cc876
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 163 deletions.
7 changes: 2 additions & 5 deletions ReactNativeClient/android/app/build.gradle
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
42 changes: 0 additions & 42 deletions ReactNativeClient/android/app/google-services.json

This file was deleted.

87 changes: 36 additions & 51 deletions ReactNativeClient/android/app/src/main/AndroidManifest.xml
Expand Up @@ -11,18 +11,18 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove"/>


<!-- ============================= -->
<!-- START RNFirebaseNotifications -->
<!-- START RN-push-notitication -->
<!-- ============================= -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!-- ============================= -->
<!-- END RNFirebaseNotifications -->
<!-- END RN-push-notitication -->
<!-- ============================= -->



<!-- Make these features optional to enable Chromebooks -->
<!-- https://github.com/laurent22/joplin/issues/37 -->
<uses-feature android:name="android.hardware.camera" android:required="false" />
Expand All @@ -39,56 +39,41 @@
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">



<!-- ============================= -->
<!-- START RNFirebaseNotifications -->
<!-- START RN-push-notitication -->
<!-- ============================= -->

<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_stat_access_alarm" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
<receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver"/>
<receiver android:enabled="true" android:exported="true" android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name" android:value="@string/default_notification_channel_id"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description" android:value="Allow displaying a notification for Joplin's alarms"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color" android:resource="@android:color/white"/>

<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<!-- ============================= -->
<!-- END RNFirebaseNotifications -->
<!-- ============================= -->



<!-- ============================= -->
<!-- START RNFirebaseNotifications -->
<!-- ============================= -->
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>

<!-- "If you want to be able to react to data-only messages when your app is in the background, e.g. to display a heads up notification" -->
<service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>

<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<!-- ============================= -->
<!-- END RNFirebaseNotifications -->
<!-- END RN-push-notitication -->
<!-- ============================= -->





<!-- 2018-12-16: Changed android:launchMode from "singleInstance" to "singleTop" for Firebase notification -->
<!-- Previously singleInstance was necessary to prevent multiple instance of the RN app from running at the same time, but maybe no longer needed. -->
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -41,10 +39,8 @@ public boolean getUseDeveloperSupport() {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactNativePushNotificationPackage(),
new ImageResizerPackage(),
new RNFirebasePackage(),
new RNFirebaseMessagingPackage(),
new RNFirebaseNotificationsPackage(),
new RNCameraPackage(),
new RNFileViewerPackage(),
new RNSecureRandomPackage(),
Expand Down
3 changes: 3 additions & 0 deletions ReactNativeClient/android/app/src/main/res/values/colors.xml
@@ -0,0 +1,3 @@
<resources>
<color name="white">#FFF</color>
</resources>
1 change: 0 additions & 1 deletion ReactNativeClient/android/build.gradle
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions 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'
Expand Down Expand Up @@ -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')
55 changes: 25 additions & 30 deletions 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() {
Expand All @@ -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);
}

}
Expand Down
30 changes: 5 additions & 25 deletions ReactNativeClient/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ReactNativeClient/package.json
Expand Up @@ -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",
Expand Down

0 comments on commit a8cc876

Please sign in to comment.