adding a helper function to remove some duplication

This commit is contained in:
tibbi 2020-03-25 17:16:44 +01:00
parent d8c59f1700
commit f7abbfc3ea

View file

@ -253,21 +253,14 @@ class WeekFragment : Fragment(), WeeklyCalendar {
updateViewScale() updateViewScale()
listener?.updateRowHeight(rowHeight.toInt()) listener?.updateRowHeight(rowHeight.toInt())
val fullContentHeight = rowHeight * 24 val targetY = rowHeightsAtScale * rowHeight - scaleCenterPercent * getVisibleHeight()
val visibleRatio = scrollView.height / fullContentHeight
val visibleHeight = fullContentHeight * visibleRatio
val targetY = rowHeightsAtScale * rowHeight - scaleCenterPercent * visibleHeight
scrollView.scrollTo(0, targetY.toInt()) scrollView.scrollTo(0, targetY.toInt())
return super.onScale(detector) return super.onScale(detector)
} }
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean { override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
val fullContentHeight = rowHeight * 24
val visibleRatio = scrollView.height / fullContentHeight
val visibleHeight = fullContentHeight * visibleRatio
scaleCenterPercent = detector.focusY / scrollView.height scaleCenterPercent = detector.focusY / scrollView.height
rowHeightsAtScale = (scrollView.scrollY + scaleCenterPercent * visibleHeight) / rowHeight rowHeightsAtScale = (scrollView.scrollY + scaleCenterPercent * getVisibleHeight()) / rowHeight
scrollView.isScrollable = false scrollView.isScrollable = false
prevScaleSpanY = detector.currentSpanY prevScaleSpanY = detector.currentSpanY
wasScaled = true 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>) { override fun updateWeeklyCalendar(events: ArrayList<Event>) {
val newHash = events.hashCode() val newHash = events.hashCode()
if (newHash == lastHash || mWasDestroyed || context == null) { if (newHash == lastHash || mWasDestroyed || context == null) {