refactor:add BaseLocalBookParse interface

This commit is contained in:
Xwite
2022-04-14 11:41:29 +08:00
parent 040cc1a9cd
commit a327d6d53a
4 changed files with 38 additions and 10 deletions

View File

@@ -0,0 +1,21 @@
package io.legado.app.model.localBook
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import java.io.InputStream
/**
*companion object interface
*see EpubFile.kt
*/
interface BaseLocalBookParse {
fun upBookInfo(book: Book)
fun getChapterList(book: Book): ArrayList<BookChapter>
fun getContent(book: Book, chapter: BookChapter): String?
fun getImage(book: Book, href: String): InputStream?
}

View File

@@ -25,7 +25,7 @@ import java.util.zip.ZipFile
class EpubFile(var book: Book) {
companion object {
companion object : BaseLocalBookParse {
private var eFile: EpubFile? = null
@Synchronized
@@ -41,17 +41,17 @@ class EpubFile(var book: Book) {
}
@Synchronized
fun getChapterList(book: Book): ArrayList<BookChapter> {
override fun getChapterList(book: Book): ArrayList<BookChapter> {
return getEFile(book).getChapterList()
}
@Synchronized
fun getContent(book: Book, chapter: BookChapter): String? {
override fun getContent(book: Book, chapter: BookChapter): String? {
return getEFile(book).getContent(chapter)
}
@Synchronized
fun getImage(
override fun getImage(
book: Book,
href: String
): InputStream? {
@@ -59,7 +59,7 @@ class EpubFile(var book: Book) {
}
@Synchronized
fun upBookInfo(book: Book) {
override fun upBookInfo(book: Book) {
return getEFile(book).upBookInfo()
}
}

View File

@@ -0,0 +1,7 @@
# 本地书籍解析
* BaseLocalBookParse.kt 本地书籍解析接口
* LocalBook.kt 总入口
* TextFile.kt 解析txt
* EpubFile.kt 解析epub
* UmdFile.kt 解析umd

View File

@@ -11,7 +11,7 @@ import java.io.File
import java.io.InputStream
class UmdFile(var book: Book) {
companion object {
companion object : BaseLocalBookParse {
private var uFile: UmdFile? = null
@Synchronized
@@ -25,17 +25,17 @@ class UmdFile(var book: Book) {
}
@Synchronized
fun getChapterList(book: Book): ArrayList<BookChapter> {
override fun getChapterList(book: Book): ArrayList<BookChapter> {
return getUFile(book).getChapterList()
}
@Synchronized
fun getContent(book: Book, chapter: BookChapter): String? {
override fun getContent(book: Book, chapter: BookChapter): String? {
return getUFile(book).getContent(chapter)
}
@Synchronized
fun getImage(
override fun getImage(
book: Book,
href: String
): InputStream? {
@@ -44,7 +44,7 @@ class UmdFile(var book: Book) {
@Synchronized
fun upBookInfo(book: Book) {
override fun upBookInfo(book: Book) {
return getUFile(book).upBookInfo()
}
}