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