@kesha-antonov/react-native-background-downloader 4.5.9 → 4.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -4
- package/android/build.gradle +17 -0
- package/android/src/main/AndroidManifest.xml +24 -0
- package/android/src/main/java/com/eko/DownloadConstants.kt +14 -2
- package/android/src/main/java/com/eko/Downloader.kt +77 -12
- package/android/src/main/java/com/eko/RNBackgroundDownloaderModuleImpl.kt +81 -11
- package/android/src/main/java/com/eko/ResumableDownloadService.kt +0 -4
- package/android/src/main/java/com/eko/ResumableDownloader.kt +121 -12
- package/android/src/main/java/com/eko/UIDTDownloadJobService.kt +65 -9
- package/android/src/main/java/com/eko/uidt/CancelDownloadReceiver.kt +64 -0
- package/android/src/main/java/com/eko/uidt/RNBGDFileProvider.kt +17 -0
- package/android/src/main/java/com/eko/uidt/UIDTJobIds.kt +112 -0
- package/android/src/main/java/com/eko/uidt/UIDTJobManager.kt +178 -17
- package/android/src/main/java/com/eko/uidt/UIDTJobState.kt +23 -1
- package/android/src/main/java/com/eko/uidt/UIDTNotificationIds.kt +73 -0
- package/android/src/main/java/com/eko/uidt/UIDTNotificationManager.kt +246 -19
- package/android/src/main/res/xml/rnbgd_file_paths.xml +23 -0
- package/android/src/test/java/com/eko/ResumableDownloaderConcurrencyTest.kt +199 -0
- package/android/src/test/java/com/eko/uidt/UIDTJobIdsTest.kt +159 -0
- package/android/src/test/java/com/eko/uidt/UIDTJobManagerTest.kt +192 -0
- package/android/src/test/java/com/eko/uidt/UIDTNotificationIdsTest.kt +99 -0
- package/lib/NativeRNBackgroundDownloader.d.ts +2 -0
- package/lib/config.d.ts +2 -0
- package/lib/config.js +3 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +9 -2
- package/lib/notifications.js +4 -3
- package/lib/types.d.ts +19 -0
- package/package.json +3 -2
- package/react-native-background-downloader.podspec +14 -1
- package/src/NativeRNBackgroundDownloader.ts +8 -1
- package/src/config.ts +5 -0
- package/src/index.ts +19 -1
- package/src/notifications.ts +1 -0
- package/src/types.ts +19 -0
package/src/config.ts
CHANGED
|
@@ -19,6 +19,7 @@ export const DEFAULT_NOTIFICATION_TEXTS: Required<NotificationTexts> = {
|
|
|
19
19
|
downloadProgress: 'Downloading... {progress}%',
|
|
20
20
|
downloadPaused: 'Paused',
|
|
21
21
|
downloadFinished: 'Download complete',
|
|
22
|
+
downloadCancel: 'Cancel',
|
|
22
23
|
groupTitle: 'Downloads',
|
|
23
24
|
groupText: (count: number) => `${count} download${count !== 1 ? 's' : ''} in progress`,
|
|
24
25
|
}
|
|
@@ -32,6 +33,8 @@ interface ConfigState {
|
|
|
32
33
|
maxParallelDownloads: number
|
|
33
34
|
allowsCellularAccess: boolean
|
|
34
35
|
showNotificationsEnabled: boolean
|
|
36
|
+
showCompletionNotification: boolean
|
|
37
|
+
showCancelAction: boolean
|
|
35
38
|
notificationsGrouping: NotificationsGroupingConfig & { mode: NotificationGroupingMode }
|
|
36
39
|
iosDataProtection: IosDataProtection
|
|
37
40
|
}
|
|
@@ -45,6 +48,8 @@ export const config: ConfigState = {
|
|
|
45
48
|
maxParallelDownloads: DEFAULT_MAX_PARALLEL_DOWNLOADS,
|
|
46
49
|
allowsCellularAccess: DEFAULT_ALLOWS_CELLULAR_ACCESS,
|
|
47
50
|
showNotificationsEnabled: false,
|
|
51
|
+
showCompletionNotification: false,
|
|
52
|
+
showCancelAction: false,
|
|
48
53
|
iosDataProtection: DEFAULT_IOS_DATA_PROTECTION,
|
|
49
54
|
notificationsGrouping: {
|
|
50
55
|
enabled: false,
|
package/src/index.ts
CHANGED
|
@@ -373,6 +373,8 @@ export function setConfig ({
|
|
|
373
373
|
maxParallelDownloads,
|
|
374
374
|
allowsCellularAccess,
|
|
375
375
|
showNotificationsEnabled,
|
|
376
|
+
showCompletionNotification,
|
|
377
|
+
showCancelAction,
|
|
376
378
|
notificationsGrouping,
|
|
377
379
|
iosDataProtection,
|
|
378
380
|
}: Config) {
|
|
@@ -404,6 +406,13 @@ export function setConfig ({
|
|
|
404
406
|
if (showNotificationsEnabled !== undefined)
|
|
405
407
|
config.showNotificationsEnabled = showNotificationsEnabled
|
|
406
408
|
|
|
409
|
+
// Android 14+ notification extras - both opt-in
|
|
410
|
+
if (showCompletionNotification !== undefined)
|
|
411
|
+
config.showCompletionNotification = showCompletionNotification
|
|
412
|
+
|
|
413
|
+
if (showCancelAction !== undefined)
|
|
414
|
+
config.showCancelAction = showCancelAction
|
|
415
|
+
|
|
407
416
|
// Update notification grouping config
|
|
408
417
|
if (notificationsGrouping !== undefined)
|
|
409
418
|
config.notificationsGrouping = {
|
|
@@ -424,7 +433,14 @@ export function setConfig ({
|
|
|
424
433
|
setLogsEnabled?: (enabled: boolean) => void
|
|
425
434
|
setMaxParallelDownloads?: (max: number) => void
|
|
426
435
|
setAllowsCellularAccess?: (allows: boolean) => void
|
|
427
|
-
setNotificationGroupingConfig?: (config: {
|
|
436
|
+
setNotificationGroupingConfig?: (config: {
|
|
437
|
+
enabled: boolean
|
|
438
|
+
showNotificationsEnabled: boolean
|
|
439
|
+
showCompletionNotification: boolean
|
|
440
|
+
showCancelAction: boolean
|
|
441
|
+
mode: string
|
|
442
|
+
texts: Record<string, string>
|
|
443
|
+
}) => void
|
|
428
444
|
}
|
|
429
445
|
if (nativeModule.setLogsEnabled)
|
|
430
446
|
nativeModule.setLogsEnabled(isLogsEnabled)
|
|
@@ -438,6 +454,8 @@ export function setConfig ({
|
|
|
438
454
|
nativeModule.setNotificationGroupingConfig({
|
|
439
455
|
enabled: config.notificationsGrouping.enabled,
|
|
440
456
|
showNotificationsEnabled: config.showNotificationsEnabled ?? false,
|
|
457
|
+
showCompletionNotification: config.showCompletionNotification ?? false,
|
|
458
|
+
showCancelAction: config.showCancelAction ?? false,
|
|
441
459
|
mode: config.notificationsGrouping.mode,
|
|
442
460
|
texts: getNotificationTextsForNative(),
|
|
443
461
|
})
|
package/src/notifications.ts
CHANGED
|
@@ -22,6 +22,7 @@ export function getNotificationTextsForNative (): Record<string, string> {
|
|
|
22
22
|
downloadProgress: texts.downloadProgress ?? DEFAULT_NOTIFICATION_TEXTS.downloadProgress,
|
|
23
23
|
downloadPaused: texts.downloadPaused ?? DEFAULT_NOTIFICATION_TEXTS.downloadPaused,
|
|
24
24
|
downloadFinished: texts.downloadFinished ?? DEFAULT_NOTIFICATION_TEXTS.downloadFinished,
|
|
25
|
+
downloadCancel: texts.downloadCancel ?? DEFAULT_NOTIFICATION_TEXTS.downloadCancel,
|
|
25
26
|
groupTitle: texts.groupTitle ?? DEFAULT_NOTIFICATION_TEXTS.groupTitle,
|
|
26
27
|
// For native side, we send a pattern with {count} placeholder
|
|
27
28
|
groupText: typeof texts.groupText === 'function'
|
package/src/types.ts
CHANGED
|
@@ -21,6 +21,9 @@ export interface NotificationTexts {
|
|
|
21
21
|
downloadPaused?: string
|
|
22
22
|
/** Text shown when download is finished (default: "Download complete") */
|
|
23
23
|
downloadFinished?: string
|
|
24
|
+
/** Label of the Cancel action on the progress notification (default: "Cancel").
|
|
25
|
+
* Android 14+ only, and only when `showCancelAction` is enabled */
|
|
26
|
+
downloadCancel?: string
|
|
24
27
|
/** Title for group summary notification (default: "Downloads") */
|
|
25
28
|
groupTitle?: string
|
|
26
29
|
/** Text pattern for group summary. Use {count} for number of downloads.
|
|
@@ -74,6 +77,19 @@ export interface Config {
|
|
|
74
77
|
allowsCellularAccess?: boolean
|
|
75
78
|
/** Show download notifications (Android only, default: false). When false, creates minimal silent notifications (UIDT requires a notification) */
|
|
76
79
|
showNotificationsEnabled?: boolean
|
|
80
|
+
/**
|
|
81
|
+
* Post a "download complete" notification when a download finishes
|
|
82
|
+
* (Android 14+ only, default: false). Tapping it opens the saved file.
|
|
83
|
+
* Requires `showNotificationsEnabled`; ignored in `summaryOnly` grouping mode.
|
|
84
|
+
*/
|
|
85
|
+
showCompletionNotification?: boolean
|
|
86
|
+
/**
|
|
87
|
+
* Add a Cancel button to the download notification (Android 14+ only, default: false).
|
|
88
|
+
* Tapping it stops the download and fires the task's `.error()` handler with
|
|
89
|
+
* `errorCode = -1`, so only enable it if your app handles that.
|
|
90
|
+
* Requires `showNotificationsEnabled`.
|
|
91
|
+
*/
|
|
92
|
+
showCancelAction?: boolean
|
|
77
93
|
/** Configuration for notifications grouping on Android */
|
|
78
94
|
notificationsGrouping?: NotificationsGroupingConfig
|
|
79
95
|
/**
|
|
@@ -151,6 +167,9 @@ export type DownloadParams = {
|
|
|
151
167
|
groupId?: string
|
|
152
168
|
/** Group name displayed in notification (only used when grouping is enabled) */
|
|
153
169
|
groupName?: string
|
|
170
|
+
/** Notification title for this download, overriding `groupName` and the
|
|
171
|
+
* configured `downloadTitle` text (Android 14+ only) */
|
|
172
|
+
notificationTitle?: string
|
|
154
173
|
/**
|
|
155
174
|
* iOS Data Protection level for this download's file (iOS only).
|
|
156
175
|
* Overrides the global `iosDataProtection` from setConfig.
|