优化
This commit is contained in:
@@ -88,6 +88,9 @@ interface BookDao {
|
|||||||
@Query("select 1 from books where bookUrl = :bookUrl")
|
@Query("select 1 from books where bookUrl = :bookUrl")
|
||||||
fun has(bookUrl: String): Boolean?
|
fun has(bookUrl: String): Boolean?
|
||||||
|
|
||||||
|
@Query("select 1 from books where bookUrl like '%' || :fileName")
|
||||||
|
fun hasFile(fileName: String): Boolean?
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun insert(vararg book: Book)
|
fun insert(vararg book: Book)
|
||||||
|
|
||||||
|
|||||||
@@ -108,9 +108,7 @@ object LocalBook {
|
|||||||
fileName: String,
|
fileName: String,
|
||||||
source: BaseSource? = null,
|
source: BaseSource? = null,
|
||||||
): Book {
|
): Book {
|
||||||
return saveBookFile(str, fileName, source).let {
|
return importFile(saveBookFile(str, fileName, source))
|
||||||
importFile(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -275,20 +273,7 @@ object LocalBook {
|
|||||||
fun isOnBookShelf(
|
fun isOnBookShelf(
|
||||||
fileName: String
|
fileName: String
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val defaultBookTreeUri = AppConfig.defaultBookTreeUri
|
return appDb.bookDao.hasFile(fileName) == true
|
||||||
if (defaultBookTreeUri.isNullOrBlank()) throw NoStackTraceException("没有设置书籍保存位置!")
|
|
||||||
val treeUri = Uri.parse(defaultBookTreeUri)
|
|
||||||
val bookUrl = if (treeUri.isContentScheme()) {
|
|
||||||
val treeDoc = DocumentFile.fromTreeUri(appCtx, treeUri)
|
|
||||||
val doc = treeDoc!!.findFile(fileName) ?: return false
|
|
||||||
doc.uri.toString()
|
|
||||||
} else {
|
|
||||||
val treeFile = File(treeUri.path!!)
|
|
||||||
val file = treeFile.getFile(fileName)
|
|
||||||
if (!file.exists()) return false
|
|
||||||
file.absolutePath
|
|
||||||
}
|
|
||||||
return appDb.bookDao.getBook(bookUrl) != null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//文件类书源 合并在线书籍信息 在线 > 本地
|
//文件类书源 合并在线书籍信息 在线 > 本地
|
||||||
|
|||||||
Reference in New Issue
Block a user