mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
Merge pull request #4307 from Isira-Seneviratne/Files_createDirectories
fix: use Files.createDirectories()
This commit is contained in:
commit
74a7518d7b
@ -10,6 +10,7 @@ import com.github.libretube.db.obj.DownloadItem
|
|||||||
import com.github.libretube.parcelable.DownloadData
|
import com.github.libretube.parcelable.DownloadData
|
||||||
import com.github.libretube.services.DownloadService
|
import com.github.libretube.services.DownloadService
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
import kotlin.io.path.createDirectories
|
||||||
|
|
||||||
object DownloadHelper {
|
object DownloadHelper {
|
||||||
const val VIDEO_DIR = "video"
|
const val VIDEO_DIR = "video"
|
||||||
@ -21,8 +22,8 @@ object DownloadHelper {
|
|||||||
const val DEFAULT_TIMEOUT = 15 * 1000
|
const val DEFAULT_TIMEOUT = 15 * 1000
|
||||||
const val DEFAULT_RETRY = 3
|
const val DEFAULT_RETRY = 3
|
||||||
|
|
||||||
private fun getOfflineStorageDir(context: Context): Path {
|
fun getDownloadDir(context: Context, path: String): Path {
|
||||||
val file = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
val storageDir = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||||
context.filesDir
|
context.filesDir
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@ -31,15 +32,7 @@ object DownloadHelper {
|
|||||||
context.filesDir
|
context.filesDir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return file.toPath()
|
return storageDir.toPath().resolve(path).createDirectories()
|
||||||
}
|
|
||||||
|
|
||||||
fun getDownloadDir(context: Context, path: String): Path {
|
|
||||||
// TODO: Use createDirectories() when https://issuetracker.google.com/issues/279034662 is
|
|
||||||
// fixed.
|
|
||||||
return getOfflineStorageDir(context).resolve(path).apply {
|
|
||||||
toFile().mkdirs()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMaxConcurrentDownloads(): Int {
|
fun getMaxConcurrentDownloads(): Int {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user