pull/32/head
kunfei 5 years ago
parent e862836349
commit e903676179
  1. 23
      app/src/main/java/io/legado/app/help/BookHelp.kt
  2. 67
      app/src/main/java/io/legado/app/model/webbook/Debug.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
}
}

@ -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, "未找到书源")
}
}
Loading…
Cancel
Save