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