优化
This commit is contained in:
@@ -57,9 +57,8 @@ object LocalBook {
|
|||||||
}.firstOrNull()?.let {
|
}.firstOrNull()?.let {
|
||||||
getBookInputStream(it)
|
getBookInputStream(it)
|
||||||
}
|
}
|
||||||
} else if (webDavUrl != null) {
|
} else if (webDavUrl != null && downloadRemoteBook(book)) {
|
||||||
// 下载远程链接
|
// 下载远程链接
|
||||||
downloadRemoteBook(book)
|
|
||||||
getBookInputStream(book)
|
getBookInputStream(book)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
@@ -90,12 +89,15 @@ object LocalBook {
|
|||||||
book.isEpub -> {
|
book.isEpub -> {
|
||||||
EpubFile.getChapterList(book)
|
EpubFile.getChapterList(book)
|
||||||
}
|
}
|
||||||
|
|
||||||
book.isUmd -> {
|
book.isUmd -> {
|
||||||
UmdFile.getChapterList(book)
|
UmdFile.getChapterList(book)
|
||||||
}
|
}
|
||||||
|
|
||||||
book.isPdf -> {
|
book.isPdf -> {
|
||||||
PdfFile.getChapterList(book)
|
PdfFile.getChapterList(book)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
TextFile.getChapterList(book)
|
TextFile.getChapterList(book)
|
||||||
}
|
}
|
||||||
@@ -117,12 +119,15 @@ object LocalBook {
|
|||||||
book.isEpub -> {
|
book.isEpub -> {
|
||||||
EpubFile.getContent(book, chapter)
|
EpubFile.getContent(book, chapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
book.isUmd -> {
|
book.isUmd -> {
|
||||||
UmdFile.getContent(book, chapter)
|
UmdFile.getContent(book, chapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
book.isPdf -> {
|
book.isPdf -> {
|
||||||
PdfFile.getContent(book, chapter)
|
PdfFile.getContent(book, chapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
TextFile.getContent(book, chapter)
|
TextFile.getContent(book, chapter)
|
||||||
}
|
}
|
||||||
@@ -218,7 +223,7 @@ object LocalBook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 批量导入 支持自动导入压缩包的支持书籍 */
|
/* 批量导入 支持自动导入压缩包的支持书籍 */
|
||||||
fun importFiles(uri: Uri): List<Book> {
|
fun importFiles(uri: Uri): List<Book> {
|
||||||
val books = mutableListOf<Book>()
|
val books = mutableListOf<Book>()
|
||||||
val fileDoc = FileDoc.fromUri(uri, false)
|
val fileDoc = FileDoc.fromUri(uri, false)
|
||||||
@@ -329,6 +334,7 @@ object LocalBook {
|
|||||||
Base64.DEFAULT
|
Base64.DEFAULT
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> throw NoStackTraceException("在线导入书籍支持http/https/DataURL")
|
else -> throw NoStackTraceException("在线导入书籍支持http/https/DataURL")
|
||||||
}
|
}
|
||||||
return saveBookFile(inputStream, fileName)
|
return saveBookFile(inputStream, fileName)
|
||||||
@@ -383,7 +389,7 @@ object LocalBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//下载book对应的远程文件 并更新Book
|
//下载book对应的远程文件 并更新Book
|
||||||
private fun downloadRemoteBook(localBook: Book) {
|
private fun downloadRemoteBook(localBook: Book): Boolean {
|
||||||
val webDavUrl = localBook.getRemoteUrl()
|
val webDavUrl = localBook.getRemoteUrl()
|
||||||
if (webDavUrl.isNullOrBlank()) throw NoStackTraceException("Book file is not webDav File")
|
if (webDavUrl.isNullOrBlank()) throw NoStackTraceException("Book file is not webDav File")
|
||||||
try {
|
try {
|
||||||
@@ -415,9 +421,11 @@ object LocalBook {
|
|||||||
localBook.save()
|
localBook.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printOnDebug()
|
e.printOnDebug()
|
||||||
AppLog.put("自动下载webDav书籍失败", e)
|
AppLog.put("自动下载webDav书籍失败", e)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user