pull/84/head
kunfei 5 years ago
parent 864b61ccba
commit d867dc3435
  1. 0
      app/src/main/assets/txtTocRule.json
  2. 20
      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<TxtTocRule> {
val rules = App.db.txtTocRule().all
if (rules.isEmpty()) {
App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray ->
GSON.fromJsonArray<TxtTocRule>(String(byteArray))?.let {
App.db.txtTocRule().insert(*it.toTypedArray())
return it
}
}
}
return rules
}
}
Loading…
Cancel
Save