adding a helper function to remove some duplication
This commit is contained in:
parent
d8c59f1700
commit
f7abbfc3ea
1 changed files with 8 additions and 9 deletions
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue