From d867dc34354f74b7a98a6674f6097b317eef1e41 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 12:34:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{txtChapterRule.json => txtTocRule.json} | 0 .../app/model/localBook/AnalyzeTxtFile.kt | 20 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) rename app/src/main/assets/{txtChapterRule.json => txtTocRule.json} (100%) diff --git a/app/src/main/assets/txtChapterRule.json b/app/src/main/assets/txtTocRule.json similarity index 100% rename from app/src/main/assets/txtChapterRule.json rename to app/src/main/assets/txtTocRule.json diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 96a44e1c5..9d6777057 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -4,9 +4,8 @@ import android.content.Context import android.net.Uri import io.legado.app.App import io.legado.app.data.entities.Book -import io.legado.app.utils.DocumentUtils -import io.legado.app.utils.EncodingDetect -import io.legado.app.utils.FileUtils +import io.legado.app.data.entities.TxtTocRule +import io.legado.app.utils.* import java.io.File import java.io.RandomAccessFile @@ -29,10 +28,23 @@ object AnalyzeTxtFile { } } book.charset = EncodingDetect.getEncode(bookFile) - + val tocRules = getTocRules() //获取文件流 val bookStream = RandomAccessFile(bookFile, "r") } + + private fun getTocRules(): List { + val rules = App.db.txtTocRule().all + if (rules.isEmpty()) { + App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray -> + GSON.fromJsonArray(String(byteArray))?.let { + App.db.txtTocRule().insert(*it.toTypedArray()) + return it + } + } + } + return rules + } } \ No newline at end of file