|
|
@ -59,23 +59,25 @@ object LocalBook { |
|
|
|
|
|
|
|
|
|
|
|
fun importFile(uri: Uri): Book { |
|
|
|
fun importFile(uri: Uri): Book { |
|
|
|
val path: String |
|
|
|
val path: String |
|
|
|
|
|
|
|
val updateTime: Long |
|
|
|
//这个变量不要修改,否则会导致读取不到缓存 |
|
|
|
//这个变量不要修改,否则会导致读取不到缓存 |
|
|
|
val fileName = (if (uri.isContentScheme()) { |
|
|
|
val fileName = (if (uri.isContentScheme()) { |
|
|
|
path = uri.toString() |
|
|
|
path = uri.toString() |
|
|
|
val doc = DocumentFile.fromSingleUri(appCtx, uri) |
|
|
|
val doc = DocumentFile.fromSingleUri(appCtx, uri)!! |
|
|
|
doc?.let { |
|
|
|
updateTime = doc.lastModified() |
|
|
|
val bookFile = cacheFolder.getFile(it.name!!) |
|
|
|
val bookFile = cacheFolder.getFile(doc.name!!) |
|
|
|
if (!bookFile.exists()) { |
|
|
|
if (!bookFile.exists()) { |
|
|
|
bookFile.createNewFile() |
|
|
|
bookFile.createNewFile() |
|
|
|
doc.readBytes(appCtx).let { bytes -> |
|
|
|
doc.readBytes(appCtx).let { bytes -> |
|
|
|
bookFile.writeBytes(bytes) |
|
|
|
bookFile.writeBytes(bytes) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
doc?.name!! |
|
|
|
doc.name!! |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
path = uri.path!! |
|
|
|
path = uri.path!! |
|
|
|
File(path).name |
|
|
|
val file = File(path) |
|
|
|
|
|
|
|
updateTime = file.lastModified() |
|
|
|
|
|
|
|
file.name |
|
|
|
}) |
|
|
|
}) |
|
|
|
var book = appDb.bookDao.getBook(path) |
|
|
|
var book = appDb.bookDao.getBook(path) |
|
|
|
if (book == null) { |
|
|
|
if (book == null) { |
|
|
@ -89,7 +91,8 @@ object LocalBook { |
|
|
|
appCtx.externalFiles, |
|
|
|
appCtx.externalFiles, |
|
|
|
"covers", |
|
|
|
"covers", |
|
|
|
"${MD5Utils.md5Encode16(path)}.jpg" |
|
|
|
"${MD5Utils.md5Encode16(path)}.jpg" |
|
|
|
) |
|
|
|
), |
|
|
|
|
|
|
|
latestChapterTime = updateTime |
|
|
|
) |
|
|
|
) |
|
|
|
if (book.isEpub()) EpubFile.upBookInfo(book) |
|
|
|
if (book.isEpub()) EpubFile.upBookInfo(book) |
|
|
|
if (book.isUmd()) UmdFile.upBookInfo(book) |
|
|
|
if (book.isUmd()) UmdFile.upBookInfo(book) |
|
|
|