create a local variable for WeekFragment scrollview

This commit is contained in:
tibbi 2018-02-18 21:18:30 +01:00
parent e47ab2f145
commit 0486b77173

View File

@ -23,10 +23,7 @@ import com.simplemobiletools.calendar.interfaces.WeekFragmentListener
import com.simplemobiletools.calendar.interfaces.WeeklyCalendar
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.views.MyScrollView
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.beGone
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.extensions.getContrastColor
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.fragment_week.*
import kotlinx.android.synthetic.main.fragment_week.view.*
import org.joda.time.DateTime
@ -58,6 +55,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
lateinit var inflater: LayoutInflater
lateinit var mView: View
lateinit var mScrollView: MyScrollView
lateinit var mCalendar: WeeklyCalendarImpl
lateinit var mRes: Resources
@ -79,19 +77,16 @@ class WeekFragment : Fragment(), WeeklyCalendar {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
this.inflater = inflater
mView = inflater.inflate(R.layout.fragment_week, container, false).apply {
week_events_scrollview.setOnScrollviewListener(object : MyScrollView.ScrollViewListener {
override fun onScrollChanged(scrollView: MyScrollView, x: Int, y: Int, oldx: Int, oldy: Int) {
checkScrollLimits(y)
}
})
mView = inflater.inflate(R.layout.fragment_week, container, false)
mScrollView = mView.week_events_scrollview
mScrollView.setOnScrollviewListener(object : MyScrollView.ScrollViewListener {
override fun onScrollChanged(scrollView: MyScrollView, x: Int, y: Int, oldx: Int, oldy: Int) {
checkScrollLimits(y)
}
})
week_events_scrollview.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
week_events_scrollview.viewTreeObserver.removeOnGlobalLayoutListener(this)
updateScrollY(Math.max(mListener?.getCurrScrollY() ?: 0, minScrollY))
}
})
mScrollView.onGlobalLayout {
updateScrollY(Math.max(mListener?.getCurrScrollY() ?: 0, minScrollY))
}
(0..6).map { inflater.inflate(R.layout.stroke_vertical_divider, mView.week_vertical_grid_holder) }
@ -111,24 +106,18 @@ class WeekFragment : Fragment(), WeeklyCalendar {
setupDayLabels()
updateCalendar()
mView.week_events_scrollview.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
if (context == null)
return
mScrollView.onGlobalLayout {
minScrollY = mRowHeight * context!!.config.startWeeklyAt
maxScrollY = mRowHeight * context!!.config.endWeeklyAt
mView.week_events_scrollview.viewTreeObserver.removeOnGlobalLayoutListener(this)
minScrollY = mRowHeight * context!!.config.startWeeklyAt
maxScrollY = mRowHeight * context!!.config.endWeeklyAt
val bounds = Rect()
week_events_holder.getGlobalVisibleRect(bounds)
maxScrollY -= bounds.bottom - bounds.top
if (minScrollY > maxScrollY)
maxScrollY = -1
val bounds = Rect()
week_events_holder.getGlobalVisibleRect(bounds)
maxScrollY -= bounds.bottom - bounds.top
if (minScrollY > maxScrollY)
maxScrollY = -1
checkScrollLimits(mView.week_events_scrollview.scrollY)
}
})
checkScrollLimits(mScrollView.scrollY)
}
}
override fun setMenuVisibility(menuVisible: Boolean) {
@ -136,7 +125,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
isFragmentVisible = menuVisible
if (isFragmentVisible && wasFragmentInit) {
mListener?.updateHoursTopMargin(mView.week_top_holder.height)
checkScrollLimits(mView.week_events_scrollview.scrollY)
checkScrollLimits(mScrollView.scrollY)
}
}
@ -176,9 +165,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
private fun checkScrollLimits(y: Int) {
if (minScrollY != -1 && y < minScrollY) {
mView.week_events_scrollview.scrollY = minScrollY
mScrollView.scrollY = minScrollY
} else if (maxScrollY != -1 && y > maxScrollY) {
mView.week_events_scrollview.scrollY = maxScrollY
mScrollView.scrollY = maxScrollY
} else if (isFragmentVisible) {
mListener?.scrollTo(y)
}
@ -451,7 +440,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
fun updateScrollY(y: Int) {
if (wasFragmentInit) {
mView.week_events_scrollview.scrollY = y
mScrollView.scrollY = y
}
}
}