adding a helper function to remove some duplication
This commit is contained in:
parent
d8c59f1700
commit
f7abbfc3ea
|
@ -253,21 +253,14 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
updateViewScale()
|
||||
listener?.updateRowHeight(rowHeight.toInt())
|
||||
|
||||
val fullContentHeight = rowHeight * 24
|
||||
val visibleRatio = scrollView.height / fullContentHeight
|
||||
val visibleHeight = fullContentHeight * visibleRatio
|
||||
val targetY = rowHeightsAtScale * rowHeight - scaleCenterPercent * visibleHeight
|
||||
val targetY = rowHeightsAtScale * rowHeight - scaleCenterPercent * getVisibleHeight()
|
||||
scrollView.scrollTo(0, targetY.toInt())
|
||||
return super.onScale(detector)
|
||||
}
|
||||
|
||||
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
|
||||
val fullContentHeight = rowHeight * 24
|
||||
val visibleRatio = scrollView.height / fullContentHeight
|
||||
val visibleHeight = fullContentHeight * visibleRatio
|
||||
|
||||
scaleCenterPercent = detector.focusY / scrollView.height
|
||||
rowHeightsAtScale = (scrollView.scrollY + scaleCenterPercent * visibleHeight) / rowHeight
|
||||
rowHeightsAtScale = (scrollView.scrollY + scaleCenterPercent * getVisibleHeight()) / rowHeight
|
||||
scrollView.isScrollable = false
|
||||
prevScaleSpanY = detector.currentSpanY
|
||||
wasScaled = true
|
||||
|
@ -277,6 +270,12 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
})
|
||||
}
|
||||
|
||||
private fun getVisibleHeight(): Float {
|
||||
val fullContentHeight = rowHeight * 24
|
||||
val visibleRatio = scrollView.height / fullContentHeight
|
||||
return fullContentHeight * visibleRatio
|
||||
}
|
||||
|
||||
override fun updateWeeklyCalendar(events: ArrayList<Event>) {
|
||||
val newHash = events.hashCode()
|
||||
if (newHash == lastHash || mWasDestroyed || context == null) {
|
||||
|
|
Loading…
Reference in New Issue