增加进入书籍阅读时动画效果的配置
高级设置:延缓书籍加载、使用共享元素动画
This commit is contained in:
4 files changed
+120
-51
No files matched your search
@@ -208,6 +208,7 @@ object PreferKey {
|
|||||||
const val paddingDisplayCutouts = "paddingDisplayCutouts"
|
const val paddingDisplayCutouts = "paddingDisplayCutouts"
|
||||||
|
|
||||||
const val delayBookLoadEnable = "delayBookLoadEnable"
|
const val delayBookLoadEnable = "delayBookLoadEnable"
|
||||||
|
const val sharedElementEnterTransitionEnable = "sharedElementEnterTransitionEnable"
|
||||||
|
|
||||||
const val bookshelfLayoutGridLandscape = "bookshelfLayoutGridLandscape"
|
const val bookshelfLayoutGridLandscape = "bookshelfLayoutGridLandscape"
|
||||||
|
|
||||||
|
|||||||
@@ -211,18 +211,29 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
|||||||
appCtx.putPrefInt(PreferKey.bookGroupStyle, value)
|
appCtx.putPrefInt(PreferKey.bookGroupStyle, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
var bookshelfLayoutPortrait: Int
|
var bookshelfLayoutModePortrait: Int
|
||||||
get() = appCtx.getPrefInt(PreferKey.bookshelfLayoutPortrait, 3)
|
get() = appCtx.getPrefInt(PreferKey.bookshelfLayoutModePortrait, 1)
|
||||||
set(value) {
|
set(value) {
|
||||||
appCtx.putPrefInt(PreferKey.bookshelfLayoutPortrait, value)
|
appCtx.putPrefInt(PreferKey.bookshelfLayoutModePortrait, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
var bookshelfLayoutLandscape: Int
|
var bookshelfLayoutModeLandscape: Int
|
||||||
get() = appCtx.getPrefInt(PreferKey.bookshelfLayoutLandscape, 5)
|
get() = appCtx.getPrefInt(PreferKey.bookshelfLayoutModeLandscape, 1)
|
||||||
set(value) {
|
set(value) {
|
||||||
appCtx.putPrefInt(PreferKey.bookshelfLayoutLandscape, value)
|
appCtx.putPrefInt(PreferKey.bookshelfLayoutModeLandscape, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var bookshelfLayoutGridPortrait: Int
|
||||||
|
get() = appCtx.getPrefInt(PreferKey.bookshelfLayoutGridPortrait, 3)
|
||||||
|
set(value) {
|
||||||
|
appCtx.putPrefInt(PreferKey.bookshelfLayoutGridPortrait, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
var bookshelfLayoutGridLandscape: Int
|
||||||
|
get() = appCtx.getPrefInt(PreferKey.bookshelfLayoutGridLandscape, 7)
|
||||||
|
set(value) {
|
||||||
|
appCtx.putPrefInt(PreferKey.bookshelfLayoutGridLandscape, value)
|
||||||
|
}
|
||||||
|
|
||||||
var saveTabPosition: Int
|
var saveTabPosition: Int
|
||||||
get() = appCtx.getPrefInt(PreferKey.saveTabPosition, 0)
|
get() = appCtx.getPrefInt(PreferKey.saveTabPosition, 0)
|
||||||
@@ -573,6 +584,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
|||||||
val paddingDisplayCutouts
|
val paddingDisplayCutouts
|
||||||
get() = appCtx.getPrefBoolean(PreferKey.paddingDisplayCutouts, false)
|
get() = appCtx.getPrefBoolean(PreferKey.paddingDisplayCutouts, false)
|
||||||
|
|
||||||
|
val delayBookLoadEnable
|
||||||
|
get() = appCtx.getPrefBoolean(PreferKey.delayBookLoadEnable, true)
|
||||||
|
|
||||||
|
val sharedElementEnterTransitionEnable
|
||||||
|
get() = appCtx.getPrefBoolean(PreferKey.sharedElementEnterTransitionEnable, true)
|
||||||
|
|
||||||
var searchScope: String
|
var searchScope: String
|
||||||
get() = appCtx.getPrefString("searchScope") ?: ""
|
get() = appCtx.getPrefString("searchScope") ?: ""
|
||||||
set(value) {
|
set(value) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.content.Intent
|
|||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.transition.Transition
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.HapticFeedbackConstants
|
import android.view.HapticFeedbackConstants
|
||||||
import android.view.InputDevice
|
import android.view.InputDevice
|
||||||
@@ -19,6 +20,7 @@ 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.net.toUri
|
import androidx.core.net.toUri
|
||||||
|
import androidx.core.view.doOnLayout
|
||||||
import androidx.core.view.doOnPreDraw
|
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
|
||||||
@@ -263,59 +265,98 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
postponeEnterTransition()
|
|
||||||
val transform = MaterialContainerTransform().apply {
|
if (AppConfig.sharedElementEnterTransitionEnable) {
|
||||||
addTarget(binding.rootView)
|
postponeEnterTransition()
|
||||||
scrimColor = Color.TRANSPARENT
|
val transform = MaterialContainerTransform().apply {
|
||||||
duration = 500
|
addTarget(binding.rootView)
|
||||||
|
scrimColor = Color.TRANSPARENT
|
||||||
|
duration = 500
|
||||||
|
}
|
||||||
|
window.sharedElementEnterTransition = transform
|
||||||
|
|
||||||
|
window.sharedElementReturnTransition =
|
||||||
|
MaterialSharedAxis(MaterialSharedAxis.X, true).apply {
|
||||||
|
duration = 300
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AppConfig.delayBookLoadEnable) {
|
||||||
|
window.sharedElementEnterTransition?.addListener(object :
|
||||||
|
Transition.TransitionListener {
|
||||||
|
override fun onTransitionStart(transition: Transition) {}
|
||||||
|
override fun onTransitionEnd(transition: Transition) {
|
||||||
|
binding.readView.doOnLayout {
|
||||||
|
viewModel.initReadBookConfig(intent)
|
||||||
|
viewModel.initData(intent)
|
||||||
|
binding.readView.initAfterTransition()
|
||||||
|
justInitData = true
|
||||||
|
}
|
||||||
|
transition.removeListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTransitionCancel(transition: Transition) {
|
||||||
|
viewModel.initReadBookConfig(intent)
|
||||||
|
viewModel.initData(intent)
|
||||||
|
binding.readView.initAfterTransition()
|
||||||
|
justInitData = true
|
||||||
|
transition.removeListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTransitionPause(transition: Transition) {}
|
||||||
|
override fun onTransitionResume(transition: Transition) {}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
window.sharedElementEnterTransition = transform
|
|
||||||
window.sharedElementReturnTransition =
|
|
||||||
MaterialSharedAxis(MaterialSharedAxis.X, true).apply { duration = 300 }
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
binding.rootView.transitionName = intent.getStringExtra("transitionName")
|
if (!AppConfig.delayBookLoadEnable || !AppConfig.sharedElementEnterTransitionEnable) {
|
||||||
|
lifecycleScope.launch(Dispatchers.Default) {
|
||||||
|
viewModel.initReadBookConfig(intent)
|
||||||
|
viewModel.initData(intent)
|
||||||
|
|
||||||
|
withContext(Main) {
|
||||||
|
binding.readView.initAfterTransition()
|
||||||
|
justInitData = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (AppConfig.sharedElementEnterTransitionEnable)
|
||||||
|
binding.rootView.transitionName = intent.getStringExtra("transitionName")
|
||||||
|
|
||||||
binding.cursorLeft.setOnTouchListener(this)
|
binding.cursorLeft.setOnTouchListener(this)
|
||||||
binding.cursorRight.setOnTouchListener(this)
|
binding.cursorRight.setOnTouchListener(this)
|
||||||
|
|
||||||
binding.rootView.doOnPreDraw { startPostponedEnterTransition() }
|
binding.rootView.doOnPreDraw {
|
||||||
|
startPostponedEnterTransition()
|
||||||
lifecycleScope.launch(Dispatchers.Default) {
|
|
||||||
viewModel.initReadBookConfig(intent)
|
|
||||||
viewModel.initData(intent)
|
|
||||||
|
|
||||||
withContext(Main) {
|
|
||||||
binding.readView.initAfterTransition()
|
|
||||||
justInitData = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onBackPressedDispatcher.addCallback(this) {
|
onBackPressedDispatcher.addCallback(this) {
|
||||||
when {
|
if (isShowingSearchResult) {
|
||||||
isShowingSearchResult -> {
|
exitSearchMenu()
|
||||||
exitSearchMenu()
|
restoreLastBookProcess()
|
||||||
restoreLastBookProcess()
|
return@addCallback
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,8 +365,6 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
upScreenTimeOut()
|
upScreenTimeOut()
|
||||||
ReadBook.register(this)
|
ReadBook.register(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
viewModel.initData(intent)
|
viewModel.initData(intent)
|
||||||
|
|||||||
@@ -94,6 +94,18 @@
|
|||||||
android:summary="@string/firebase_enable_summary"
|
android:summary="@string/firebase_enable_summary"
|
||||||
android:title="@string/firebase_enable_title" />
|
android:title="@string/firebase_enable_title" />
|
||||||
|
|
||||||
|
<io.legato.kazusa.lib.prefs.SwitchPreference
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:key="sharedElementEnterTransitionEnable"
|
||||||
|
android:summary="从书架进入阅读界面时,优化动画效果。"
|
||||||
|
android:title="使用共享元素动画" />
|
||||||
|
|
||||||
|
<io.legato.kazusa.lib.prefs.SwitchPreference
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:key="delayBookLoadEnable"
|
||||||
|
android:summary="减少进入阅读界面时的卡顿,但加载书籍时间会延长。"
|
||||||
|
android:title="延缓书籍加载" />
|
||||||
|
|
||||||
<io.legato.kazusa.lib.prefs.Preference
|
<io.legato.kazusa.lib.prefs.Preference
|
||||||
android:key="localPassword"
|
android:key="localPassword"
|
||||||
android:summary="@string/set_local_password_summary"
|
android:summary="@string/set_local_password_summary"
|
||||||
|
|||||||
Reference in new issue
Block a user