mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-07 20:38:43 +02:00
Always download to internal app storage
This commit is contained in:
@@ -99,17 +99,19 @@ class DownloadItemManager(
|
||||
/** Processes the download item parts. */
|
||||
private fun processDownloadItemParts(nextDownloadItemParts: List<DownloadItemPart>) {
|
||||
nextDownloadItemParts.forEach {
|
||||
if (it.isInternalStorage) {
|
||||
startInternalDownload(it)
|
||||
} else {
|
||||
startExternalDownload(it)
|
||||
}
|
||||
// if (it.isInternalStorage) {
|
||||
startInternalDownload(it)
|
||||
// } else {
|
||||
// startExternalDownload(it)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/** Starts an internal download. */
|
||||
private fun startInternalDownload(downloadItemPart: DownloadItemPart) {
|
||||
val file = File(downloadItemPart.finalDestinationPath)
|
||||
// Create internal download location at temp directory location
|
||||
Log.d(tag, "Creating internal download location at ${downloadItemPart.destinationUri.path}")
|
||||
val file = File(downloadItemPart.destinationUri.path ?: "")
|
||||
file.parentFile?.mkdirs()
|
||||
|
||||
val internalProgressCallback =
|
||||
@@ -129,11 +131,7 @@ class DownloadItemManager(
|
||||
tag,
|
||||
"Start internal download to destination path ${downloadItemPart.finalDestinationPath} from ${downloadItemPart.serverUrl}"
|
||||
)
|
||||
InternalDownloadManager(
|
||||
mainActivity,
|
||||
downloadItemPart.finalDestinationUri,
|
||||
internalProgressCallback
|
||||
)
|
||||
InternalDownloadManager(mainActivity, downloadItemPart.destinationUri, internalProgressCallback)
|
||||
.download(downloadItemPart.serverUrl)
|
||||
downloadItemPart.downloadId = 1
|
||||
currentDownloadItemParts.add(downloadItemPart)
|
||||
@@ -159,11 +157,11 @@ class DownloadItemManager(
|
||||
while (currentDownloadItemParts.isNotEmpty()) {
|
||||
val itemParts = currentDownloadItemParts.filter { !it.isMoving }
|
||||
for (downloadItemPart in itemParts) {
|
||||
if (downloadItemPart.isInternalStorage) {
|
||||
handleInternalDownloadPart(downloadItemPart)
|
||||
} else {
|
||||
handleExternalDownloadPart(downloadItemPart)
|
||||
}
|
||||
// if (downloadItemPart.isInternalStorage) {
|
||||
handleInternalDownloadPart(downloadItemPart)
|
||||
// } else {
|
||||
// handleExternalDownloadPart(downloadItemPart)
|
||||
// }
|
||||
}
|
||||
|
||||
delay(500)
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.audiobookshelf.app.plugins
|
||||
|
||||
import android.app.DownloadManager
|
||||
import android.content.Context
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import com.audiobookshelf.app.MainActivity
|
||||
import com.audiobookshelf.app.data.*
|
||||
@@ -108,6 +107,8 @@ class AbsDownloader : Plugin() {
|
||||
DeviceManager.dbManager.saveLocalFolder(localFolder)
|
||||
}
|
||||
|
||||
val isInternal = localFolderId.startsWith("internal-")
|
||||
|
||||
if (localFolder != null) {
|
||||
if (episodeId.isNotEmpty() && libraryItem.mediaType != "podcast") {
|
||||
Log.e(tag, "Library item is not a podcast but episode was requested")
|
||||
@@ -119,11 +120,11 @@ class AbsDownloader : Plugin() {
|
||||
if (episode == null) {
|
||||
call.resolve(JSObject("{\"error\":\"Invalid podcast episode not found\"}"))
|
||||
} else {
|
||||
startLibraryItemDownload(libraryItem, localFolder, episode)
|
||||
startLibraryItemDownload(libraryItem, isInternal, localFolder, episode)
|
||||
call.resolve()
|
||||
}
|
||||
} else {
|
||||
startLibraryItemDownload(libraryItem, localFolder, null)
|
||||
startLibraryItemDownload(libraryItem, isInternal, localFolder, null)
|
||||
call.resolve()
|
||||
}
|
||||
} else {
|
||||
@@ -153,14 +154,12 @@ class AbsDownloader : Plugin() {
|
||||
|
||||
private fun startLibraryItemDownload(
|
||||
libraryItem: LibraryItem,
|
||||
isInternal: Boolean,
|
||||
localFolder: LocalFolder,
|
||||
episode: PodcastEpisode?
|
||||
) {
|
||||
val isInternal = localFolder.id.startsWith("internal-")
|
||||
|
||||
val tempFolderPath =
|
||||
if (isInternal) "${mainActivity.filesDir}/downloads/${libraryItem.id}"
|
||||
else mainActivity.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
|
||||
val tempFolderPath = "${mainActivity.filesDir}/downloads/${libraryItem.id}"
|
||||
|
||||
Log.d(tag, "downloadCacheDirectory=$tempFolderPath")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user