mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-04 01:54:33 +02:00
Add bookshelf list view
This commit is contained in:
parent
119bfd6c98
commit
105451ebf1
8 changed files with 471 additions and 255 deletions
|
@ -273,220 +273,3 @@ class AbsDownloader : Plugin() {
|
|||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// @PluginMethod
|
||||
// fun download(call: PluginCall) {
|
||||
// var audiobookId = call.data.getString("audiobookId", "audiobook").toString()
|
||||
// var url = call.data.getString("downloadUrl", "unknown").toString()
|
||||
// var coverDownloadUrl = call.data.getString("coverDownloadUrl", "").toString()
|
||||
// var title = call.data.getString("title", "Audiobook").toString()
|
||||
// var filename = call.data.getString("filename", "audiobook.mp3").toString()
|
||||
// var coverFilename = call.data.getString("coverFilename", "cover.png").toString()
|
||||
// var downloadFolderUrl = call.data.getString("downloadFolderUrl", "").toString()
|
||||
// var folder = DocumentFileCompat.fromUri(context, Uri.parse(downloadFolderUrl))!!
|
||||
// Log.d(tag, "Called download: $url | Folder: ${folder.name} | $downloadFolderUrl")
|
||||
//
|
||||
// var dlfilename = audiobookId + "." + File(filename).extension
|
||||
// var coverdlfilename = audiobookId + "." + File(coverFilename).extension
|
||||
// Log.d(tag, "DL Filename $dlfilename | Cover DL Filename $coverdlfilename")
|
||||
//
|
||||
// var canWriteToFolder = folder.canWrite()
|
||||
// if (!canWriteToFolder) {
|
||||
// Log.e(tag, "Error Cannot Write to Folder ${folder.baseName}")
|
||||
// val ret = JSObject()
|
||||
// ret.put("error", "Cannot write to ${folder.baseName}")
|
||||
// call.resolve(ret)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// var dlRequest = DownloadManager.Request(Uri.parse(url))
|
||||
// dlRequest.setTitle("Ab: $title")
|
||||
// dlRequest.setDescription("Downloading to ${folder.name}")
|
||||
// dlRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
||||
// dlRequest.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, dlfilename)
|
||||
//
|
||||
// var audiobookDownloadId = downloadManager.enqueue(dlRequest)
|
||||
// var coverDownloadId:Long? = null
|
||||
//
|
||||
// if (coverDownloadUrl != "") {
|
||||
// var coverDlRequest = DownloadManager.Request(Uri.parse(coverDownloadUrl))
|
||||
// coverDlRequest.setTitle("Cover: $title")
|
||||
// coverDlRequest.setDescription("Downloading to ${folder.name}")
|
||||
// coverDlRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION)
|
||||
// coverDlRequest.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, coverdlfilename)
|
||||
// coverDownloadId = downloadManager.enqueue(coverDlRequest)
|
||||
// }
|
||||
//
|
||||
// var progressReceiver : (id:Long, prog: Long) -> Unit = { id:Long, prog: Long ->
|
||||
// if (id == audiobookDownloadId) {
|
||||
// var jsobj = JSObject()
|
||||
// jsobj.put("audiobookId", audiobookId)
|
||||
// jsobj.put("progress", prog)
|
||||
// notifyListeners("onDownloadProgress", jsobj)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// var coverDocFile:DocumentFile? = null
|
||||
//
|
||||
// var doneReceiver : (id:Long, success: Boolean) -> Unit = { id:Long, success: Boolean ->
|
||||
// Log.d(tag, "RECEIVER DONE $id, SUCCES? $success")
|
||||
// var docfile:DocumentFile? = null
|
||||
//
|
||||
// // Download was complete, now find downloaded file
|
||||
// if (id == coverDownloadId) {
|
||||
// docfile = DocumentFileCompat.fromPublicFolder(context, PublicDirectory.DOWNLOADS, coverdlfilename)
|
||||
// Log.d(tag, "Move Cover File ${docfile?.name}")
|
||||
//
|
||||
// // For unknown reason, Android 10 test was using the title set in "setTitle" for the dl manager as the filename
|
||||
// // check if this was the case
|
||||
// if (docfile?.name == null) {
|
||||
// docfile = DocumentFileCompat.fromPublicFolder(context, PublicDirectory.DOWNLOADS, "Cover: $title")
|
||||
// Log.d(tag, "Cover File name attempt 2 ${docfile?.name}")
|
||||
// }
|
||||
// } else if (id == audiobookDownloadId) {
|
||||
// docfile = DocumentFileCompat.fromPublicFolder(context, PublicDirectory.DOWNLOADS, dlfilename)
|
||||
// Log.d(tag, "Move Audiobook File ${docfile?.name}")
|
||||
//
|
||||
// if (docfile?.name == null) {
|
||||
// docfile = DocumentFileCompat.fromPublicFolder(context, PublicDirectory.DOWNLOADS, "Ab: $title")
|
||||
// Log.d(tag, "File name attempt 2 ${docfile?.name}")
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Callback for moving the downloaded file
|
||||
// var callback = object : FileCallback() {
|
||||
// override fun onPrepare() {
|
||||
// Log.d(tag, "PREPARING MOVE FILE")
|
||||
// }
|
||||
// override fun onFailed(errorCode:ErrorCode) {
|
||||
// Log.e(tag, "FAILED MOVE FILE $errorCode")
|
||||
//
|
||||
// docfile?.delete()
|
||||
// coverDocFile?.delete()
|
||||
//
|
||||
// if (id == audiobookDownloadId) {
|
||||
// var jsobj = JSObject()
|
||||
// jsobj.put("audiobookId", audiobookId)
|
||||
// jsobj.put("error", "Move failed")
|
||||
// notifyListeners("onDownloadFailed", jsobj)
|
||||
// }
|
||||
// }
|
||||
// override fun onCompleted(result:Any) {
|
||||
// var resultDocFile = result as DocumentFile
|
||||
// var simplePath = resultDocFile.getSimplePath(context)
|
||||
// var storageId = resultDocFile.getStorageId(context)
|
||||
// var size = resultDocFile.length()
|
||||
// Log.d(tag, "Finished Moving File, NAME: ${resultDocFile.name} | URI:${resultDocFile.uri} | AbsolutePath:${resultDocFile.getAbsolutePath(context)} | $storageId | SimplePath: $simplePath")
|
||||
//
|
||||
// var abFolder = folder.findFolder(title)
|
||||
// var jsobj = JSObject()
|
||||
// jsobj.put("audiobookId", audiobookId)
|
||||
// jsobj.put("downloadId", id)
|
||||
// jsobj.put("storageId", storageId)
|
||||
// jsobj.put("storageType", resultDocFile.getStorageType(context))
|
||||
// jsobj.put("folderUrl", abFolder?.uri)
|
||||
// jsobj.put("folderName", abFolder?.name)
|
||||
// jsobj.put("downloadFolderUrl", downloadFolderUrl)
|
||||
// jsobj.put("contentUrl", resultDocFile.uri)
|
||||
// jsobj.put("basePath", resultDocFile.getBasePath(context))
|
||||
// jsobj.put("filename", filename)
|
||||
// jsobj.put("simplePath", simplePath)
|
||||
// jsobj.put("size", size)
|
||||
//
|
||||
// if (resultDocFile.name == filename) {
|
||||
// Log.d(tag, "Audiobook Finishing Moving")
|
||||
// } else if (resultDocFile.name == coverFilename) {
|
||||
// coverDocFile = docfile
|
||||
// Log.d(tag, "Audiobook Cover Finished Moving")
|
||||
// jsobj.put("isCover", true)
|
||||
// }
|
||||
// notifyListeners("onDownloadComplete", jsobj)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // After file is downloaded, move the files into an audiobook directory inside the user selected folder
|
||||
// if (id == coverDownloadId) {
|
||||
// docfile?.moveFileTo(context, folder, FileDescription(coverFilename, title, MimeType.IMAGE), callback)
|
||||
// } else if (id == audiobookDownloadId) {
|
||||
// docfile?.moveFileTo(context, folder, FileDescription(filename, title, MimeType.AUDIO), callback)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// var progressUpdater = DownloadProgressUpdater(downloadManager, audiobookDownloadId, progressReceiver, doneReceiver)
|
||||
// progressUpdater.run()
|
||||
// if (coverDownloadId != null) {
|
||||
// var coverProgressUpdater = DownloadProgressUpdater(downloadManager, coverDownloadId, progressReceiver, doneReceiver)
|
||||
// coverProgressUpdater.run()
|
||||
// }
|
||||
//
|
||||
// val ret = JSObject()
|
||||
// ret.put("audiobookDownloadId", audiobookDownloadId)
|
||||
// ret.put("coverDownloadId", coverDownloadId)
|
||||
// call.resolve(ret)
|
||||
// }
|
||||
//
|
||||
//
|
||||
//internal class DownloadProgressUpdater(private val manager: DownloadManager, private val downloadId: Long, private var receiver: (Long, Long) -> Unit, private var doneReceiver: (Long, Boolean) -> Unit) : Thread() {
|
||||
// private val query: DownloadManager.Query = DownloadManager.Query()
|
||||
// private var totalBytes: Int = 0
|
||||
// private var TAG = "DownloadProgressUpdater"
|
||||
//
|
||||
// init {
|
||||
// query.setFilterById(this.downloadId)
|
||||
// }
|
||||
//
|
||||
// override fun run() {
|
||||
// Log.d(TAG, "RUN FOR ID $downloadId")
|
||||
// var keepRunning = true
|
||||
// var increment = 0
|
||||
// while (keepRunning) {
|
||||
// Thread.sleep(500)
|
||||
// increment++
|
||||
//
|
||||
// if (increment % 4 == 0) {
|
||||
// Log.d(TAG, "Loop $increment : $downloadId")
|
||||
// }
|
||||
//
|
||||
// manager.query(query).use {
|
||||
// if (it.moveToFirst()) {
|
||||
// //get total bytes of the file
|
||||
// if (totalBytes <= 0) {
|
||||
// totalBytes = it.getInt(it.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES))
|
||||
// if (totalBytes <= 0) {
|
||||
// Log.e(TAG, "Download Is 0 Bytes $downloadId")
|
||||
// doneReceiver(downloadId, false)
|
||||
// keepRunning = false
|
||||
// this.interrupt()
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// val downloadStatus = it.getInt(it.getColumnIndex(DownloadManager.COLUMN_STATUS))
|
||||
// val bytesDownloadedSoFar = it.getInt(it.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR))
|
||||
//
|
||||
// if (increment % 4 == 0) {
|
||||
// Log.d(TAG, "BYTES $increment : $downloadId : $bytesDownloadedSoFar : TOTAL: $totalBytes")
|
||||
// }
|
||||
//
|
||||
// if (downloadStatus == DownloadManager.STATUS_SUCCESSFUL || downloadStatus == DownloadManager.STATUS_FAILED) {
|
||||
// if (downloadStatus == DownloadManager.STATUS_SUCCESSFUL) {
|
||||
// doneReceiver(downloadId, true)
|
||||
// } else {
|
||||
// doneReceiver(downloadId, false)
|
||||
// }
|
||||
// keepRunning = false
|
||||
// this.interrupt()
|
||||
// } else {
|
||||
// //update progress
|
||||
// val percentProgress = ((bytesDownloadedSoFar * 100L) / totalBytes)
|
||||
// receiver(downloadId, percentProgress)
|
||||
// }
|
||||
// } else {
|
||||
// Log.e(TAG, "NOT FOUND IN QUERY")
|
||||
// keepRunning = false
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue