1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-05 12:50:29 +02:00

Android: Fixes , Fixes , Fixes : Fixed and improved alarm notifications ()

This commit is contained in:
Roman Musin 2021-05-19 22:26:42 +01:00 committed by GitHub
parent eceb14ff9e
commit 9f37aa96c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 51 deletions

View File

@ -794,9 +794,9 @@ packages/app-mobile/services/AlarmServiceDriver.android.js.map
packages/app-mobile/services/AlarmServiceDriver.ios.d.ts
packages/app-mobile/services/AlarmServiceDriver.ios.js
packages/app-mobile/services/AlarmServiceDriver.ios.js.map
packages/app-mobile/setUpQuickActions.d.ts
packages/app-mobile/setUpQuickActions.js
packages/app-mobile/setUpQuickActions.js.map
packages/app-mobile/setupQuickActions.d.ts
packages/app-mobile/setupQuickActions.js
packages/app-mobile/setupQuickActions.js.map
packages/app-mobile/utils/ShareExtension.d.ts
packages/app-mobile/utils/ShareExtension.js
packages/app-mobile/utils/ShareExtension.js.map
@ -812,6 +812,9 @@ packages/app-mobile/utils/checkPermissions.js.map
packages/app-mobile/utils/fs-driver-rn.d.ts
packages/app-mobile/utils/fs-driver-rn.js
packages/app-mobile/utils/fs-driver-rn.js.map
packages/app-mobile/utils/setupNotifications.d.ts
packages/app-mobile/utils/setupNotifications.js
packages/app-mobile/utils/setupNotifications.js.map
packages/app-mobile/utils/shareHandler.d.ts
packages/app-mobile/utils/shareHandler.js
packages/app-mobile/utils/shareHandler.js.map

9
.gitignore vendored
View File

@ -780,9 +780,9 @@ packages/app-mobile/services/AlarmServiceDriver.android.js.map
packages/app-mobile/services/AlarmServiceDriver.ios.d.ts
packages/app-mobile/services/AlarmServiceDriver.ios.js
packages/app-mobile/services/AlarmServiceDriver.ios.js.map
packages/app-mobile/setUpQuickActions.d.ts
packages/app-mobile/setUpQuickActions.js
packages/app-mobile/setUpQuickActions.js.map
packages/app-mobile/setupQuickActions.d.ts
packages/app-mobile/setupQuickActions.js
packages/app-mobile/setupQuickActions.js.map
packages/app-mobile/utils/ShareExtension.d.ts
packages/app-mobile/utils/ShareExtension.js
packages/app-mobile/utils/ShareExtension.js.map
@ -798,6 +798,9 @@ packages/app-mobile/utils/checkPermissions.js.map
packages/app-mobile/utils/fs-driver-rn.d.ts
packages/app-mobile/utils/fs-driver-rn.js
packages/app-mobile/utils/fs-driver-rn.js.map
packages/app-mobile/utils/setupNotifications.d.ts
packages/app-mobile/utils/setupNotifications.js
packages/app-mobile/utils/setupNotifications.js.map
packages/app-mobile/utils/shareHandler.d.ts
packages/app-mobile/utils/shareHandler.js
packages/app-mobile/utils/shareHandler.js.map

View File

@ -8,12 +8,6 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- RN-NOTIFICATION -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- /RN-NOTIFICATION -->
<!-- Make these features optional to enable Chromebooks -->
<!-- https://github.com/laurent22/joplin/issues/37 -->
<uses-feature android:name="android.hardware.camera" android:required="false" />
@ -41,35 +35,6 @@
android:resizeableActivity="true"
android:theme="@style/AppTheme">
<!-- RN-NOTIFICATION -->
<receiver
android:name="com.emekalites.react.alarm.notification.AlarmReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="ACTION_DISMISS" />
<action android:name="ACTION_SNOOZE" />
</intent-filter>
</receiver>
<receiver
android:name="com.emekalites.react.alarm.notification.AlarmDismissReceiver"
android:enabled="true"
android:exported="true" />
<receiver
android:name="com.emekalites.react.alarm.notification.AlarmBootReceiver"
android:directBootAware="true"
android:enabled="false"
android:exported="true">
<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" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
</intent-filter>
</receiver>
<!-- /RN-NOTIFICATION -->
<!--
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.

View File

@ -23,6 +23,7 @@
"@react-native-community/slider": "^3.0.3",
"buffer": "^5.0.8",
"events": "^3.2.0",
"joplin-rn-alarm-notification": "^1.0.3",
"jsc-android": "241213.1.0",
"md5": "^2.2.1",
"prop-types": "^15.6.0",
@ -30,7 +31,6 @@
"react": "16.13.1",
"react-native": "0.63.3",
"react-native-action-button": "^2.8.5",
"react-native-alarm-notification": "^1.7.1",
"react-native-camera": "^3.40.0",
"react-native-dialogbox": "^0.6.10",
"react-native-document-picker": "^4.0.0",

View File

@ -2,7 +2,7 @@ const React = require('react');
import shim from '@joplin/lib/shim';
shim.setReact(React);
import setUpQuickActions from './setUpQuickActions';
import setupQuickActions from './setupQuickActions';
import PluginAssetsLoader from './PluginAssetsLoader';
import AlarmService from '@joplin/lib/services/AlarmService';
import Alarm from '@joplin/lib/models/Alarm';
@ -98,6 +98,7 @@ import MigrationService from '@joplin/lib/services/MigrationService';
import { clearSharedFilesCache } from './utils/ShareUtils';
import setIgnoreTlsErrors from './utils/TlsUtils';
import ShareService from '@joplin/lib/services/share/ShareService';
import setupNotifications from './utils/setupNotifications';
let storeDispatch = function(_action: any) {};
@ -715,7 +716,9 @@ class AppComponent extends React.Component {
await this.handleShareData();
setUpQuickActions(this.props.dispatch, this.props.selectedFolderId);
setupQuickActions(this.props.dispatch, this.props.selectedFolderId);
await setupNotifications(this.props.dispatch);
}
componentWillUnmount() {

View File

@ -1,7 +1,7 @@
import Logger from '@joplin/lib/Logger';
import { Notification } from '@joplin/lib/models/Alarm';
const ReactNativeAN = require('react-native-alarm-notification').default;
const ReactNativeAN = require('joplin-rn-alarm-notification').default;
export default class AlarmServiceDriver {
@ -30,9 +30,11 @@ export default class AlarmServiceDriver {
// Returns -1 if could not be found
private alarmJoplinAlarmId(alarm: any): number {
if (!alarm.data) return -1;
const m = alarm.data.match(/joplinNotificationId==>(\d+)/);
return m ? Number(m[1]) : -1;
if (!alarm.data || !alarm.data.joplinNotificationId) {
return -1;
} else {
return alarm.data.joplinNotificationId;
}
}
private async alarmByJoplinNotificationId(joplinNotificationId: number) {
@ -51,9 +53,12 @@ export default class AlarmServiceDriver {
title: notification.title,
message: notification.body ? notification.body : '-', // Required
channel: 'net.cozic.joplin.notification',
small_icon: 'ic_launcher',
color: 'white',
data: { joplinNotificationId: `${notification.id}` },
small_icon: 'ic_launcher_foreground', // Android requires the icon to be transparent
color: 'blue',
data: {
joplinNotificationId: `${notification.id}`,
noteId: notification.noteId,
},
};
// ReactNativeAN expects a string as a date and it seems this utility

View File

@ -0,0 +1,37 @@
import { Dispatch } from 'redux';
const { NativeEventEmitter, NativeModules, Platform } = require('react-native');
interface NotificationData {
joplinNotificationId: string;
noteId: string;
}
export default async (dispatch: Dispatch) => {
if (Platform.OS === 'android') {
const RNAlarmNotification = NativeModules.RNAlarmNotification;
const RNAlarmEmitter = new NativeEventEmitter(RNAlarmNotification);
const handleNotification = async (notification: NotificationData) => {
if (notification) {
const noteId = notification.noteId;
if (noteId) {
dispatch({ type: 'NAV_BACK' });
dispatch({ type: 'SIDE_MENU_CLOSE' });
dispatch({
type: 'NAV_GO',
noteId: noteId,
routeName: 'Note',
});
}
}
};
// receive notification click events when the app is running
RNAlarmEmitter.addListener('OnNotificationOpened', handleNotification);
// retrieve notification info if the app was started after the user clicked notification
const notification = await RNAlarmNotification.getAlarmInfo();
await handleNotification(notification);
}
};