From 1e6ce455c461c40888f8efb1631f08a6cf08a66a Mon Sep 17 00:00:00 2001 From: Muka Schultze Date: Wed, 7 Aug 2019 16:23:56 -0300 Subject: [PATCH 1/5] androidAutoClearNotification implemented --- README.md | 1 + src/background-http.android.ts | 9 +++++++++ src/index.d.ts | 17 +++++++++++------ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5d71309..4176894 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ androidDisplayNotificationProgress | `boolean` | (Android only) Used to set if p androidNotificationTitle | `string` | (Android only) Used to set the title shown in the Android notifications center. androidAutoDeleteAfterUpload | `boolean` | (Android only) Used to set if files should be deleted automatically after upload. androidMaxRetries | `number` | (Android only) Used to set the maximum retry count. The default retry count is 0. https://github.com/gotev/android-upload-service/wiki/Recipes#backoff +androidAutoClearNotification | `boolean` | (Android only) Used to set if notifications should be cleared automatically upon upload completion. Default is false. The task object has the following properties and methods, that can be used to get information about the upload: diff --git a/src/background-http.android.ts b/src/background-http.android.ts index 4729ac6..9f317ff 100644 --- a/src/background-http.android.ts +++ b/src/background-http.android.ts @@ -307,7 +307,16 @@ function setRequestOptions(request: any, options: common.Request) { if (displayNotificationProgress) { const uploadNotificationConfig = new net.gotev.uploadservice.UploadNotificationConfig(); const notificationTitle = typeof options.androidNotificationTitle === "string" ? options.androidNotificationTitle : 'File Upload'; + const autoClearNotifications = typeof options.androidAutoClearNotification === "boolean" ? options.androidAutoClearNotification : false; + uploadNotificationConfig.setTitleForAllStatuses(notificationTitle); + + if (autoClearNotifications) { + uploadNotificationConfig.getCompleted().autoClear = autoClearNotifications; + uploadNotificationConfig.getCancelled().autoClear = autoClearNotifications; + uploadNotificationConfig.getError().autoClear = autoClearNotifications; + } + request.setNotificationConfig(uploadNotificationConfig); } const autoDeleteAfterUpload = typeof options.androidAutoDeleteAfterUpload === "boolean" ? options.androidAutoDeleteAfterUpload : false; diff --git a/src/index.d.ts b/src/index.d.ts index 2240ab8..2a0fcd6 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -85,12 +85,12 @@ export interface Task { * Cancel the Upload Task. */ cancel(): void; - /** - * Subscribe for a general event. - * @param event The name of the event to subscribe for. - * @param handler The handler called when the event occure. - * @event - */ + /** + * Subscribe for a general event. + * @param event The name of the event to subscribe for. + * @param handler The handler called when the event occure. + * @event + */ on(event: string, handler: (e: observable.EventData) => void): void; /** @@ -194,4 +194,9 @@ export interface Request { * https://github.com/gotev/android-upload-service/wiki/Recipes#backoff */ androidMaxRetries?: number; + + /* + * Use this to set if notifications should be cleared automatically upon upload completion + */ + androidAutoClearNotification?: boolean; } From 5ff7d72beae303d8686cd1edd5d52c1f3a52b1ca Mon Sep 17 00:00:00 2001 From: Muka Schultze Date: Wed, 7 Aug 2019 16:46:29 -0300 Subject: [PATCH 2/5] androidRingToneEnabled implemented --- README.md | 1 + src/background-http.android.ts | 10 +++++----- src/index.d.ts | 5 +++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4176894..79e2e1f 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ androidNotificationTitle | `string` | (Android only) Used to set the title shown androidAutoDeleteAfterUpload | `boolean` | (Android only) Used to set if files should be deleted automatically after upload. androidMaxRetries | `number` | (Android only) Used to set the maximum retry count. The default retry count is 0. https://github.com/gotev/android-upload-service/wiki/Recipes#backoff androidAutoClearNotification | `boolean` | (Android only) Used to set if notifications should be cleared automatically upon upload completion. Default is false. +androidRingToneEnabled | `boolean` | (Android only) Used to set if a ringtone should be played upon upload completion. Default is true. The task object has the following properties and methods, that can be used to get information about the upload: diff --git a/src/background-http.android.ts b/src/background-http.android.ts index 9f317ff..fb14bb3 100644 --- a/src/background-http.android.ts +++ b/src/background-http.android.ts @@ -308,14 +308,14 @@ function setRequestOptions(request: any, options: common.Request) { const uploadNotificationConfig = new net.gotev.uploadservice.UploadNotificationConfig(); const notificationTitle = typeof options.androidNotificationTitle === "string" ? options.androidNotificationTitle : 'File Upload'; const autoClearNotifications = typeof options.androidAutoClearNotification === "boolean" ? options.androidAutoClearNotification : false; + const ringToneEnabled = typeof options.androidRingToneEnabled === "boolean" ? options.androidRingToneEnabled : true; uploadNotificationConfig.setTitleForAllStatuses(notificationTitle); + uploadNotificationConfig.setRingToneEnabled(new java.lang.Boolean(ringToneEnabled)); - if (autoClearNotifications) { - uploadNotificationConfig.getCompleted().autoClear = autoClearNotifications; - uploadNotificationConfig.getCancelled().autoClear = autoClearNotifications; - uploadNotificationConfig.getError().autoClear = autoClearNotifications; - } + uploadNotificationConfig.getCompleted().autoClear = autoClearNotifications; + uploadNotificationConfig.getCancelled().autoClear = autoClearNotifications; + uploadNotificationConfig.getError().autoClear = autoClearNotifications; request.setNotificationConfig(uploadNotificationConfig); } diff --git a/src/index.d.ts b/src/index.d.ts index 2a0fcd6..a9c8491 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -199,4 +199,9 @@ export interface Request { * Use this to set if notifications should be cleared automatically upon upload completion */ androidAutoClearNotification?: boolean; + + /* + * Use this to set if a ringtone should be played upon upload completion + */ + androidRingToneEnabled?: boolean; } From 38037daa9030c88b9ffcb12f9c5ba9996b459c40 Mon Sep 17 00:00:00 2001 From: Muka Schultze Date: Wed, 7 Aug 2019 17:19:33 -0300 Subject: [PATCH 3/5] androidNotificationChannelID implemented --- README.md | 1 + src/background-http.android.ts | 5 +++++ src/index.d.ts | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 79e2e1f..6e58b8c 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ androidAutoDeleteAfterUpload | `boolean` | (Android only) Used to set if files s androidMaxRetries | `number` | (Android only) Used to set the maximum retry count. The default retry count is 0. https://github.com/gotev/android-upload-service/wiki/Recipes#backoff androidAutoClearNotification | `boolean` | (Android only) Used to set if notifications should be cleared automatically upon upload completion. Default is false. androidRingToneEnabled | `boolean` | (Android only) Used to set if a ringtone should be played upon upload completion. Default is true. +androidNotificationChannelID | `string` | (Android only) Used to set the channel ID for the notifications. The task object has the following properties and methods, that can be used to get information about the upload: diff --git a/src/background-http.android.ts b/src/background-http.android.ts index fb14bb3..b360684 100644 --- a/src/background-http.android.ts +++ b/src/background-http.android.ts @@ -309,10 +309,15 @@ function setRequestOptions(request: any, options: common.Request) { const notificationTitle = typeof options.androidNotificationTitle === "string" ? options.androidNotificationTitle : 'File Upload'; const autoClearNotifications = typeof options.androidAutoClearNotification === "boolean" ? options.androidAutoClearNotification : false; const ringToneEnabled = typeof options.androidRingToneEnabled === "boolean" ? options.androidRingToneEnabled : true; + const channelID = typeof options.androidNotificationChannelID === "string" ? options.androidNotificationChannelID : undefined; uploadNotificationConfig.setTitleForAllStatuses(notificationTitle); uploadNotificationConfig.setRingToneEnabled(new java.lang.Boolean(ringToneEnabled)); + if (channelID) { + uploadNotificationConfig.setNotificationChannelId(channelID); + } + uploadNotificationConfig.getCompleted().autoClear = autoClearNotifications; uploadNotificationConfig.getCancelled().autoClear = autoClearNotifications; uploadNotificationConfig.getError().autoClear = autoClearNotifications; diff --git a/src/index.d.ts b/src/index.d.ts index a9c8491..9e66108 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -204,4 +204,9 @@ export interface Request { * Use this to set if a ringtone should be played upon upload completion */ androidRingToneEnabled?: boolean; + + /* + * Use this to set the channel ID for the notifications + */ + androidNotificationChannelID?: string; } From af49af3ab35964ec1ed7d3862351b11c01669d57 Mon Sep 17 00:00:00 2001 From: Muka Schultze Date: Thu, 8 Aug 2019 12:18:44 -0300 Subject: [PATCH 4/5] better way of using default values --- src/background-http.android.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/background-http.android.ts b/src/background-http.android.ts index b360684..3aae97c 100644 --- a/src/background-http.android.ts +++ b/src/background-http.android.ts @@ -307,20 +307,22 @@ function setRequestOptions(request: any, options: common.Request) { if (displayNotificationProgress) { const uploadNotificationConfig = new net.gotev.uploadservice.UploadNotificationConfig(); const notificationTitle = typeof options.androidNotificationTitle === "string" ? options.androidNotificationTitle : 'File Upload'; - const autoClearNotifications = typeof options.androidAutoClearNotification === "boolean" ? options.androidAutoClearNotification : false; - const ringToneEnabled = typeof options.androidRingToneEnabled === "boolean" ? options.androidRingToneEnabled : true; - const channelID = typeof options.androidNotificationChannelID === "string" ? options.androidNotificationChannelID : undefined; uploadNotificationConfig.setTitleForAllStatuses(notificationTitle); - uploadNotificationConfig.setRingToneEnabled(new java.lang.Boolean(ringToneEnabled)); - if (channelID) { - uploadNotificationConfig.setNotificationChannelId(channelID); + if (typeof options.androidRingToneEnabled === "boolean") { + uploadNotificationConfig.setRingToneEnabled(new java.lang.Boolean(options.androidRingToneEnabled)); } - uploadNotificationConfig.getCompleted().autoClear = autoClearNotifications; - uploadNotificationConfig.getCancelled().autoClear = autoClearNotifications; - uploadNotificationConfig.getError().autoClear = autoClearNotifications; + if (typeof options.androidAutoClearNotification === "boolean") { + uploadNotificationConfig.getCompleted().autoClear = options.androidAutoClearNotification; + uploadNotificationConfig.getCancelled().autoClear = options.androidAutoClearNotification; + uploadNotificationConfig.getError().autoClear = options.androidAutoClearNotification; + } + + if (typeof options.androidNotificationChannelID === "string" && options.androidNotificationChannelID) { + uploadNotificationConfig.setNotificationChannelId(options.androidNotificationChannelID); + } request.setNotificationConfig(uploadNotificationConfig); } From ce1c5c40cefc6f09dbf7755c1f74069d29fd656f Mon Sep 17 00:00:00 2001 From: Muka Schultze Date: Wed, 21 Aug 2019 13:10:01 -0300 Subject: [PATCH 5/5] add android notes on readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6e58b8c..d37ef35 100644 --- a/README.md +++ b/README.md @@ -76,8 +76,8 @@ androidDisplayNotificationProgress | `boolean` | (Android only) Used to set if p androidNotificationTitle | `string` | (Android only) Used to set the title shown in the Android notifications center. androidAutoDeleteAfterUpload | `boolean` | (Android only) Used to set if files should be deleted automatically after upload. androidMaxRetries | `number` | (Android only) Used to set the maximum retry count. The default retry count is 0. https://github.com/gotev/android-upload-service/wiki/Recipes#backoff -androidAutoClearNotification | `boolean` | (Android only) Used to set if notifications should be cleared automatically upon upload completion. Default is false. -androidRingToneEnabled | `boolean` | (Android only) Used to set if a ringtone should be played upon upload completion. Default is true. +androidAutoClearNotification | `boolean` | (Android only) Used to set if notifications should be cleared automatically upon upload completion. Default is false. Please note that setting this to true will also disable the ringtones. +androidRingToneEnabled | `boolean` | (Android only) Used to set if a ringtone should be played upon upload completion. Default is true. Please note that this flag has no effect when `androidAutoClearNotification` is set to true. androidNotificationChannelID | `string` | (Android only) Used to set the channel ID for the notifications. The task object has the following properties and methods, that can be used to get information about the upload: