Skip to content

Instantly share code, notes, and snippets.

View FhdAlotaibi's full-sized avatar
👩‍💻
Focusing

Fahad Alotaibi FhdAlotaibi

👩‍💻
Focusing
View GitHub Profile
@FhdAlotaibi
FhdAlotaibi / DownloadProgressLiveData.kt
Last active November 20, 2023 11:27
Observe Download manager progress using LiveData and Coroutine
data class DownloadItem(val bytesDownloadedSoFar: Long = -1, val totalSizeBytes: Long = -1, val status: Int)
class DownloadProgressLiveData(private val application: Application, private val requestId: Long) : LiveData<DownloadItem>(), CoroutineScope {
private val downloadManager by lazy {
application.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
}
private val job = Job()