This commit is contained in:
Horis
2025-04-30 12:38:19 +08:00
parent 14dd24945b
commit 5d981808bf
4 changed files with 41 additions and 30 deletions

View File

@@ -18,7 +18,6 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.PopupMenu
import androidx.core.view.get
import androidx.core.view.isVisible
import androidx.core.view.size
import androidx.lifecycle.lifecycleScope
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
@@ -106,6 +105,7 @@ import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.StartActivityContract
import io.legado.app.utils.applyOpenTint
import io.legado.app.utils.buildMainHandler
import io.legado.app.utils.dismissDialogFragment
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefString
import io.legado.app.utils.hexString
@@ -175,23 +175,22 @@ class ReadBookActivity : BaseReadBookActivity(),
}
}
private val searchContentActivity =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
it.data?.let { data ->
val key = data.getLongExtra("key", System.currentTimeMillis())
val index = data.getIntExtra("index", 0)
val searchResult = IntentData.get<SearchResult>("searchResult$key")
val searchResultList = IntentData.get<List<SearchResult>>("searchResultList$key")
if (searchResult != null && searchResultList != null) {
viewModel.searchContentQuery = searchResult.query
binding.searchMenu.upSearchResultList(searchResultList)
isShowingSearchResult = true
viewModel.searchResultIndex = index
binding.searchMenu.updateSearchResultIndex(index)
binding.searchMenu.selectedSearchResult?.let { currentResult ->
ReadBook.saveCurrentBookProgress() //退出全文搜索恢复此时进度
skipToSearch(currentResult)
showActionMenu()
}
registerForActivityResult(StartActivityContract(SearchContentActivity::class.java)) {
val data = it.data ?: return@registerForActivityResult
val key = data.getLongExtra("key", System.currentTimeMillis())
val index = data.getIntExtra("index", 0)
val searchResult = IntentData.get<SearchResult>("searchResult$key")
val searchResultList = IntentData.get<List<SearchResult>>("searchResultList$key")
if (searchResult != null && searchResultList != null) {
viewModel.searchContentQuery = searchResult.query
binding.searchMenu.upSearchResultList(searchResultList)
isShowingSearchResult = true
viewModel.searchResultIndex = index
binding.searchMenu.updateSearchResultIndex(index)
binding.searchMenu.selectedSearchResult?.let { currentResult ->
ReadBook.saveCurrentBookProgress() //退出全文搜索恢复此时进度
skipToSearch(currentResult)
showActionMenu()
}
}
}
@@ -1138,6 +1137,7 @@ class ReadBookActivity : BaseReadBookActivity(),
if (isAutoPage) {
binding.readView.autoPager.stop()
binding.readMenu.setAutoPage(false)
dismissDialogFragment<AutoReadDialog>()
upScreenTimeOut()
}
}
@@ -1179,17 +1179,16 @@ class ReadBookActivity : BaseReadBookActivity(),
* 打开搜索界面
*/
override fun openSearchActivity(searchWord: String?) {
ReadBook.book?.let {
searchContentActivity.launch(Intent(this, SearchContentActivity::class.java).apply {
putExtra("bookUrl", it.bookUrl)
putExtra("searchWord", searchWord ?: viewModel.searchContentQuery)
putExtra("searchResultIndex", viewModel.searchResultIndex)
viewModel.searchResultList?.first()?.let {
if (it.query == viewModel.searchContentQuery) {
IntentData.put("searchResultList", viewModel.searchResultList)
}
val book = ReadBook.book ?: return
searchContentActivity.launch {
putExtra("bookUrl", book.bookUrl)
putExtra("searchWord", searchWord ?: viewModel.searchContentQuery)
putExtra("searchResultIndex", viewModel.searchResultIndex)
viewModel.searchResultList?.first()?.let {
if (it.query == viewModel.searchContentQuery) {
IntentData.put("searchResultList", viewModel.searchResultList)
}
})
}
}
}

View File

@@ -17,6 +17,7 @@ import io.legado.app.utils.canvasrecorder.recordIfNeeded
class AutoPager(private val readView: ReadView) {
private var progress = 0
var isRunning = false
private set
private var isPausing = false
private var scrollOffsetRemain = 0.0
private var scrollOffset = 0
@@ -102,7 +103,7 @@ class AutoPager(private val readView: ReadView) {
}
fun computeOffset() {
if (!isRunning) {
if (!isRunning || isPausing) {
return
}

View File

@@ -33,6 +33,7 @@ class ConfigViewModel(application: Application) : BaseViewModel(application) {
fun clearWebViewData() {
execute {
FileUtils.delete(context.getDir("webview", Context.MODE_PRIVATE))
FileUtils.delete(context.getDir("hws_webview", Context.MODE_PRIVATE), true)
context.toastOnUi(R.string.clear_webview_data_success)
delay(3000)
appCtx.restart()

View File

@@ -34,6 +34,14 @@ inline fun <reified T : DialogFragment> AppCompatActivity.showDialogFragment(
dialog.show(supportFragmentManager, T::class.simpleName)
}
inline fun <reified T : DialogFragment> AppCompatActivity.dismissDialogFragment() {
supportFragmentManager.fragments.forEach {
if (it is T) {
it.dismissAllowingStateLoss()
}
}
}
fun AppCompatActivity.showDialogFragment(dialogFragment: DialogFragment) {
dialogFragment.show(supportFragmentManager, dialogFragment::class.simpleName)
}
@@ -44,7 +52,9 @@ val WindowManager.windowSize: DisplayMetrics
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowMetrics: WindowMetrics = currentWindowMetrics
val insets = windowMetrics.windowInsets
.getInsetsIgnoringVisibility(WindowInsets.Type.systemBars() or WindowInsets.Type.displayCutout())
.getInsetsIgnoringVisibility(
WindowInsets.Type.systemBars() or WindowInsets.Type.displayCutout()
)
val windowWidth = windowMetrics.bounds.width()
val windowHeight = windowMetrics.bounds.height()
var insetsWidth = insets.left + insets.right