diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 74ec65055..62342bb9c 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -143,7 +143,7 @@ object Restore { ) source.ruleBookInfo = GSON.toJson(bookInfoRule) val chapterRule = TocRule( - chapterList = jsonItem.readString("ruleChapterUrlNext"), + chapterList = jsonItem.readString("ruleChapterList"), chapterName = jsonItem.readString("ruleChapterName"), chapterUrl = jsonItem.readString("ruleContentUrl"), nextTocUrl = jsonItem.readString("ruleChapterUrlNext") diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 4c3545135..fead18fe8 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -195,7 +195,7 @@ class AnalyzeRule(private var book: BaseBook? = null) { Mode.Js -> result = evalJS(rule.rule, it) Mode.Json -> result = getAnalyzeByJSonPath(it).getString(rule.rule) Mode.XPath -> result = getAnalyzeByXPath(it).getString(rule.rule) - Mode.Default -> result = if (isUrl && !TextUtils.isEmpty(baseUrl)) { + Mode.Default -> result = if (isUrl) { getAnalyzeByJSoup(it).getString0(rule.rule) } else { getAnalyzeByJSoup(it).getString(rule.rule) diff --git a/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt index 3bd4be757..6719aff4c 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt @@ -23,7 +23,7 @@ object BookChapterList { bookSource: BookSource, analyzeUrl: AnalyzeUrl ): List { - val chapterList = arrayListOf() + var chapterList = arrayListOf() val baseUrl: String = NetworkUtils.getUrl(response) val body: String? = response.body() body ?: throw Exception( @@ -58,7 +58,6 @@ object BookChapterList { } } } - if (reverse) chapterList.reverse() } else if (chapterData.nextUrl.size > 1) { val chapterDataList = arrayListOf>() for (item in chapterData.nextUrl) { @@ -85,8 +84,14 @@ object BookChapterList { chapterList.addAll(it) } } - if (reverse) chapterList.reverse() } + //去重 + if (!reverse) { + chapterList.reverse() + } + val lh = LinkedHashSet(chapterList) + chapterList = ArrayList(lh) + chapterList.reverse() return chapterList } @@ -116,8 +121,11 @@ object BookChapterList { } SourceDebug.printLog(bookSource.bookSourceUrl, 1, TextUtils.join(",", nextUrlList), printLog) } + SourceDebug.printLog(bookSource.bookSourceUrl, 1, "解析目录列表", printLog) val elements = analyzeRule.getElements(listRule) + SourceDebug.printLog(bookSource.bookSourceUrl, 1, "目录数${elements.size}", printLog) if (elements.isNotEmpty()) { + SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取目录", printLog) val nameRule = analyzeRule.splitSourceRule(tocRule.chapterName ?: "") val urlRule = analyzeRule.splitSourceRule(tocRule.chapterUrl ?: "") for (item in elements) { @@ -131,6 +139,7 @@ object BookChapterList { chapterList.add(bookChapter) } } + SourceDebug.printLog(bookSource.bookSourceUrl, 1, "${chapterList[0].title}${chapterList[0].url}", printLog) } return ChapterData(chapterList, nextUrlList) } diff --git a/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt b/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt index 988a1fa59..f678e5ed2 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt @@ -26,7 +26,7 @@ object BookInfo { SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:$baseUrl") val infoRule = bookSource.getBookInfoRule() val analyzeRule = AnalyzeRule(book) - analyzeRule.setContent(body) + analyzeRule.setContent(body, baseUrl) infoRule.init?.let { if (it.isNotEmpty()) { SourceDebug.printLog(bookSource.bookSourceUrl, 1, "执行详情页初始化规则") diff --git a/app/src/main/java/io/legado/app/model/webbook/SourceDebug.kt b/app/src/main/java/io/legado/app/model/webbook/SourceDebug.kt index 7ca534ed9..a7cd9c5e7 100644 --- a/app/src/main/java/io/legado/app/model/webbook/SourceDebug.kt +++ b/app/src/main/java/io/legado/app/model/webbook/SourceDebug.kt @@ -20,16 +20,25 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { @SuppressLint("ConstantLocale") private val DEBUG_TIME_FORMAT = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault()) - private val startTime: Long = System.currentTimeMillis() - - fun printLog(sourceUrl: String?, state: Int, msg: String, print: Boolean = true, isHtml: Boolean = false) { + private var startTime: Long = System.currentTimeMillis() + + @Synchronized + fun printLog( + sourceUrl: String?, + state: Int, + msg: String, + print: Boolean = true, + isHtml: Boolean = false, + showTime: Boolean = true + ) { if (debugSource != sourceUrl || callback == null || !print) return var printMsg = msg if (isHtml) { printMsg = printMsg.htmlFormat() } - printMsg = - String.format("%s %s", DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - startTime)), printMsg) + if (showTime) { + printMsg = "${DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - startTime))} $printMsg" + } callback?.printLog(state, printMsg) } @@ -51,6 +60,7 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { fun startDebug(key: String) { cancelDebug() + startTime = System.currentTimeMillis() with(webBook) { if (key.isAbsUrl()) { val book = Book() @@ -70,8 +80,11 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { .onSuccess { searchBooks -> searchBooks?.let { if (searchBooks.isNotEmpty()) { - callback?.printLog(1, "") + printLog(debugSource, 1, "搜索完成") + printLog(debugSource, 1, "", showTime = false) infoDebug(BookHelp.toBook(searchBooks[0])) + } else { + printLog(debugSource, -1, "未获取到书籍") } } } @@ -85,7 +98,8 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { printLog(debugSource, 1, "开始获取详情页") val info = webBook.getBookInfo(book) .onSuccess { - callback?.printLog(1, "") + printLog(debugSource, 1, "详情页完成") + printLog(debugSource, 1, "", showTime = false) tocDebug(book) } .onError { @@ -100,8 +114,11 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { .onSuccess { chapterList -> chapterList?.let { if (it.isNotEmpty()) { - callback?.printLog(1, "") + printLog(debugSource, 1, "目录完成") + printLog(debugSource, 1, "", showTime = false) contentDebug(book, it[0]) + } else { + printLog(debugSource, -1, "目录列表为空") } } } @@ -129,14 +146,4 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { fun printLog(state: Int, msg: String) } - fun printLog( - sourceUrl: String?, - state: Int, - msg: String, - print: Boolean = true, - isHtml: Boolean = false - ): SourceDebug { - SourceDebug.printLog(sourceUrl, state, msg, print, isHtml) - return this - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt index 66ff91a1d..4be37daca 100644 --- a/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.booksource +import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -27,6 +28,7 @@ import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch import org.jetbrains.anko.startActivity +import org.jetbrains.anko.startActivityForResult class BookSourceActivity : VMBaseActivity(R.layout.activity_book_source), BookSourceAdapter.CallBack, @@ -36,6 +38,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity_ private lateinit var adapter: BookSourceAdapter private var bookSourceLiveDate: LiveData>? = null + private val qrRequestCode = 101 override fun onActivityCreated(savedInstanceState: Bundle?) { setSupportActionBar(toolbar) @@ -55,7 +58,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity_ this.startActivity() } R.id.action_import_book_source_qr -> { - this.startActivity() + this.startActivityForResult(qrRequestCode) } R.id.action_select_all -> { launch(IO) { @@ -135,4 +138,17 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity_ override fun edit(bookSource: BookSource) { startActivity(Pair("data", bookSource.bookSourceUrl)) } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + qrRequestCode -> { + if (resultCode == RESULT_OK) { + data?.getStringExtra("result")?.let { + + } + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt index a70924bed..1e0cd7fef 100644 --- a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt @@ -1,20 +1,22 @@ package io.legado.app.ui.sourcedebug +import android.content.Intent import android.os.Bundle +import android.view.Menu +import android.view.MenuItem import android.view.View import androidx.appcompat.widget.SearchView import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.VMBaseActivity -import io.legado.app.constant.Bus -import io.legado.app.help.EventMessage import io.legado.app.lib.theme.ATH -import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.accentColor +import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.utils.getViewModel -import io.legado.app.utils.observeEvent +import io.legado.app.utils.hideSoftInput import kotlinx.android.synthetic.main.activity_source_debug.* import kotlinx.android.synthetic.main.view_title_bar.* +import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast class SourceDebugActivity : VMBaseActivity(R.layout.activity_source_debug) { @@ -23,17 +25,12 @@ class SourceDebugActivity : VMBaseActivity(R.layout.activity_s get() = getViewModel(SourceDebugModel::class.java) private lateinit var adapter: SourceDebugAdapter + private val qrRequestCode = 101 override fun onActivityCreated(savedInstanceState: Bundle?) { viewModel.init(intent.getStringExtra("key")) initRecyclerView() initSearchView() - viewModel.observe{state, msg-> - adapter.addItem(msg) - if (state == -1 || state == 1000) { - rotate_loading.hide() - } - } } private fun initRecyclerView() { @@ -52,6 +49,7 @@ class SourceDebugActivity : VMBaseActivity(R.layout.activity_s search_view.clearFocus() search_view.setOnQueryTextListener(object : SearchView.OnQueryTextListener { override fun onQueryTextSubmit(query: String?): Boolean { + search_view.hideSoftInput() startSearch(query ?: "我的") return true } @@ -70,4 +68,31 @@ class SourceDebugActivity : VMBaseActivity(R.layout.activity_s toast("未获取到书源") }) } + + override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.source_debug, menu) + return super.onCompatCreateOptionsMenu(menu) + } + + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.action_scan -> { + startActivityForResult(qrRequestCode) + } + } + return super.onCompatOptionsItemSelected(item) + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + qrRequestCode -> { + if (resultCode == RESULT_OK) { + data?.getStringExtra("result")?.let { + startSearch(it) + } + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/res/menu/source_debug.xml b/app/src/main/res/menu/source_debug.xml new file mode 100644 index 000000000..5b8b467f2 --- /dev/null +++ b/app/src/main/res/menu/source_debug.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file