From e903676179f4f55960f6164673f9dd9215bcf817 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 27 Jul 2019 17:20:46 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/help/BookHelp.kt | 23 +++++++ .../java/io/legado/app/model/webbook/Debug.kt | 67 ++++++++++++++----- 2 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/io/legado/app/help/BookHelp.kt diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt new file mode 100644 index 000000000..1e975631f --- /dev/null +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -0,0 +1,23 @@ +package io.legado.app.help + +import io.legado.app.data.entities.Book +import io.legado.app.data.entities.SearchBook + +object BookHelp { + + fun toBook(searchBook: SearchBook): Book { + val book = Book() + book.name = searchBook.name + book.author = searchBook.author + book.kind = searchBook.kind + book.bookUrl = searchBook.bookUrl + book.origin = searchBook.origin + book.wordCount = searchBook.wordCount + book.latestChapterTitle = searchBook.latestChapterTitle + book.coverUrl = searchBook.coverUrl + + return book + } + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/webbook/Debug.kt b/app/src/main/java/io/legado/app/model/webbook/Debug.kt index 82047ddd0..a62fe1b2a 100644 --- a/app/src/main/java/io/legado/app/model/webbook/Debug.kt +++ b/app/src/main/java/io/legado/app/model/webbook/Debug.kt @@ -1,32 +1,67 @@ package io.legado.app.model.webbook import android.annotation.SuppressLint +import io.legado.app.App +import io.legado.app.data.entities.Book +import io.legado.app.data.entities.BookSource +import io.legado.app.help.BookHelp +import io.legado.app.model.WebBook import io.legado.app.utils.htmlFormat import java.text.SimpleDateFormat import java.util.* -object Debug { +class Debug(sourceUrl: String) { - var debugSource: String? = null - var callback: Callback? = null - @SuppressLint("ConstantLocale") - private val DEBUG_TIME_FORMAT = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault()) - private val startTime: Long = System.currentTimeMillis() + companion object { + var debugSource: String? = null + var callback: Callback? = null + @SuppressLint("ConstantLocale") + private val DEBUG_TIME_FORMAT = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault()) + private val startTime: Long = System.currentTimeMillis() + + fun printLog(source: String?, state: Int, msg: String, print: Boolean = true, isHtml: Boolean = false) { + if (debugSource != source) return + if (!print) return + var printMsg = msg + if (isHtml) { + printMsg = printMsg.htmlFormat() + } + printMsg = + String.format("%s %s", DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - startTime)), printMsg) + callback?.printLog(state, printMsg) + } + } interface Callback { fun printLog(state: Int, msg: String) } - fun printLog(source: String, state: Int, msg: String, print: Boolean = true, isHtml: Boolean = false) { - if (debugSource != source) return - if (!print) return - var printMsg = msg - if (isHtml) { - printMsg = printMsg.htmlFormat() - } - printMsg = - String.format("%s %s", DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - startTime)), printMsg) - callback?.printLog(state, printMsg) + private var bookSource: BookSource? = null + + init { + debugSource = sourceUrl + bookSource = App.db.bookSourceDao().findByKey(sourceUrl) } + fun searchDebug(key: String) { + bookSource?.let { + WebBook(it).searchBook(key, 1) + .onSuccess { searchBooks -> + searchBooks?.let { + if (searchBooks.isNotEmpty()) { + infoDebug(BookHelp.toBook(searchBooks[0])) + } + } + } + + } ?: printLog(debugSource, -1, "未找到书源") + } + + fun infoDebug(book: Book) { + bookSource?.let { + WebBook(it).getBookInfo(book) + } ?: printLog(debugSource, -1, "未找到书源") + } + + } \ No newline at end of file