优化调试界面

pull/1282/head
gedoor 3 years ago
parent ea3259be2e
commit eff260f7e1
  1. 3
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  2. 49
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt
  4. 165
      app/src/main/res/layout/activity_source_debug.xml

@ -69,8 +69,7 @@ class AnalyzeRule(val ruleData: RuleDataInterface, private val source: BaseSourc
fun setRedirectUrl(url: String): URL? { fun setRedirectUrl(url: String): URL? {
kotlin.runCatching { kotlin.runCatching {
val urlMatcher = AnalyzeUrl.paramPattern.matcher(url) redirectUrl = URL(url)
redirectUrl = URL(if (urlMatcher.find()) url.substring(0, urlMatcher.start()) else url)
} }
return redirectUrl return redirectUrl
} }

@ -1,14 +1,15 @@
package io.legado.app.ui.book.source.debug package io.legado.app.ui.book.source.debug
import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivitySourceDebugBinding import io.legado.app.databinding.ActivitySourceDebugBinding
import io.legado.app.help.LocalConfig
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.qrcode.QrCodeResult import io.legado.app.ui.qrcode.QrCodeResult
@ -16,6 +17,7 @@ import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import splitties.views.onClick
class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookSourceDebugModel>() { class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookSourceDebugModel>() {
@ -32,9 +34,11 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
searchView = binding.titleBar.findViewById(R.id.search_view) searchView = binding.titleBar.findViewById(R.id.search_view)
viewModel.init(intent.getStringExtra("key"))
initRecyclerView() initRecyclerView()
initSearchView() initSearchView()
viewModel.init(intent.getStringExtra("key")) {
initHelpView()
}
viewModel.observe { state, msg -> viewModel.observe { state, msg ->
launch { launch {
adapter.addItem(msg) adapter.addItem(msg)
@ -45,13 +49,6 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
} }
} }
override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
if (!LocalConfig.debugHelpVersionIsLast) {
showHelp()
}
}
private fun initRecyclerView() { private fun initRecyclerView() {
ATH.applyEdgeEffectColor(binding.recyclerView) ATH.applyEdgeEffectColor(binding.recyclerView)
adapter = BookSourceDebugAdapter(this) adapter = BookSourceDebugAdapter(this)
@ -63,10 +60,10 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
searchView.onActionViewExpanded() searchView.onActionViewExpanded()
searchView.isSubmitButtonEnabled = true searchView.isSubmitButtonEnabled = true
searchView.queryHint = getString(R.string.search_book_key) searchView.queryHint = getString(R.string.search_book_key)
searchView.clearFocus()
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean { override fun onQueryTextSubmit(query: String?): Boolean {
searchView.clearFocus() searchView.clearFocus()
openOrCloseHelp(false)
startSearch(query ?: "我的") startSearch(query ?: "我的")
return true return true
} }
@ -75,6 +72,38 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
return false return false
} }
}) })
searchView.setOnQueryTextFocusChangeListener { _, hasFocus ->
openOrCloseHelp(hasFocus)
}
}
@SuppressLint("SetTextI18n")
private fun initHelpView() {
viewModel.bookSource?.exploreKinds?.firstOrNull {
!it.url.isNullOrBlank()
}?.let {
binding.textFx.text = "${it.title}::${it.url}"
}
binding.textMy.onClick {
searchView.setQuery(binding.textMy.text, true)
}
binding.textXt.onClick {
searchView.setQuery(binding.textXt.text, true)
}
binding.textFx.onClick {
searchView.setQuery(binding.textFx.text, true)
}
}
/**
* 打开关闭历史界面
*/
private fun openOrCloseHelp(open: Boolean) {
if (open) {
binding.help.visibility = View.VISIBLE
} else {
binding.help.visibility = View.GONE
}
} }
private fun startSearch(key: String) { private fun startSearch(key: String) {

@ -9,18 +9,20 @@ import io.legado.app.model.Debug
class BookSourceDebugModel(application: Application) : BaseViewModel(application), class BookSourceDebugModel(application: Application) : BaseViewModel(application),
Debug.Callback { Debug.Callback {
private var bookSource: BookSource? = null var bookSource: BookSource? = null
private var callback: ((Int, String) -> Unit)? = null private var callback: ((Int, String) -> Unit)? = null
var searchSrc: String? = null var searchSrc: String? = null
var bookSrc: String? = null var bookSrc: String? = null
var tocSrc: String? = null var tocSrc: String? = null
var contentSrc: String? = null var contentSrc: String? = null
fun init(sourceUrl: String?) { fun init(sourceUrl: String?, finally: () -> Unit) {
sourceUrl?.let { sourceUrl?.let {
//优先使用这个,不会抛出异常 //优先使用这个,不会抛出异常
execute { execute {
bookSource = appDb.bookSourceDao.getBookSource(sourceUrl) bookSource = appDb.bookSourceDao.getBookSource(sourceUrl)
}.onFinally {
finally.invoke()
} }
} }
} }

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ll_content" android:id="@+id/ll_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -34,4 +35,168 @@
app:layout_constraintTop_toBottomOf="@+id/title_bar" app:layout_constraintTop_toBottomOf="@+id/title_bar"
app:loading_width="2dp" /> app:loading_width="2dp" />
<androidx.core.widget.NestedScrollView
android:id="@+id/help"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/title_bar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:background="@color/background"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/secondaryText"
android:text="调试搜索>>输入关键字,如:"
tools:ignore="HardcodedText" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/text_my"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="@drawable/selector_fillet_btn_bg"
android:ellipsize="end"
android:gravity="center"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:maxLines="1"
android:textColor="@color/primaryText"
android:textSize="14sp"
android:text="我的"
tools:ignore="HardcodedText,UnusedAttribute" />
<TextView
android:id="@+id/text_xt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="@drawable/selector_fillet_btn_bg"
android:ellipsize="end"
android:gravity="center"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:maxLines="1"
android:textColor="@color/primaryText"
android:textSize="14sp"
android:text="系统"
tools:ignore="HardcodedText,UnusedAttribute" />
</LinearLayout>
<TextView
android:id="@+id/text_fx_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/secondaryText"
android:text="调试发现>>输入发现URL,如:"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/text_fx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="@drawable/selector_fillet_btn_bg"
android:ellipsize="end"
android:gravity="center"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:maxLines="1"
android:textColor="@color/primaryText"
android:textSize="14sp"
android:text="系统::http://xxx"
tools:ignore="HardcodedText,UnusedAttribute" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/secondaryText"
android:text="调试详情页>>输入详情页URL,如:"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="@drawable/selector_fillet_btn_bg"
android:ellipsize="end"
android:gravity="center"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:maxLines="1"
android:textColor="@color/primaryText"
android:textSize="14sp"
android:text="https://m.qidian.com/book/1015609210"
tools:ignore="HardcodedText,UnusedAttribute" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/secondaryText"
android:text="调试目录页>>输入目录页URL,如:"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="@drawable/selector_fillet_btn_bg"
android:ellipsize="end"
android:gravity="center"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:maxLines="1"
android:textColor="@color/primaryText"
android:textSize="14sp"
android:text="++https://www.zhaishuyuan.com/read/30394"
tools:ignore="HardcodedText,UnusedAttribute" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/secondaryText"
android:text="调试详情页>>输入详情页URL,如:"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="@drawable/selector_fillet_btn_bg"
android:ellipsize="end"
android:gravity="center"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:maxLines="1"
android:textColor="@color/primaryText"
android:textSize="14sp"
android:text="--https://www.zhaishuyuan.com/chapter/30394/20940996"
tools:ignore="HardcodedText,UnusedAttribute" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save