mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 04:10:45 +01:00
improving the weekly views scale UX
This commit is contained in:
parent
d3e6705226
commit
24b524bbe2
@ -64,7 +64,7 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.23.8'
|
||||
implementation 'com.simplemobiletools:commons:5.23.9'
|
||||
implementation 'joda-time:joda-time:2.10.1'
|
||||
implementation 'androidx.multidex:multidex:2.0.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
|
||||
|
@ -38,8 +38,8 @@ class MyWeekPagerAdapter(fm: FragmentManager, private val mWeekTimestamps: List<
|
||||
}
|
||||
}
|
||||
|
||||
fun updateNotVisibleZoomLevel(pos: Int) {
|
||||
mFragments[pos - 1]?.updateNotVisibleViewZoomLevel()
|
||||
mFragments[pos + 1]?.updateNotVisibleViewZoomLevel()
|
||||
fun updateNotVisibleScaleLevel(pos: Int) {
|
||||
mFragments[pos - 1]?.updateNotVisibleViewScaleLevel()
|
||||
mFragments[pos + 1]?.updateNotVisibleViewScaleLevel()
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,9 @@ import java.util.*
|
||||
|
||||
class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
private val PLUS_FADEOUT_DELAY = 5000L
|
||||
private val MIN_ZOOM_FACTOR = 0.3f
|
||||
private val MAX_ZOOM_FACTOR = 5f
|
||||
private val MIN_SCALE_FACTOR = 0.3f
|
||||
private val MAX_SCALE_FACTOR = 5f
|
||||
private val SCALE_RANGE = MAX_SCALE_FACTOR - MIN_SCALE_FACTOR
|
||||
|
||||
var listener: WeekFragmentListener? = null
|
||||
private var weekTimestamp = 0L
|
||||
@ -42,8 +43,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
private var todayColumnIndex = -1
|
||||
private var primaryColor = 0
|
||||
private var lastHash = 0
|
||||
private var scaleAtStart = 1f
|
||||
private var prevScaleSpanY = 0f
|
||||
private var defaultRowHeight = 0f
|
||||
private var screenHeight = 0
|
||||
private var mWasDestroyed = false
|
||||
private var isFragmentVisible = false
|
||||
private var wasFragmentInit = false
|
||||
@ -147,7 +149,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
listener?.updateHoursTopMargin(mView.week_top_holder.height)
|
||||
checkScrollLimits(scrollView.scrollY)
|
||||
|
||||
// fix some glitches like at swiping from a fully zoomed out fragment will all-day events to an empty one
|
||||
// fix some glitches like at swiping from a fully scaled out fragment will all-day events to an empty one
|
||||
val fullFragmentHeight = (listener?.getFullFragmentHeight() ?: 0) - mView.week_top_holder.height
|
||||
if (scrollView.height < fullFragmentHeight) {
|
||||
config.weeklyViewItemHeightMultiplier = fullFragmentHeight / 24 / defaultRowHeight
|
||||
@ -236,9 +238,11 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
private fun getViewScaleDetector(): ScaleGestureDetector {
|
||||
return ScaleGestureDetector(context, object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
||||
override fun onScale(detector: ScaleGestureDetector): Boolean {
|
||||
val scaleDifference = detector.scaleFactor - scaleAtStart
|
||||
scaleAtStart = detector.scaleFactor
|
||||
var newFactor = Math.max(Math.min(config.weeklyViewItemHeightMultiplier + scaleDifference, MAX_ZOOM_FACTOR), MIN_ZOOM_FACTOR)
|
||||
val percent = (prevScaleSpanY - detector.currentSpanY) / screenHeight
|
||||
prevScaleSpanY = detector.currentSpanY
|
||||
|
||||
val wantedFactor = config.weeklyViewItemHeightMultiplier - (SCALE_RANGE * percent)
|
||||
var newFactor = Math.max(Math.min(wantedFactor, MAX_SCALE_FACTOR), MIN_SCALE_FACTOR)
|
||||
if (scrollView.height > defaultRowHeight * newFactor * 24) {
|
||||
newFactor = scrollView.height / 24f / defaultRowHeight
|
||||
}
|
||||
@ -251,8 +255,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
|
||||
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
|
||||
scrollView.isScrollable = false
|
||||
scaleAtStart = detector.scaleFactor
|
||||
prevScaleSpanY = detector.currentSpanY
|
||||
wasScaled = true
|
||||
screenHeight = context!!.realScreenSize.y
|
||||
return super.onScaleBegin(detector)
|
||||
}
|
||||
})
|
||||
@ -554,7 +559,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
}
|
||||
}
|
||||
|
||||
fun updateNotVisibleViewZoomLevel() {
|
||||
fun updateNotVisibleViewScaleLevel() {
|
||||
if (!isFragmentVisible) {
|
||||
updateViewScale()
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
|
||||
}
|
||||
|
||||
weekHolder!!.week_view_hours_holder.setPadding(0, 0, 0, rowHeight)
|
||||
(viewPager!!.adapter as? MyWeekPagerAdapter)?.updateNotVisibleZoomLevel(viewPager!!.currentItem)
|
||||
(viewPager!!.adapter as? MyWeekPagerAdapter)?.updateNotVisibleScaleLevel(viewPager!!.currentItem)
|
||||
}
|
||||
|
||||
override fun getFullFragmentHeight() = weekHolder!!.week_view_holder.height
|
||||
|
Loading…
x
Reference in New Issue
Block a user