From d8c59f1700dbb474c68cedf337b7057f87ef89d3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 25 Mar 2020 14:51:07 +0100 Subject: [PATCH] improving the way weekly zooming works a bit, needs some cleanup --- .../calendar/pro/fragments/WeekFragment.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt index 9f27eedaf..d397fc675 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt @@ -44,8 +44,10 @@ class WeekFragment : Fragment(), WeeklyCalendar { private var primaryColor = 0 private var lastHash = 0 private var prevScaleSpanY = 0f + private var scaleCenterPercent = 0f private var defaultRowHeight = 0f private var screenHeight = 0 + private var rowHeightsAtScale = 0f private var mWasDestroyed = false private var isFragmentVisible = false private var wasFragmentInit = false @@ -250,10 +252,22 @@ class WeekFragment : Fragment(), WeeklyCalendar { config.weeklyViewItemHeightMultiplier = newFactor updateViewScale() listener?.updateRowHeight(rowHeight.toInt()) + + val fullContentHeight = rowHeight * 24 + val visibleRatio = scrollView.height / fullContentHeight + val visibleHeight = fullContentHeight * visibleRatio + val targetY = rowHeightsAtScale * rowHeight - scaleCenterPercent * visibleHeight + 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 scrollView.isScrollable = false prevScaleSpanY = detector.currentSpanY wasScaled = true