Merge remote-tracking branch 'origin/master'

pull/1486/head
gedoor 3 years ago
commit 8922dfafd4
  1. 19
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  2. 8
      app/src/main/java/io/legado/app/model/localBook/TextFile.kt

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

@ -14,13 +14,13 @@ import java.nio.charset.Charset
import java.util.regex.Matcher
import java.util.regex.Pattern
class TextFile {
class TextFile(private val book: Book) {
private val tocRules = arrayListOf<TxtTocRule>()
private lateinit var charset: Charset
@Throws(Exception::class)
fun analyze(book: Book): ArrayList<BookChapter> {
fun getChapterList(): ArrayList<BookChapter> {
val bookFile = getBookFile(book)
if (book.charset == null) {
book.charset = EncodingDetect.getEncode(bookFile)
@ -249,6 +249,10 @@ class TextFile {
//没有标题的时候,每个章节的最大长度
private const val MAX_LENGTH_WITH_NO_CHAPTER = 10 * 1024
fun getChapterList(book: Book): ArrayList<BookChapter> {
return TextFile(book).getChapterList()
}
fun getContent(book: Book, bookChapter: BookChapter): String {
val bookFile = getBookFile(book)
//获取文件流

Loading…
Cancel
Save