add some threshold at the weekly view zoom, ignore too small changes

This commit is contained in:
tibbi 2020-03-25 20:13:42 +01:00
parent f7abbfc3ea
commit c90b21f90d
2 changed files with 12 additions and 6 deletions

View File

@ -64,7 +64,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.23.9'
implementation 'com.simplemobiletools:commons:5.23.10'
implementation 'joda-time:joda-time:2.10.1'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'

View File

@ -35,6 +35,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
private val PLUS_FADEOUT_DELAY = 5000L
private val MIN_SCALE_FACTOR = 0.3f
private val MAX_SCALE_FACTOR = 5f
private val MIN_SCALE_DIFFERENCE = 0.02f
private val SCALE_RANGE = MAX_SCALE_FACTOR - MIN_SCALE_FACTOR
var listener: WeekFragmentListener? = null
@ -48,6 +49,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
private var defaultRowHeight = 0f
private var screenHeight = 0
private var rowHeightsAtScale = 0f
private var prevScaleFactor = 0f
private var mWasDestroyed = false
private var isFragmentVisible = false
private var wasFragmentInit = false
@ -249,12 +251,15 @@ class WeekFragment : Fragment(), WeeklyCalendar {
newFactor = scrollView.height / 24f / defaultRowHeight
}
if (Math.abs(newFactor - prevScaleFactor) > MIN_SCALE_DIFFERENCE) {
prevScaleFactor = newFactor
config.weeklyViewItemHeightMultiplier = newFactor
updateViewScale()
listener?.updateRowHeight(rowHeight.toInt())
val targetY = rowHeightsAtScale * rowHeight - scaleCenterPercent * getVisibleHeight()
scrollView.scrollTo(0, targetY.toInt())
}
return super.onScale(detector)
}
@ -263,6 +268,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
rowHeightsAtScale = (scrollView.scrollY + scaleCenterPercent * getVisibleHeight()) / rowHeight
scrollView.isScrollable = false
prevScaleSpanY = detector.currentSpanY
prevScaleFactor = config.weeklyViewItemHeightMultiplier
wasScaled = true
screenHeight = context!!.realScreenSize.y
return super.onScaleBegin(detector)