feat: 优化代码

pull/178/head
kunfei 5 years ago
parent b6f7f48b2f
commit 9881d6e95b
  1. 2
      app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -18,6 +18,7 @@ class AnalyzeTxtFile {
private val tocRules = arrayListOf<TxtTocRule>() private val tocRules = arrayListOf<TxtTocRule>()
private lateinit var charset: Charset private lateinit var charset: Charset
@Throws(Exception::class)
fun analyze(context: Context, book: Book): ArrayList<BookChapter> { fun analyze(context: Context, book: Book): ArrayList<BookChapter> {
val bookFile = getBookFile(context, book) val bookFile = getBookFile(context, book)
book.charset = EncodingDetect.getEncode(bookFile) book.charset = EncodingDetect.getEncode(bookFile)
@ -33,6 +34,7 @@ class AnalyzeTxtFile {
return analyze(bookStream, book, rulePattern) return analyze(bookStream, book, rulePattern)
} }
@Throws(Exception::class)
private fun analyze( private fun analyze(
bookStream: RandomAccessFile, bookStream: RandomAccessFile,
book: Book, book: Book,

@ -112,6 +112,8 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
toast(R.string.error_no_source) toast(R.string.error_no_source)
} }
} }
}.onError {
toast("LoadTocError:${it.localizedMessage}")
} }
} }

@ -129,6 +129,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.upMsg(context.getString(R.string.error_load_toc)) ReadBook.upMsg(context.getString(R.string.error_load_toc))
} }
} }
}.onError {
ReadBook.upMsg("LoadTocError:${it.localizedMessage}")
} }
} }

Loading…
Cancel
Save