From 87523bba2dc96f567115ec8dbf1621968886a019 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 31 Jul 2019 22:55:32 +0800 Subject: [PATCH 1/5] up --- .../java/io/legado/app/model/webbook/SourceDebug.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 919be87a6..7ca534ed9 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 @@ -5,7 +5,6 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.help.BookHelp import io.legado.app.help.coroutine.CompositeCoroutine -import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.WebBook import io.legado.app.utils.htmlFormat import io.legado.app.utils.isAbsUrl @@ -66,11 +65,12 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { } } - fun searchDebug(key: String) { + private fun searchDebug(key: String) { val search = webBook.searchBook(key, 1) .onSuccess { searchBooks -> searchBooks?.let { if (searchBooks.isNotEmpty()) { + callback?.printLog(1, "") infoDebug(BookHelp.toBook(searchBooks[0])) } } @@ -81,9 +81,11 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { tasks.add(search) } - fun infoDebug(book: Book) { + private fun infoDebug(book: Book) { + printLog(debugSource, 1, "开始获取详情页") val info = webBook.getBookInfo(book) .onSuccess { + callback?.printLog(1, "") tocDebug(book) } .onError { @@ -93,10 +95,12 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { } private fun tocDebug(book: Book) { + printLog(debugSource, 1, "开始获取目录页") val chapterList = webBook.getChapterList(book) .onSuccess { chapterList -> chapterList?.let { if (it.isNotEmpty()) { + callback?.printLog(1, "") contentDebug(book, it[0]) } } @@ -108,6 +112,7 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) { } private fun contentDebug(book: Book, bookChapter: BookChapter) { + printLog(debugSource, 1, "开始获取内容") val content = webBook.getContent(book, bookChapter) .onSuccess { content -> content?.let { From 51d537fba355828558cc91a4731998d75bdc1762 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 31 Jul 2019 23:02:41 +0800 Subject: [PATCH 2/5] up --- app/src/main/java/io/legado/app/model/webbook/BookList.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/model/webbook/BookList.kt b/app/src/main/java/io/legado/app/model/webbook/BookList.kt index dbc3c6af8..1fcc447dc 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookList.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookList.kt @@ -48,6 +48,7 @@ object BookList { reverse = true ruleList = ruleList.substring(1) } + SourceDebug.printLog(bookSource.bookSourceUrl, 1, "解析书籍列表") collections = analyzeRule.getElements(ruleList) if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) { SourceDebug.printLog(bookSource.bookSourceUrl, 1, "列表为空,按详情页解析") From 821e56182bfc424bf20b067b9c5dbdeef3040c3e Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 1 Aug 2019 08:23:41 +0800 Subject: [PATCH 3/5] up --- app/build.gradle | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 578212db5..72945b3c7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -83,7 +83,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.1.0-rc01' implementation 'androidx.preference:preference:1.1.0-rc01' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'com.google.android.material:material:1.1.0-alpha08' + implementation 'com.google.android.material:material:1.1.0-alpha09' implementation 'com.google.android:flexbox:1.1.0' //lifecycle @@ -116,8 +116,6 @@ dependencies { implementation 'com.google.code.gson:gson:2.8.5' implementation 'org.jsoup:jsoup:1.12.1' implementation 'cn.wanghaomiao:JsoupXpath:2.3.2' - // implementation 'org.apache.commons:commons-text:1.6' - // Default json parser for jsonpath implementation 'com.jayway.jsonpath:json-path:2.4.0' //JS @@ -137,7 +135,7 @@ dependencies { implementation 'com.jaredrummler:colorpicker:1.1.0' //对话框 - implementation 'com.afollestad.material-dialogs:core:3.0.0-rc3' - implementation 'com.afollestad.material-dialogs:input:3.0.0-rc3' - implementation 'com.afollestad.material-dialogs:files:3.0.0-rc3' + implementation 'com.afollestad.material-dialogs:core:3.1.0' + implementation 'com.afollestad.material-dialogs:input:3.1.0' + implementation 'com.afollestad.material-dialogs:files:3.1.0' } From 50e4f72b8e094bc328257dfad7b2f56f21c8b8d6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 1 Aug 2019 09:22:20 +0800 Subject: [PATCH 4/5] up --- app/build.gradle | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 72945b3c7..7354986a4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -83,6 +83,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.1.0-rc01' implementation 'androidx.preference:preference:1.1.0-rc01' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0' implementation 'com.google.android.material:material:1.1.0-alpha09' implementation 'com.google.android:flexbox:1.1.0' @@ -108,7 +109,7 @@ dependencies { implementation 'com.jeremyliao:live-event-bus-x:1.4.4' //协程 - def coroutines_version = '1.2.1' + def coroutines_version = '1.2.2' implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" @@ -138,4 +139,5 @@ dependencies { implementation 'com.afollestad.material-dialogs:core:3.1.0' implementation 'com.afollestad.material-dialogs:input:3.1.0' implementation 'com.afollestad.material-dialogs:files:3.1.0' + } From 6a65b282f286433b03211c89311682831ee4ec04 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 1 Aug 2019 10:26:00 +0800 Subject: [PATCH 5/5] up --- .../main/java/io/legado/app/constant/Bus.kt | 1 + .../app/ui/sourcedebug/SourceDebugActivity.kt | 19 ++++++++++++------- .../app/ui/sourcedebug/SourceDebugModel.kt | 15 +++------------ 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/Bus.kt b/app/src/main/java/io/legado/app/constant/Bus.kt index 94d41fafb..98acde903 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/Bus.kt @@ -2,4 +2,5 @@ package io.legado.app.constant object Bus { const val RECREATE = "RECREATE" + const val SOURCE_DEBUG_LOG = "sourceDebugLog" } \ 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 eda5f392d..81817b616 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 @@ -3,13 +3,15 @@ package io.legado.app.ui.sourcedebug import android.os.Bundle import android.view.View import androidx.appcompat.widget.SearchView -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.BaseActivity +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.utils.getViewModel +import io.legado.app.utils.observeEvent import kotlinx.android.synthetic.main.activity_source_debug.* import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.toast @@ -27,12 +29,6 @@ class SourceDebugActivity : BaseActivity() { viewModel.init(intent.getStringExtra("key")) initRecyclerView() initSearchView() - viewModel.observeLogs(this){ - adapter.addItem(it.obj as String) - if (it.what == -1 || it.what == 1000) { - rotate_loading.hide() - } - } } private fun initRecyclerView() { @@ -69,4 +65,13 @@ class SourceDebugActivity : BaseActivity() { toast("未获取到书源") }) } + + override fun observeLiveBus() { + observeEvent(Bus.SOURCE_DEBUG_LOG) { + adapter.addItem(it.obj as String) + if (it.what == -1 || it.what == 1000) { + rotate_loading.hide() + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt index 5b7716804..df76cda3b 100644 --- a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt +++ b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt @@ -1,27 +1,18 @@ package io.legado.app.ui.sourcedebug import android.app.Application -import androidx.lifecycle.LifecycleOwner -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.Observer import io.legado.app.App import io.legado.app.base.BaseViewModel +import io.legado.app.constant.Bus import io.legado.app.help.EventMessage import io.legado.app.model.WebBook import io.legado.app.model.webbook.SourceDebug +import io.legado.app.utils.postEvent class SourceDebugModel(application: Application) : BaseViewModel(application), SourceDebug.Callback { - private val logs: MutableLiveData = MutableLiveData() - private var webBook: WebBook? = null - fun observeLogs(owner: LifecycleOwner, observer: (EventMessage) -> Unit) { - logs.observe(owner, Observer { - observer(it) - }) - } - fun init(sourceUrl: String?) { sourceUrl?.let { //优先使用这个,不会抛出异常 @@ -40,7 +31,7 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S } override fun printLog(state: Int, msg: String) { - logs.postValue(EventMessage.obtain(state, msg)) + postEvent(Bus.SOURCE_DEBUG_LOG, EventMessage.obtain(state, msg)) } override fun onCleared() {