Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Jan 6, 2025
1 parent 9bf7db4 commit 30c3a62
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.legado.app.utils.ArchiveUtils
import io.legado.app.utils.FileDoc
import io.legado.app.utils.applyTint
import io.legado.app.utils.hideSoftInput
import io.legado.app.utils.shouldHideSoftInput
import io.legado.app.utils.startActivity
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
Expand Down Expand Up @@ -51,7 +52,7 @@ abstract class BaseImportBookActivity<VM : ViewModel> : VMBaseActivity<ActivityI
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
if (ev.action == MotionEvent.ACTION_DOWN) {
currentFocus?.let {
if (it is EditText) {
if (it.shouldHideSoftInput(ev)) {
it.clearFocus()
it.hideSoftInput()
}
Expand Down
20 changes: 18 additions & 2 deletions app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.net.Uri
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.MotionEvent
import android.widget.CheckBox
import android.widget.LinearLayout
import androidx.activity.result.contract.ActivityResultContracts
Expand Down Expand Up @@ -285,6 +286,17 @@ class BookInfoActivity :
}
}

override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
if (ev.action == MotionEvent.ACTION_DOWN) {
currentFocus?.let {
if (it === binding.tvIntro) {
it.clearFocus()
}
}
}
return super.dispatchTouchEvent(ev)
}

private fun refreshBook() {
upLoading(true)
viewModel.getBook()?.let {
Expand Down Expand Up @@ -485,6 +497,9 @@ class BookInfoActivity :
refreshLayout.isRefreshing = false
refreshBook()
}
refreshLayout?.setOnChildScrollUpCallback { _, _ ->
tvIntro.hasSelection()
}
}

private fun setSourceVariable() {
Expand Down Expand Up @@ -517,8 +532,9 @@ class BookInfoActivity :
}
val book = viewModel.getBook() ?: return@launch
val variable = withContext(IO) { book.getCustomVariable() }
val comment =
source.getDisplayVariableComment("""书籍变量可在js中通过book.getVariable("custom")获取""")
val comment = source.getDisplayVariableComment(
"""书籍变量可在js中通过book.getVariable("custom")获取"""
)
showDialogFragment(
VariableDialog(
getString(R.string.set_book_variable),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import io.legado.app.utils.hideSoftInput
import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.sendToClip
import io.legado.app.utils.setEdgeEffectColor
import io.legado.app.utils.shouldHideSoftInput
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding
Expand Down Expand Up @@ -122,7 +123,7 @@ class BookshelfManageActivity :
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
if (ev.action == MotionEvent.ACTION_DOWN) {
currentFocus?.let {
if (it is EditText) {
if (it.shouldHideSoftInput(ev)) {
it.clearFocus()
it.hideSoftInput()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class SearchContentActivity :
if (ev.action == MotionEvent.ACTION_DOWN) {
currentFocus?.let {
if (it.shouldHideSoftInput(ev)) {
it.clearFocus()
it.hideSoftInput()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import io.legado.app.utils.observeEvent
import io.legado.app.utils.sendToClip
import io.legado.app.utils.setEdgeEffectColor
import io.legado.app.utils.share
import io.legado.app.utils.shouldHideSoftInput
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.showHelp
import io.legado.app.utils.splitNotBlank
Expand Down Expand Up @@ -161,7 +162,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
if (ev.action == MotionEvent.ACTION_DOWN) {
currentFocus?.let {
if (it is EditText) {
if (it.shouldHideSoftInput(ev)) {
it.clearFocus()
it.hideSoftInput()
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.MotionEvent
import android.widget.EditText
import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView
import androidx.fragment.app.Fragment
Expand All @@ -30,6 +29,7 @@ import io.legado.app.ui.widget.dialog.WaitDialog
import io.legado.app.utils.applyTint
import io.legado.app.utils.gone
import io.legado.app.utils.hideSoftInput
import io.legado.app.utils.shouldHideSoftInput
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
Expand Down Expand Up @@ -74,7 +74,7 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>(),
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
if (ev.action == MotionEvent.ACTION_DOWN) {
currentFocus?.let {
if (it is EditText) {
if (it.shouldHideSoftInput(ev)) {
it.hideSoftInput()
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/io/legado/app/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.text.format.DateUtils
import android.view.MenuItem
import android.view.MotionEvent
import android.view.ViewGroup
import android.widget.EditText
import androidx.activity.addCallback
import androidx.activity.viewModels
import androidx.core.view.ViewCompat
Expand Down Expand Up @@ -49,6 +48,7 @@ import io.legado.app.utils.isCreated
import io.legado.app.utils.navigationBarHeight
import io.legado.app.utils.observeEvent
import io.legado.app.utils.setEdgeEffectColor
import io.legado.app.utils.shouldHideSoftInput
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
Expand Down Expand Up @@ -119,7 +119,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
if (ev.action == MotionEvent.ACTION_DOWN) {
currentFocus?.let {
if (it is EditText) {
if (it.shouldHideSoftInput(ev)) {
it.clearFocus()
it.hideSoftInput()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import io.legado.app.utils.launch
import io.legado.app.utils.readText
import io.legado.app.utils.sendToClip
import io.legado.app.utils.setEdgeEffectColor
import io.legado.app.utils.shouldHideSoftInput
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.showHelp
import io.legado.app.utils.splitNotBlank
Expand Down Expand Up @@ -129,7 +130,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
if (ev.action == MotionEvent.ACTION_DOWN) {
currentFocus?.let {
if (it is EditText) {
if (it.shouldHideSoftInput(ev)) {
it.clearFocus()
it.hideSoftInput()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import io.legado.app.utils.readText
import io.legado.app.utils.sendToClip
import io.legado.app.utils.setEdgeEffectColor
import io.legado.app.utils.share
import io.legado.app.utils.shouldHideSoftInput
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.showHelp
import io.legado.app.utils.splitNotBlank
Expand Down Expand Up @@ -120,7 +121,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
if (ev.action == MotionEvent.ACTION_DOWN) {
currentFocus?.let {
if (it is EditText) {
if (it.shouldHideSoftInput(ev)) {
it.clearFocus()
it.hideSoftInput()
}
Expand Down

0 comments on commit 30c3a62

Please sign in to comment.