From c24e18f4135af553c64cb6feaa12e4f4ff01f58e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 4 Feb 2017 11:43:06 +0100 Subject: [PATCH] update the hours scrollview margin if theres something at all-day top holder --- .../calendar/activities/MainActivity.kt | 1 + .../calendar/fragments/WeekFragment.kt | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt index 9b4a21442..5c7925bfd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -265,6 +265,7 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener { fun updateHoursTopMargin(margin: Int) { (week_view_hours_scrollview.layoutParams as LinearLayout.LayoutParams).setMargins(0, margin, 0, 0) + week_view_hours_scrollview.requestLayout() } private fun getWeekTimestamps(targetWeekTS: Int): List { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt index cde3980b9..250409393 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt @@ -36,6 +36,9 @@ class WeekFragment : Fragment(), WeeklyCalendar { private var maxScrollY = -1 private var mWasDestroyed = false private var primaryColor = 0 + private var isFragmentVisible = false + private var wasFragmentInit = false + lateinit var mView: View lateinit var mCalendar: WeeklyCalendarImpl lateinit var mRes: Resources @@ -70,9 +73,18 @@ class WeekFragment : Fragment(), WeeklyCalendar { mRes = resources mCalendar = WeeklyCalendarImpl(this, context) + wasFragmentInit = true return mView } + override fun setMenuVisibility(menuVisible: Boolean) { + super.setMenuVisibility(menuVisible) + isFragmentVisible = menuVisible + if (isFragmentVisible && wasFragmentInit) { + (activity as MainActivity).updateHoursTopMargin(mView.week_top_holder.height) + } + } + override fun onResume() { super.onResume() setupDayLabels() @@ -86,7 +98,6 @@ class WeekFragment : Fragment(), WeeklyCalendar { mView.week_events_scrollview.viewTreeObserver.removeOnGlobalLayoutListener(this) minScrollY = mRowHeight * context.config.startWeeklyAt maxScrollY = mRowHeight * context.config.endWeeklyAt - (activity as MainActivity).updateHoursTopMargin(mView.week_letters_holder.height) val bounds = Rect() week_events_holder.getGlobalVisibleRect(bounds) @@ -205,6 +216,15 @@ class WeekFragment : Fragment(), WeeklyCalendar { leftMargin = firstDayIndex * dayColumnWidth width = (daysCnt + 1) * dayColumnWidth - mRes.displayMetrics.density.toInt() } + + mView.week_top_holder.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { + override fun onGlobalLayout() { + mView.week_top_holder.viewTreeObserver.removeOnGlobalLayoutListener(this) + if (isFragmentVisible) { + (activity as MainActivity).updateHoursTopMargin(mView.week_top_holder.height) + } + } + }) } setOnClickListener { Intent(activity.applicationContext, EventActivity::class.java).apply {