mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-21 14:10:51 +01:00
limit the weekly view scrollview depending on set hours limit
This commit is contained in:
parent
7b6c4dde34
commit
3903d82204
@ -1,6 +1,7 @@
|
|||||||
package com.simplemobiletools.calendar.fragments
|
package com.simplemobiletools.calendar.fragments
|
||||||
|
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
|
import android.graphics.Rect
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.app.Fragment
|
import android.support.v4.app.Fragment
|
||||||
@ -31,18 +32,30 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
lateinit var mRes: Resources
|
lateinit var mRes: Resources
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
mView = inflater.inflate(R.layout.fragment_week, container, false).apply {
|
val rowHeight = context.resources.getDimension(R.dimen.weekly_view_row_height)
|
||||||
|
val minY = (rowHeight * context.config.startWeeklyAt).toInt()
|
||||||
|
var maxY = (rowHeight * context.config.endWeeklyAt).toInt()
|
||||||
|
|
||||||
|
mView = inflater.inflate(R.layout.fragment_week, container, false).apply {
|
||||||
week_events_scrollview.setOnScrollviewListener(object : MyScrollView.ScrollViewListener {
|
week_events_scrollview.setOnScrollviewListener(object : MyScrollView.ScrollViewListener {
|
||||||
override fun onScrollChanged(scrollView: MyScrollView, x: Int, y: Int, oldx: Int, oldy: Int) {
|
override fun onScrollChanged(scrollView: MyScrollView, x: Int, y: Int, oldx: Int, oldy: Int) {
|
||||||
|
if (y < minY) {
|
||||||
|
week_events_scrollview.scrollY = minY
|
||||||
|
} else if (y > maxY) {
|
||||||
|
week_events_scrollview.scrollY = maxY
|
||||||
|
} else {
|
||||||
mListener?.scrollTo(y)
|
mListener?.scrollTo(y)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
week_events_scrollview.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
week_events_scrollview.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||||
override fun onGlobalLayout() {
|
override fun onGlobalLayout() {
|
||||||
updateScrollY(MainActivity.mWeekScrollY)
|
updateScrollY(Math.max(MainActivity.mWeekScrollY, minY))
|
||||||
mView.week_events_scrollview.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||||
|
val bounds = Rect()
|
||||||
|
week_events_holder.getGlobalVisibleRect(bounds)
|
||||||
|
maxY -= bounds.bottom - bounds.top
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -102,6 +102,7 @@
|
|||||||
android:verticalSpacing="1dp"/>
|
android:verticalSpacing="1dp"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/week_events_columns_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/weekly_view_events_height"
|
android:layout_height="@dimen/weekly_view_events_height"
|
||||||
android:background="@android:color/transparent"
|
android:background="@android:color/transparent"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user