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 {