This commit is contained in:
Horis
2025-04-30 12:38:19 +08:00
parent 5e76523c8d
commit bd7cbbb9f0
4 changed files with 41 additions and 30 deletions
@@ -18,7 +18,6 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.core.view.get import androidx.core.view.get
import androidx.core.view.isVisible
import androidx.core.view.size import androidx.core.view.size
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener 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.StartActivityContract
import io.legado.app.utils.applyOpenTint import io.legado.app.utils.applyOpenTint
import io.legado.app.utils.buildMainHandler import io.legado.app.utils.buildMainHandler
import io.legado.app.utils.dismissDialogFragment
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import io.legado.app.utils.hexString import io.legado.app.utils.hexString
@@ -175,23 +175,22 @@ class ReadBookActivity : BaseReadBookActivity(),
} }
} }
private val searchContentActivity = private val searchContentActivity =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { registerForActivityResult(StartActivityContract(SearchContentActivity::class.java)) {
it.data?.let { data -> val data = it.data ?: return@registerForActivityResult
val key = data.getLongExtra("key", System.currentTimeMillis()) val key = data.getLongExtra("key", System.currentTimeMillis())
val index = data.getIntExtra("index", 0) val index = data.getIntExtra("index", 0)
val searchResult = IntentData.get<SearchResult>("searchResult$key") val searchResult = IntentData.get<SearchResult>("searchResult$key")
val searchResultList = IntentData.get<List<SearchResult>>("searchResultList$key") val searchResultList = IntentData.get<List<SearchResult>>("searchResultList$key")
if (searchResult != null && searchResultList != null) { if (searchResult != null && searchResultList != null) {
viewModel.searchContentQuery = searchResult.query viewModel.searchContentQuery = searchResult.query
binding.searchMenu.upSearchResultList(searchResultList) binding.searchMenu.upSearchResultList(searchResultList)
isShowingSearchResult = true isShowingSearchResult = true
viewModel.searchResultIndex = index viewModel.searchResultIndex = index
binding.searchMenu.updateSearchResultIndex(index) binding.searchMenu.updateSearchResultIndex(index)
binding.searchMenu.selectedSearchResult?.let { currentResult -> binding.searchMenu.selectedSearchResult?.let { currentResult ->
ReadBook.saveCurrentBookProgress() //退出全文搜索恢复此时进度 ReadBook.saveCurrentBookProgress() //退出全文搜索恢复此时进度
skipToSearch(currentResult) skipToSearch(currentResult)
showActionMenu() showActionMenu()
}
} }
} }
} }
@@ -1138,6 +1137,7 @@ class ReadBookActivity : BaseReadBookActivity(),
if (isAutoPage) { if (isAutoPage) {
binding.readView.autoPager.stop() binding.readView.autoPager.stop()
binding.readMenu.setAutoPage(false) binding.readMenu.setAutoPage(false)
dismissDialogFragment<AutoReadDialog>()
upScreenTimeOut() upScreenTimeOut()
} }
} }
@@ -1179,17 +1179,16 @@ class ReadBookActivity : BaseReadBookActivity(),
* 打开搜索界面 * 打开搜索界面
*/ */
override fun openSearchActivity(searchWord: String?) { override fun openSearchActivity(searchWord: String?) {
ReadBook.book?.let { val book = ReadBook.book ?: return
searchContentActivity.launch(Intent(this, SearchContentActivity::class.java).apply { searchContentActivity.launch {
putExtra("bookUrl", it.bookUrl) putExtra("bookUrl", book.bookUrl)
putExtra("searchWord", searchWord ?: viewModel.searchContentQuery) putExtra("searchWord", searchWord ?: viewModel.searchContentQuery)
putExtra("searchResultIndex", viewModel.searchResultIndex) putExtra("searchResultIndex", viewModel.searchResultIndex)
viewModel.searchResultList?.first()?.let { viewModel.searchResultList?.first()?.let {
if (it.query == viewModel.searchContentQuery) { if (it.query == viewModel.searchContentQuery) {
IntentData.put("searchResultList", viewModel.searchResultList) IntentData.put("searchResultList", viewModel.searchResultList)
}
} }
}) }
} }
} }
@@ -17,6 +17,7 @@ import io.legado.app.utils.canvasrecorder.recordIfNeeded
class AutoPager(private val readView: ReadView) { class AutoPager(private val readView: ReadView) {
private var progress = 0 private var progress = 0
var isRunning = false var isRunning = false
private set
private var isPausing = false private var isPausing = false
private var scrollOffsetRemain = 0.0 private var scrollOffsetRemain = 0.0
private var scrollOffset = 0 private var scrollOffset = 0
@@ -102,7 +103,7 @@ class AutoPager(private val readView: ReadView) {
} }
fun computeOffset() { fun computeOffset() {
if (!isRunning) { if (!isRunning || isPausing) {
return return
} }
@@ -33,6 +33,7 @@ class ConfigViewModel(application: Application) : BaseViewModel(application) {
fun clearWebViewData() { fun clearWebViewData() {
execute { execute {
FileUtils.delete(context.getDir("webview", Context.MODE_PRIVATE)) 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) context.toastOnUi(R.string.clear_webview_data_success)
delay(3000) delay(3000)
appCtx.restart() appCtx.restart()
@@ -34,6 +34,14 @@ inline fun <reified T : DialogFragment> AppCompatActivity.showDialogFragment(
dialog.show(supportFragmentManager, T::class.simpleName) 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) { fun AppCompatActivity.showDialogFragment(dialogFragment: DialogFragment) {
dialogFragment.show(supportFragmentManager, dialogFragment::class.simpleName) dialogFragment.show(supportFragmentManager, dialogFragment::class.simpleName)
} }
@@ -44,7 +52,9 @@ val WindowManager.windowSize: DisplayMetrics
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowMetrics: WindowMetrics = currentWindowMetrics val windowMetrics: WindowMetrics = currentWindowMetrics
val insets = windowMetrics.windowInsets 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 windowWidth = windowMetrics.bounds.width()
val windowHeight = windowMetrics.bounds.height() val windowHeight = windowMetrics.bounds.height()
var insetsWidth = insets.left + insets.right var insetsWidth = insets.left + insets.right