Bottom space bar: always try to center the selected space
Change-Id: Ia9820869d27b409da50900ab9819cec9e5e4691b
This commit is contained in:
parent
a53c183847
commit
731dc8987d
|
@ -171,10 +171,10 @@ class HomeDetailFragment :
|
||||||
|
|
||||||
checkNotificationTabStatus()
|
checkNotificationTabStatus()
|
||||||
|
|
||||||
|
views.spaceBarRecyclerView.layoutManager = LinearLayoutManager(context)
|
||||||
val spaceBarAdapter = spaceBarController.also { controller ->
|
val spaceBarAdapter = spaceBarController.also { controller ->
|
||||||
controller.spaceRoomListener = spaceBarListener
|
controller.spaceRoomListener = spaceBarListener
|
||||||
}.adapter
|
}.adapter
|
||||||
views.spaceBarRecyclerView.layoutManager = LinearLayoutManager(context)
|
|
||||||
views.spaceBarRecyclerView.adapter = spaceBarAdapter
|
views.spaceBarRecyclerView.adapter = spaceBarAdapter
|
||||||
|
|
||||||
// Reduce sensitivity of viewpager to avoid scrolling horizontally by accident too easily
|
// Reduce sensitivity of viewpager to avoid scrolling horizontally by accident too easily
|
||||||
|
|
|
@ -69,8 +69,10 @@ class SpaceBarController @Inject constructor(
|
||||||
)
|
)
|
||||||
onBind { _, view, _ ->
|
onBind { _, view, _ ->
|
||||||
host.carousel = view
|
host.carousel = view
|
||||||
|
view.post {
|
||||||
host.scrollToSpace(selectedSpace?.roomId)
|
host.scrollToSpace(selectedSpace?.roomId)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onUnbind { _, _ ->
|
onUnbind { _, _ ->
|
||||||
host.carousel = null
|
host.carousel = null
|
||||||
|
@ -137,12 +139,17 @@ class SpaceBarController @Inject constructor(
|
||||||
var effectivePosition = position
|
var effectivePosition = position
|
||||||
val lm = safeCarousel.layoutManager as? LinearLayoutManager
|
val lm = safeCarousel.layoutManager as? LinearLayoutManager
|
||||||
if (lm != null) {
|
if (lm != null) {
|
||||||
// Look-ahead of 1
|
// Scroll to an element such that the new selection is roughly in the middle
|
||||||
if (lm.findFirstCompletelyVisibleItemPosition() >= position) {
|
val firstVisible = lm.findFirstCompletelyVisibleItemPosition()
|
||||||
effectivePosition--
|
val visibleRange = lm.findLastCompletelyVisibleItemPosition() - firstVisible + 1
|
||||||
} else if (lm.findLastVisibleItemPosition() <= position) {
|
val overshoot = visibleRange/2
|
||||||
effectivePosition++
|
val currentMiddle = firstVisible + overshoot
|
||||||
|
if (currentMiddle < position) {
|
||||||
|
effectivePosition = position + overshoot
|
||||||
|
} else if (currentMiddle > position) {
|
||||||
|
effectivePosition = position - overshoot
|
||||||
}
|
}
|
||||||
|
// List limits
|
||||||
effectivePosition = max(0, min(effectivePosition, lm.itemCount-1))
|
effectivePosition = max(0, min(effectivePosition, lm.itemCount-1))
|
||||||
}
|
}
|
||||||
safeCarousel.smoothScrollToPosition(effectivePosition)
|
safeCarousel.smoothScrollToPosition(effectivePosition)
|
||||||
|
|
Loading…
Reference in New Issue