|
|
@ -4,16 +4,20 @@ import android.annotation.SuppressLint |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
|
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
import io.legado.app.model.WebBook |
|
|
|
import io.legado.app.model.WebBook |
|
|
|
import io.legado.app.utils.htmlFormat |
|
|
|
import io.legado.app.utils.htmlFormat |
|
|
|
|
|
|
|
import io.legado.app.utils.isAbsUrl |
|
|
|
import java.text.SimpleDateFormat |
|
|
|
import java.text.SimpleDateFormat |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
class SourceDebug(private val webBook: WebBook, callback: Callback) { |
|
|
|
class SourceDebug(private val webBook: WebBook, callback: Callback) { |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
var debugSource: String? = null |
|
|
|
private var debugSource: String? = null |
|
|
|
var callback: Callback? = null |
|
|
|
private var callback: Callback? = null |
|
|
|
|
|
|
|
private val tasks: MutableList<Coroutine<*>> = mutableListOf() |
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("ConstantLocale") |
|
|
|
@SuppressLint("ConstantLocale") |
|
|
|
private val DEBUG_TIME_FORMAT = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault()) |
|
|
|
private val DEBUG_TIME_FORMAT = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault()) |
|
|
|
private val startTime: Long = System.currentTimeMillis() |
|
|
|
private val startTime: Long = System.currentTimeMillis() |
|
|
@ -29,18 +33,46 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { |
|
|
|
String.format("%s %s", DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - startTime)), printMsg) |
|
|
|
String.format("%s %s", DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - startTime)), printMsg) |
|
|
|
callback?.printLog(state, printMsg) |
|
|
|
callback?.printLog(state, printMsg) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface Callback { |
|
|
|
fun cancelDebug() { |
|
|
|
fun printLog(state: Int, msg: String) |
|
|
|
tasks.forEach { |
|
|
|
|
|
|
|
if (!it.isCancelled) { |
|
|
|
|
|
|
|
it.cancel() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tasks.clear() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun stopDebug(){ |
|
|
|
|
|
|
|
cancelDebug() |
|
|
|
|
|
|
|
debugSource = null |
|
|
|
|
|
|
|
callback = null |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
|
|
|
|
debugSource = webBook.sourceUrl |
|
|
|
SourceDebug.callback = callback |
|
|
|
SourceDebug.callback = callback |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun startDebug(key: String) { |
|
|
|
|
|
|
|
cancelDebug() |
|
|
|
|
|
|
|
with(webBook) { |
|
|
|
|
|
|
|
if (key.isAbsUrl()) { |
|
|
|
|
|
|
|
val book = Book() |
|
|
|
|
|
|
|
book.origin = sourceUrl |
|
|
|
|
|
|
|
book.bookUrl = key |
|
|
|
|
|
|
|
printLog(sourceUrl, 1, "开始访问$key") |
|
|
|
|
|
|
|
infoDebug(book) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
printLog(sourceUrl, 1, "开始搜索关键字$key") |
|
|
|
|
|
|
|
searchDebug(key) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun searchDebug(key: String) { |
|
|
|
fun searchDebug(key: String) { |
|
|
|
webBook.searchBook(key, 1) |
|
|
|
val search = webBook.searchBook(key, 1) |
|
|
|
.onSuccess { searchBooks -> |
|
|
|
.onSuccess { searchBooks -> |
|
|
|
searchBooks?.let { |
|
|
|
searchBooks?.let { |
|
|
|
if (searchBooks.isNotEmpty()) { |
|
|
|
if (searchBooks.isNotEmpty()) { |
|
|
@ -51,20 +83,22 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { |
|
|
|
.onError { |
|
|
|
.onError { |
|
|
|
printLog(debugSource, -1, it.localizedMessage) |
|
|
|
printLog(debugSource, -1, it.localizedMessage) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
tasks.add(search) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun infoDebug(book: Book) { |
|
|
|
fun infoDebug(book: Book) { |
|
|
|
webBook.getBookInfo(book) |
|
|
|
val info = webBook.getBookInfo(book) |
|
|
|
.onSuccess { |
|
|
|
.onSuccess { |
|
|
|
tocDebug(book) |
|
|
|
tocDebug(book) |
|
|
|
} |
|
|
|
} |
|
|
|
.onError { |
|
|
|
.onError { |
|
|
|
printLog(debugSource, -1, it.localizedMessage) |
|
|
|
printLog(debugSource, -1, it.localizedMessage) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
tasks.add(info) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun tocDebug(book: Book) { |
|
|
|
private fun tocDebug(book: Book) { |
|
|
|
webBook.getChapterList(book) |
|
|
|
val chapterList = webBook.getChapterList(book) |
|
|
|
.onSuccess { chapterList -> |
|
|
|
.onSuccess { chapterList -> |
|
|
|
chapterList?.let { |
|
|
|
chapterList?.let { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
if (it.isNotEmpty()) { |
|
|
@ -75,10 +109,11 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { |
|
|
|
.onError { |
|
|
|
.onError { |
|
|
|
printLog(debugSource, -1, it.localizedMessage) |
|
|
|
printLog(debugSource, -1, it.localizedMessage) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
tasks.add(chapterList) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun contentDebug(book: Book, bookChapter: BookChapter) { |
|
|
|
private fun contentDebug(book: Book, bookChapter: BookChapter) { |
|
|
|
webBook.getContent(book, bookChapter) |
|
|
|
val content = webBook.getContent(book, bookChapter) |
|
|
|
.onSuccess { content -> |
|
|
|
.onSuccess { content -> |
|
|
|
content?.let { |
|
|
|
content?.let { |
|
|
|
printLog(debugSource, 1000, it) |
|
|
|
printLog(debugSource, 1000, it) |
|
|
@ -87,5 +122,10 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { |
|
|
|
.onError { |
|
|
|
.onError { |
|
|
|
printLog(debugSource, -1, it.localizedMessage) |
|
|
|
printLog(debugSource, -1, it.localizedMessage) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
tasks.add(content) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface Callback { |
|
|
|
|
|
|
|
fun printLog(state: Int, msg: String) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |