Fix: Jitter when scrolling in Apps Page

This commit is contained in:
LooKeR 2021-11-11 01:42:36 +05:30
parent 24e9b8e403
commit 6239c9c5f7

View File

@ -307,8 +307,6 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
if (downloading) ProductAdapter.Action.CANCEL else primaryAction?.adapterAction
(recyclerView?.adapter as? ProductAdapter)?.setAction(adapterAction)
val toolbar = toolbar
if (toolbar != null) {
for (action in sequenceOf(
Action.INSTALL,
Action.SHARE,
@ -317,22 +315,22 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
)) {
toolbar.menu.findItem(action.id).isEnabled = !downloading
}
}
this.actions = Pair(actions, primaryAction)
updateToolbarButtons()
}
private fun updateToolbarTitle() {
val showPackageName = recyclerView?.let {
(it.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() != 0
} == true
lifecycleScope.launch(Dispatchers.IO) {
val showPackageName = recyclerView
?.let { (it.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() != 0 } == true
collapsingToolbar.title =
if (showPackageName) products[0].first.name.trimAfter(' ', 2)
else getString(R.string.application)
}
}
private fun updateToolbarButtons() {
lifecycleScope.launch(Dispatchers.IO) {
val (actions, primaryAction) = actions
val showPrimaryAction = recyclerView
?.let { (it.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() != 0 } == true
@ -343,9 +341,9 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
if (displayActions.size >= 4 && resources.configuration.screenWidthDp < 400) {
displayActions -= Action.DETAILS
}
val toolbar = toolbar
if (toolbar != null) {
for (action in Action.values()) {
launch(Dispatchers.Main) {
for (action in Action.values())
toolbar.menu.findItem(action.id).isVisible = action in displayActions
}
}