pull/32/head
kunfei 5 years ago
parent e903676179
commit d14edecc1a
  1. 42
      app/src/main/java/io/legado/app/model/webbook/SourceDebug.kt
  2. 27
      app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt

@ -1,16 +1,15 @@
package io.legado.app.model.webbook package io.legado.app.model.webbook
import android.annotation.SuppressLint import android.annotation.SuppressLint
import io.legado.app.App
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
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 java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
class Debug(sourceUrl: String) { class SourceDebug(val webBook: WebBook) {
companion object { companion object {
var debugSource: String? = null var debugSource: String? = null
@ -36,16 +35,8 @@ class Debug(sourceUrl: String) {
fun printLog(state: Int, msg: String) fun printLog(state: Int, msg: String)
} }
private var bookSource: BookSource? = null
init {
debugSource = sourceUrl
bookSource = App.db.bookSourceDao().findByKey(sourceUrl)
}
fun searchDebug(key: String) { fun searchDebug(key: String) {
bookSource?.let { webBook.searchBook(key, 1)
WebBook(it).searchBook(key, 1)
.onSuccess { searchBooks -> .onSuccess { searchBooks ->
searchBooks?.let { searchBooks?.let {
if (searchBooks.isNotEmpty()) { if (searchBooks.isNotEmpty()) {
@ -53,15 +44,32 @@ class Debug(sourceUrl: String) {
} }
} }
} }
} ?: printLog(debugSource, -1, "未找到书源")
} }
fun infoDebug(book: Book) { fun infoDebug(book: Book) {
bookSource?.let { webBook.getBookInfo(book)
WebBook(it).getBookInfo(book) .onSuccess {
} ?: printLog(debugSource, -1, "未找到书源") tocDebug(book)
}
} }
private fun tocDebug(book: Book) {
webBook.getChapterList(book)
.onSuccess { chapterList ->
chapterList?.let {
if (it.isNotEmpty()) {
contentDebug(book, it[0])
}
}
}
}
private fun contentDebug(book: Book, bookChapter: BookChapter) {
webBook.getContent(book, bookChapter)
.onSuccess { content ->
content?.let {
printLog(debugSource, 1000, it)
}
}
}
} }

@ -5,11 +5,19 @@ import android.view.View
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity import io.legado.app.base.BaseActivity
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource
import io.legado.app.model.WebBook
import io.legado.app.model.webbook.SourceDebug
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.isAbsUrl
import kotlinx.android.synthetic.main.activity_source_debug.* import kotlinx.android.synthetic.main.activity_source_debug.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
class SourceDebugActivity : BaseActivity<AndroidViewModel>() { class SourceDebugActivity : BaseActivity<AndroidViewModel>() {
override val viewModel: AndroidViewModel override val viewModel: AndroidViewModel
@ -18,8 +26,14 @@ class SourceDebugActivity : BaseActivity<AndroidViewModel>() {
get() = R.layout.activity_source_debug get() = R.layout.activity_source_debug
private lateinit var adapter: SourceDebugAdapter private lateinit var adapter: SourceDebugAdapter
private var bookSource: BookSource? = null
override fun onViewModelCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) { override fun onViewModelCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) {
launch(IO) {
intent.getStringExtra("key")?.let {
bookSource = App.db.bookSourceDao().findByKey(it)
}
}
initRecyclerView() initRecyclerView()
initSearchView() initSearchView()
} }
@ -51,7 +65,18 @@ class SourceDebugActivity : BaseActivity<AndroidViewModel>() {
private fun startSearch(key: String) { private fun startSearch(key: String) {
adapter.logList.clear() adapter.logList.clear()
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()
bookSource?.let {
if (key.isAbsUrl()) {
val book = Book()
book.origin = it.bookSourceUrl
book.bookUrl = key
SourceDebug(WebBook(it))
.infoDebug(book)
} else {
SourceDebug(WebBook(it))
.searchDebug(key)
}
}
} }
} }
Loading…
Cancel
Save