mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-26 13:24:39 +02:00
Add internal storage size check for download item part
This commit is contained in:
@@ -2,6 +2,7 @@ package com.audiobookshelf.app.managers
|
|||||||
|
|
||||||
import android.app.DownloadManager
|
import android.app.DownloadManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.StatFs
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import com.anggrayudi.storage.callback.FileCallback
|
import com.anggrayudi.storage.callback.FileCallback
|
||||||
@@ -101,6 +102,22 @@ class DownloadItemManager(
|
|||||||
val file = File(downloadItemPart.destinationUri.path ?: "")
|
val file = File(downloadItemPart.destinationUri.path ?: "")
|
||||||
file.parentFile?.mkdirs()
|
file.parentFile?.mkdirs()
|
||||||
|
|
||||||
|
// Check if enough internal storage is available for downloading
|
||||||
|
val statFs = StatFs(file.parentFile?.absolutePath ?: mainActivity.filesDir.absolutePath)
|
||||||
|
val availableBytes = statFs.availableBytes
|
||||||
|
val fileSize = downloadItemPart.fileSize
|
||||||
|
|
||||||
|
Log.d(
|
||||||
|
tag,
|
||||||
|
"Attempting to start ${downloadItemPart.filename}. Available: ${availableBytes / (1024)} KB, Required: ${fileSize / (1024)} KB"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The margin is based on how many simultaneous downloads can be running at once
|
||||||
|
if (availableBytes < fileSize * maxSimultaneousDownloads) {
|
||||||
|
Log.w(tag, "Not enough internal storage for ${downloadItemPart.filename}, skipping for now")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val internalProgressCallback =
|
val internalProgressCallback =
|
||||||
object : InternalProgressCallback {
|
object : InternalProgressCallback {
|
||||||
override fun onProgress(totalBytesWritten: Long, progress: Long) {
|
override fun onProgress(totalBytesWritten: Long, progress: Long) {
|
||||||
|
|||||||
Reference in New Issue
Block a user