Avoid NoSuchFieldError.

This commit is contained in:
Isira Seneviratne 2023-04-21 07:07:41 +05:30
parent b169e768ce
commit 6c146f70db
2 changed files with 8 additions and 5 deletions

View File

@ -9,7 +9,6 @@ import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.db.obj.DownloadItem
import com.github.libretube.services.DownloadService
import java.nio.file.Path
import kotlin.io.path.createDirectories
object DownloadHelper {
const val VIDEO_DIR = "video"
@ -35,7 +34,11 @@ object DownloadHelper {
}
fun getDownloadDir(context: Context, path: String): Path {
return getOfflineStorageDir(context).resolve(path).createDirectories()
// TODO: Use createDirectories() when https://issuetracker.google.com/issues/279034662 is
// fixed.
return getOfflineStorageDir(context).resolve(path).apply {
toFile().mkdirs()
}
}
fun getMaxConcurrentDownloads(): Int {

View File

@ -45,6 +45,7 @@ import java.nio.file.StandardOpenOption
import java.util.concurrent.Executors
import kotlin.io.path.absolute
import kotlin.io.path.createFile
import kotlin.io.path.deleteIfExists
import kotlin.io.path.fileSize
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
@ -103,7 +104,6 @@ class DownloadService : LifecycleService() {
}
val thumbnailTargetPath = getDownloadPath(DownloadHelper.THUMBNAIL_DIR, fileName)
.absolute()
val download = Download(
videoId,
@ -147,7 +147,7 @@ class DownloadService : LifecycleService() {
FileType.AUDIO -> getDownloadPath(DownloadHelper.AUDIO_DIR, item.fileName)
FileType.VIDEO -> getDownloadPath(DownloadHelper.VIDEO_DIR, item.fileName)
FileType.SUBTITLE -> getDownloadPath(DownloadHelper.SUBTITLE_DIR, item.fileName)
}.createFile().absolute()
}.apply { deleteIfExists() }.createFile()
lifecycleScope.launch(coroutineContext) {
item.id = Database.downloadDao().insertDownloadItem(item).toInt()
@ -440,7 +440,7 @@ class DownloadService : LifecycleService() {
* Get a [File] from the corresponding download directory and the file name
*/
private fun getDownloadPath(directory: String, fileName: String): Path {
return DownloadHelper.getDownloadDir(this, directory).resolve(fileName)
return DownloadHelper.getDownloadDir(this, directory).resolve(fileName).absolute()
}
override fun onDestroy() {