Fix toolbars not scrolled when option was enabled

This commit is contained in:
ztimms73
2021-06-20 20:11:17 +03:00
parent ed65145f83
commit f50a8b3112

View File

@@ -57,12 +57,15 @@ abstract class BaseActivity<B : ViewBinding> : AppCompatActivity(), OnApplyWindo
this.binding = binding
super.setContentView(binding.root)
(binding.root.findViewById<View>(R.id.toolbar) as? Toolbar)?.let(this::setSupportActionBar)
val params = (binding.root.findViewById<View>(R.id.toolbar_card))?.layoutParams as? AppBarLayout.LayoutParams
val toolbarParams = (binding.root.findViewById<View>(R.id.toolbar) as? Toolbar)?.layoutParams as? AppBarLayout.LayoutParams
val persistentToolbarParams = (binding.root.findViewById<View>(R.id.toolbar_card))?.layoutParams as? AppBarLayout.LayoutParams
ViewCompat.setOnApplyWindowInsetsListener(binding.root, this)
if (get<AppSettings>().isToolbarHideWhenScrolling) {
params?.scrollFlags = SCROLL_FLAG_SCROLL or SCROLL_FLAG_ENTER_ALWAYS
toolbarParams?.scrollFlags = SCROLL_FLAG_SCROLL or SCROLL_FLAG_ENTER_ALWAYS
persistentToolbarParams?.scrollFlags = SCROLL_FLAG_SCROLL or SCROLL_FLAG_ENTER_ALWAYS
} else {
params?.scrollFlags = SCROLL_FLAG_NO_SCROLL
toolbarParams?.scrollFlags = SCROLL_FLAG_NO_SCROLL
persistentToolbarParams?.scrollFlags = SCROLL_FLAG_NO_SCROLL
}
}