Skip to content

Commit cbc41c0

Browse files
author
thomasvo
committed
minimum progress
1 parent 488717f commit cbc41c0

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

android/src/main/java/com/vydia/RNUploader/Notification.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ object UploadNotification {
5858

5959
// builds the notification required to enable Foreground mode
6060
fun build(context: Context): Notification {
61-
// since all workers share the same notification ID,
62-
// get the active upload so we don't overwrite the notification when multiple uploads are running
63-
val wifiOnly = getActiveUpload()?.wifiOnly ?: false
61+
// Determine wifiOnly preference for connectivity check:
62+
// - If an upload is actively running, use its preference
63+
// - Otherwise, check the queue: if ANY upload can proceed with just mobile data (wifiOnly=false),
64+
// we only need internet to make progress. If ALL uploads need WiFi, we need WiFi.
65+
// This ensures the notification ("Waiting for internet" vs "Waiting for WiFi") reflects
66+
// the minimum connectivity required to make progress.
67+
val wifiOnly = getActiveUpload()?.wifiOnly ?: !UploadProgress.hasNonWifiOnlyUploads()
6468
val channel = channel
6569
val progress = UploadProgress.total()
6670
val progress2Decimals = "%.2f".format(progress)

android/src/main/java/com/vydia/RNUploader/UploadProgress.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ object UploadProgress {
88
private data class Progress(
99
var bytesUploaded: Long,
1010
val size: Long,
11+
val wifiOnly: Boolean,
1112
var complete: Boolean = false
1213
) {
1314
fun complete() {
@@ -19,8 +20,8 @@ object UploadProgress {
1920
private val map = mutableMapOf<String, Progress>()
2021

2122
@Synchronized
22-
fun add(id: String, size: Long) {
23-
map[id] = Progress(bytesUploaded = 0L, size = size)
23+
fun add(id: String, size: Long, wifiOnly: Boolean) {
24+
map[id] = Progress(bytesUploaded = 0L, size = size, wifiOnly = wifiOnly)
2425
}
2526

2627
@Synchronized
@@ -55,4 +56,16 @@ object UploadProgress {
5556
private fun clearIfCompleted() {
5657
if (map.values.all { it.complete }) map.clear()
5758
}
59+
60+
/**
61+
* Returns true if any incomplete upload can proceed without WiFi (wifiOnly=false).
62+
* Used to determine notification text when no upload is actively running:
63+
* - If true: at least one upload only needs mobile data, so show "Waiting for internet"
64+
* - If false: all uploads need WiFi, so show "Waiting for WiFi"
65+
* This ensures the notification reflects the minimum connectivity needed to make progress.
66+
*/
67+
@Synchronized
68+
fun hasNonWifiOnlyUploads(): Boolean {
69+
return map.values.any { !it.complete && !it.wifiOnly }
70+
}
5871
}

0 commit comments

Comments
 (0)