mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 23:21:59 +01:00
post our own download progress notification
The platform posts one notification per download, so queueing an album buries the UI in them and they can be swiped away. Hiding them (VISIBILITY_HIDDEN, which needs DOWNLOAD_WITHOUT_NOTIFICATION) and posting one aggregated notification instead gives a single ongoing entry with the overall progress and a Cancel action that stops everything in flight. It is refreshed from the download state the poller already maintains, so it tracks the engine without extra queries, and it is tied to this process: if we are killed the downloads continue with no notification, which is the trade for not writing a service.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package com.subtracks.data.download
|
||||
|
||||
import com.subtracks.data.model.DownloadStatus
|
||||
import com.subtracks.data.model.SongDownload
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class DownloadNotificationTest {
|
||||
@Test
|
||||
fun nothingInFlightMeansNoNotification() {
|
||||
assertNull(downloadNotification(emptyList()))
|
||||
assertNull(downloadNotification(listOf(row("s1", DownloadStatus.Completed), row("s2", DownloadStatus.Failed))))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun oneRunningDownloadReportsItsShare() {
|
||||
val notification = downloadNotification(listOf(row("s1", DownloadStatus.Running, bytes = 50, total = 100)))
|
||||
|
||||
assertEquals("Downloading 1 song", notification?.title)
|
||||
assertEquals("50%", notification?.text)
|
||||
assertEquals(0.5f, notification?.progress)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theProgressIsTheShareOfEveryActiveDownload() {
|
||||
val notification =
|
||||
downloadNotification(
|
||||
listOf(
|
||||
row("s1", DownloadStatus.Running, bytes = 50, total = 100),
|
||||
row("s2", DownloadStatus.Queued, bytes = 150, total = 300),
|
||||
row("s3", DownloadStatus.Completed, bytes = 10, total = 10),
|
||||
),
|
||||
)
|
||||
|
||||
assertEquals("Downloading 2 songs", notification?.title)
|
||||
assertEquals(0.5f, notification?.progress)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anUnknownTotalLeavesTheProgressIndeterminate() {
|
||||
val notification = downloadNotification(listOf(row("s1", DownloadStatus.Running)))
|
||||
|
||||
assertEquals("In progress", notification?.text)
|
||||
assertNull(notification?.progress)
|
||||
}
|
||||
|
||||
private fun row(
|
||||
songId: String,
|
||||
status: DownloadStatus,
|
||||
bytes: Long = 0,
|
||||
total: Long = 0,
|
||||
) = SongDownload(sourceId = 1, songId = songId, status = status, bytes = bytes, total = total)
|
||||
}
|
||||
Reference in New Issue
Block a user