孩子们这次真修了
修复从后台进入前台且Activity被系统回收时导致的书籍未加载和NPE问题
This commit is contained in:
@@ -253,7 +253,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|
||||||
if (AppConfig.sharedElementEnterTransitionEnable && savedInstanceState == null) {
|
if (AppConfig.sharedElementEnterTransitionEnable) {
|
||||||
|
|
||||||
val transform = MaterialContainerTransform().apply {
|
val transform = MaterialContainerTransform().apply {
|
||||||
addTarget(binding.rootView)
|
addTarget(binding.rootView)
|
||||||
@@ -280,8 +280,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
override fun onTransitionResume(transition: Transition) {}
|
override fun onTransitionResume(transition: Transition) {}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
loadBook()
|
|
||||||
}
|
}
|
||||||
window.sharedElementReturnTransition =
|
window.sharedElementReturnTransition =
|
||||||
MaterialSharedAxis(MaterialSharedAxis.X, true).apply {
|
MaterialSharedAxis(MaterialSharedAxis.X, true).apply {
|
||||||
@@ -289,6 +288,10 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
}
|
}
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
if (savedInstanceState != null && AppConfig.delayBookLoadEnable) {
|
||||||
|
loadBook()
|
||||||
|
}
|
||||||
|
|
||||||
if (AppConfig.sharedElementEnterTransitionEnable)
|
if (AppConfig.sharedElementEnterTransitionEnable)
|
||||||
binding.rootView.transitionName = intent.getStringExtra("transitionName")
|
binding.rootView.transitionName = intent.getStringExtra("transitionName")
|
||||||
|
|
||||||
@@ -325,6 +328,13 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onPostCreate(savedInstanceState)
|
||||||
|
if (!AppConfig.delayBookLoadEnable || !AppConfig.sharedElementEnterTransitionEnable) {
|
||||||
|
loadBook()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
viewModel.initData(intent)
|
viewModel.initData(intent)
|
||||||
@@ -440,7 +450,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
lifecycleScope.launch(Dispatchers.Default) {
|
lifecycleScope.launch(Dispatchers.Default) {
|
||||||
viewModel.initReadBookConfig(intent)
|
viewModel.initReadBookConfig(intent)
|
||||||
viewModel.initData(intent)
|
viewModel.initData(intent)
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Main) {
|
||||||
binding.readView.initAfterTransition()
|
binding.readView.initAfterTransition()
|
||||||
justInitData = true
|
justInitData = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,9 +236,10 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
removeCallbacks(longPressRunnable)
|
removeCallbacks(longPressRunnable)
|
||||||
if (!pressDown) return true
|
if (!pressDown) return true
|
||||||
pressDown = false
|
pressDown = false
|
||||||
if (!pageDelegate!!.isMoved && !isMove) {
|
if (pageDelegate?.isMoved == false && !isMove) {
|
||||||
if (!longPressed && !pressOnTextSelected) {
|
if (!longPressed && !pressOnTextSelected) {
|
||||||
if (!curPage.onClick(startX, startY)) {
|
val handled = curPage.onClick(startX, startY)
|
||||||
|
if (!handled) {
|
||||||
onSingleTapUp()
|
onSingleTapUp()
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user