[UI] Fix disabling pull to refresh when changing page using tab layout.

This commit is contained in:
Kuba Szczodrzyński 2020-03-30 23:16:35 +02:00
parent 0db6393bb0
commit b794b30346
4 changed files with 7 additions and 1 deletions

View File

@ -13,10 +13,12 @@ class LazyViewPager @JvmOverloads constructor(
) : ViewPager(context, attrs) {
private var pageSelection = -1
private var scrollState = 0
init {
addOnPageChangeListener(object : OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {
scrollState = state
(adapter as? LazyPagerAdapter)?.let {
it.swipeRefreshLayout?.isEnabled = state == SCROLL_STATE_IDLE && it.enabledList[pageSelection, true]
}
@ -28,7 +30,8 @@ class LazyViewPager @JvmOverloads constructor(
override fun onPageSelected(position: Int) {
pageSelection = position
if (adapter is LazyPagerAdapter) {
(adapter as? LazyPagerAdapter)?.let {
it.swipeRefreshLayout?.isEnabled = scrollState == SCROLL_STATE_IDLE && it.enabledList[pageSelection, true]
val fragment = adapter?.instantiateItem(this@LazyViewPager, position)
val lazyFragment = fragment as? LazyFragment
lazyFragment?.createPage()

View File

@ -93,6 +93,7 @@ class HomeworkListFragment : LazyFragment(), CoroutineScope {
}
}
adapter.notifyDataSetChanged()
setSwipeToRefresh(false) // TODO
// show/hide relevant views
b.progressBar.isVisible = false

View File

@ -64,6 +64,7 @@ class TemplateListFragment : Fragment(), CoroutineScope {
}
}
adapter.notifyDataSetChanged()
b.refreshLayout.isEnabled = false // TODO
// show/hide relevant views
b.progressBar.isVisible = false

View File

@ -64,6 +64,7 @@ class TemplateListPageFragment : LazyFragment(), CoroutineScope {
}
}
adapter.notifyDataSetChanged()
setSwipeToRefresh(false) // TODO
// show/hide relevant views
b.progressBar.isVisible = false