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,46 +307,44 @@ 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 for (action in sequenceOf(
if (toolbar != null) { Action.INSTALL,
for (action in sequenceOf( Action.SHARE,
Action.INSTALL, Action.UPDATE,
Action.SHARE, Action.UNINSTALL
Action.UPDATE, )) {
Action.UNINSTALL 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() {
val (actions, primaryAction) = actions lifecycleScope.launch(Dispatchers.IO) {
val showPrimaryAction = recyclerView val (actions, primaryAction) = actions
?.let { (it.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() != 0 } == true val showPrimaryAction = recyclerView
val displayActions = actions.toMutableSet() ?.let { (it.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() != 0 } == true
if (!showPrimaryAction && primaryAction != null) { val displayActions = actions.toMutableSet()
displayActions -= primaryAction if (!showPrimaryAction && primaryAction != null) {
} displayActions -= primaryAction
if (displayActions.size >= 4 && resources.configuration.screenWidthDp < 400) { }
displayActions -= Action.DETAILS 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) {
toolbar.menu.findItem(action.id).isVisible = action in displayActions for (action in Action.values())
toolbar.menu.findItem(action.id).isVisible = action in displayActions
} }
} }
} }