refactor:add BaseLocalBookParse interface

pull/1786/head
Xwite 3 years ago
parent 040cc1a9cd
commit a327d6d53a
  1. 21
      app/src/main/java/io/legado/app/model/localBook/BaseLocalBookParse.kt
  2. 10
      app/src/main/java/io/legado/app/model/localBook/EpubFile.kt
  3. 7
      app/src/main/java/io/legado/app/model/localBook/README.md
  4. 10
      app/src/main/java/io/legado/app/model/localBook/UmdFile.kt

@ -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?
}

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

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

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

Loading…
Cancel
Save