减小动画卡顿概率(但是能力有限呜呜呜)
This commit is contained in:
@@ -492,7 +492,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
*/
|
||||
val durPageIndex: Int
|
||||
get() {
|
||||
return curTextChapter?.getPageIndexByCharIndex(durChapterPos) ?: durChapterPos
|
||||
return curTextChapter?.getPageIndexByCharIndex(durChapterPos) ?: 0
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,7 @@ import android.widget.LinearLayout
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.doOnPreDraw
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.transition.platform.MaterialContainerTransform
|
||||
import io.legato.kazusa.R
|
||||
@@ -153,21 +154,19 @@ class BookInfoActivity :
|
||||
|
||||
@SuppressLint("PrivateResource")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
window.sharedElementEnterTransition = MaterialContainerTransform().apply {
|
||||
postponeEnterTransition()
|
||||
val transform = MaterialContainerTransform().apply {
|
||||
addTarget(binding.ivCover)
|
||||
duration = 500
|
||||
scrimColor = Color.TRANSPARENT
|
||||
fadeMode = MaterialContainerTransform.FADE_MODE_THROUGH
|
||||
}
|
||||
window.sharedElementReturnTransition = MaterialContainerTransform().apply {
|
||||
addTarget(binding.ivCover)
|
||||
duration = 500
|
||||
scrimColor = Color.TRANSPARENT
|
||||
fadeMode = MaterialContainerTransform.FADE_MODE_THROUGH
|
||||
}
|
||||
window.sharedElementEnterTransition = transform
|
||||
window.sharedElementReturnTransition = transform
|
||||
window.sharedElementsUseOverlay = false
|
||||
super.onCreate(savedInstanceState)
|
||||
binding.ivCover.transitionName = intent.getStringExtra("transitionName")
|
||||
binding.ivCover.doOnPreDraw {
|
||||
startPostponedEnterTransition()
|
||||
}
|
||||
setSupportActionBar(binding.topBar)
|
||||
binding.llRead?.applyNavigationBarMargin()
|
||||
binding.btnShelf.text = getString(R.string.remove_from_bookshelf)
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.view.WindowInsets
|
||||
import android.view.WindowManager
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.doOnDetach
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import io.legato.kazusa.R
|
||||
@@ -84,14 +85,15 @@ abstract class BaseReadBookActivity :
|
||||
setOrientation()
|
||||
upLayoutInDisplayCutoutMode()
|
||||
super.onCreate(savedInstanceState)
|
||||
binding.navigationBar.setOnApplyWindowInsetsListenerCompat { view, windowInsets ->
|
||||
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
view.updateLayoutParams {
|
||||
height = insets.bottom
|
||||
binding.navigationBar.doOnDetach {
|
||||
binding.navigationBar.setOnApplyWindowInsetsListenerCompat { view, windowInsets ->
|
||||
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
view.updateLayoutParams {
|
||||
height = insets.bottom
|
||||
}
|
||||
windowInsets
|
||||
}
|
||||
windowInsets
|
||||
}
|
||||
|
||||
viewModel.permissionDenialLiveData.observe(this) {
|
||||
selectBookFolderResult.launch {
|
||||
mode = HandleFileContract.DIR_SYS
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Looper
|
||||
import android.view.Gravity
|
||||
import android.view.HapticFeedbackConstants
|
||||
import android.view.InputDevice
|
||||
@@ -20,10 +19,12 @@ import androidx.activity.addCallback
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.core.view.doOnPreDraw
|
||||
import androidx.core.view.get
|
||||
import androidx.core.view.size
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.transition.platform.MaterialContainerTransform
|
||||
import com.google.android.material.transition.platform.MaterialSharedAxis
|
||||
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
|
||||
import io.legato.kazusa.BuildConfig
|
||||
import io.legato.kazusa.R
|
||||
@@ -130,6 +131,7 @@ import io.legato.kazusa.utils.sysScreenOffTime
|
||||
import io.legato.kazusa.utils.throttle
|
||||
import io.legato.kazusa.utils.toastOnUi
|
||||
import io.legato.kazusa.utils.visible
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.Dispatchers.Main
|
||||
import kotlinx.coroutines.Job
|
||||
@@ -261,64 +263,69 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
window.sharedElementEnterTransition = MaterialContainerTransform().apply {
|
||||
postponeEnterTransition()
|
||||
val transform = MaterialContainerTransform().apply {
|
||||
addTarget(binding.rootView)
|
||||
duration = 700
|
||||
scrimColor = Color.TRANSPARENT
|
||||
fadeMode = MaterialContainerTransform.FADE_MODE_THROUGH
|
||||
}
|
||||
window.sharedElementReturnTransition = MaterialContainerTransform().apply {
|
||||
addTarget(binding.rootView)
|
||||
duration = 700
|
||||
scrimColor = Color.TRANSPARENT
|
||||
fadeMode = MaterialContainerTransform.FADE_MODE_THROUGH
|
||||
duration = 500
|
||||
}
|
||||
window.sharedElementEnterTransition = transform
|
||||
window.sharedElementReturnTransition =
|
||||
MaterialSharedAxis(MaterialSharedAxis.X, true).apply { duration = 300 }
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding.rootView.transitionName = intent.getStringExtra("transitionName")
|
||||
//binding.cursorLeft.setColorFilter(accentColor)
|
||||
//binding.cursorRight.setColorFilter(accentColor)
|
||||
binding.cursorLeft.setOnTouchListener(this)
|
||||
binding.cursorRight.setOnTouchListener(this)
|
||||
//window.setBackgroundDrawable(null)
|
||||
upScreenTimeOut()
|
||||
ReadBook.register(this)
|
||||
|
||||
binding.rootView.doOnPreDraw { startPostponedEnterTransition() }
|
||||
|
||||
lifecycleScope.launch(Dispatchers.Default) {
|
||||
viewModel.initReadBookConfig(intent)
|
||||
viewModel.initData(intent)
|
||||
|
||||
withContext(Main) {
|
||||
binding.readView.initAfterTransition()
|
||||
justInitData = true
|
||||
}
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this) {
|
||||
if (isShowingSearchResult) {
|
||||
exitSearchMenu()
|
||||
restoreLastBookProcess()
|
||||
return@addCallback
|
||||
when {
|
||||
isShowingSearchResult -> {
|
||||
exitSearchMenu()
|
||||
restoreLastBookProcess()
|
||||
}
|
||||
|
||||
ReadBook.lastBookProgress != null && confirmRestoreProcess != false -> {
|
||||
restoreLastBookProcess()
|
||||
}
|
||||
|
||||
BaseReadAloudService.isPlay() -> {
|
||||
ReadAloud.pause(this@ReadBookActivity)
|
||||
toastOnUi(R.string.read_aloud_pause)
|
||||
}
|
||||
|
||||
isAutoPage -> {
|
||||
autoPageStop()
|
||||
}
|
||||
|
||||
getPrefBoolean("disableReturnKey") && !menuLayoutIsVisible -> {
|
||||
|
||||
}
|
||||
|
||||
else -> finish()
|
||||
}
|
||||
//拦截返回供恢复阅读进度
|
||||
if (ReadBook.lastBookProgress != null && confirmRestoreProcess != false) {
|
||||
restoreLastBookProcess()
|
||||
return@addCallback
|
||||
}
|
||||
if (BaseReadAloudService.isPlay()) {
|
||||
ReadAloud.pause(this@ReadBookActivity)
|
||||
toastOnUi(R.string.read_aloud_pause)
|
||||
return@addCallback
|
||||
}
|
||||
if (isAutoPage) {
|
||||
autoPageStop()
|
||||
return@addCallback
|
||||
}
|
||||
if (getPrefBoolean("disableReturnKey") && !menuLayoutIsVisible) {
|
||||
return@addCallback
|
||||
}
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||
super.onPostCreate(savedInstanceState)
|
||||
viewModel.initReadBookConfig(intent)
|
||||
Looper.myQueue().addIdleHandler {
|
||||
viewModel.initData(intent)
|
||||
false
|
||||
}
|
||||
justInitData = true
|
||||
upScreenTimeOut()
|
||||
ReadBook.register(this)
|
||||
}
|
||||
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
viewModel.initData(intent)
|
||||
@@ -1095,7 +1102,9 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
"page" -> ReadBook.durPageIndex
|
||||
else /* chapter */ -> ReadBook.durChapterIndex
|
||||
}
|
||||
binding.readMenu.setSeekPage(progress)
|
||||
if (progress >= 0) {
|
||||
binding.readMenu.setSeekPage(progress)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -243,7 +243,6 @@ class ReadMenu @JvmOverloads constructor(
|
||||
} else {
|
||||
binding.bottomView.applyNavigationBarPadding()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
|
||||
@@ -118,13 +118,19 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
||||
nextPage.invisible()
|
||||
curPage.markAsMainView()
|
||||
if (!isInEditMode) {
|
||||
upBg()
|
||||
//upBg()
|
||||
setWillNotDraw(false)
|
||||
upPageAnim()
|
||||
upPageSlopSquare()
|
||||
//upPageAnim()
|
||||
//upPageSlopSquare()
|
||||
}
|
||||
}
|
||||
|
||||
fun initAfterTransition() {
|
||||
upBg()
|
||||
upPageAnim()
|
||||
upPageSlopSquare()
|
||||
}
|
||||
|
||||
private fun setRect9x() {
|
||||
tlRect.set(0f, 0f, width * 0.33f, height * 0.33f)
|
||||
tcRect.set(width * 0.33f, 0f, width * 0.66f, height * 0.33f)
|
||||
|
||||
@@ -228,9 +228,9 @@ data class TextChapter(
|
||||
if (pageSize == 0) {
|
||||
return -1
|
||||
}
|
||||
val bIndex = pages.fastBinarySearchBy(charIndex, 0, pageSize) {
|
||||
val bIndex = pages.takeIf { it.isNotEmpty() }?.fastBinarySearchBy(charIndex, 0, pageSize) {
|
||||
it.chapterPosition
|
||||
}
|
||||
} ?: 0
|
||||
val index = abs(bIndex + 1) - 1
|
||||
// 判断是否已经排版到 charIndex ,没有则返回 -1
|
||||
if (!isCompleted && index == pageSize - 1) {
|
||||
|
||||
@@ -49,7 +49,8 @@ data class TextPage(
|
||||
val lines: List<TextLine> get() = textLines
|
||||
val lineSize: Int get() = textLines.size
|
||||
val charSize: Int get() = text.length.coerceAtLeast(1)
|
||||
val chapterPosition: Int get() = textLines.first().chapterPosition
|
||||
val chapterPosition: Int
|
||||
get() = textLines.firstOrNull()?.chapterPosition ?: 0
|
||||
val searchResult = hashSetOf<TextColumn>()
|
||||
var isMsgPage: Boolean = false
|
||||
var canvasRecorder = CanvasRecorderFactory.create(true)
|
||||
|
||||
Reference in New Issue
Block a user