From f2e3817e260e3e5e42069fca6284e9e47e89f1a9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 19 Jan 2018 21:02:25 +0100 Subject: [PATCH] invalidate options menu only when necessary, not at every swipe --- .../calendar/activities/MainActivity.kt | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) 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 d0163fc09..2266380cb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -65,6 +65,7 @@ class MainActivity : SimpleActivity(), NavigationListener, RefreshRecyclerViewLi private var mLatestSearchQuery = "" private var mCalDAVSyncHandler = Handler() private var mSearchMenuItem: MenuItem? = null + private var mIsGoToTodayVisible = true private var mDefaultWeeklyPage = 0 private var mDefaultMonthlyPage = 0 @@ -168,13 +169,16 @@ class MainActivity : SimpleActivity(), NavigationListener, RefreshRecyclerViewLi override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_main, menu) + mIsGoToTodayVisible = shouldGoToTodayBeVisible() menu.apply { findItem(R.id.filter).isVisible = mShouldFilterBeVisible - findItem(R.id.go_to_today).isVisible = shouldGoToTodayBeVisible() + findItem(R.id.go_to_today).isVisible = mIsGoToTodayVisible findItem(R.id.refresh_caldav_calendars).isVisible = config.caldavSync } - setupSearch(menu) + if (mSearchMenuItem == null) { + setupSearch(menu) + } return true } @@ -630,7 +634,10 @@ class MainActivity : SimpleActivity(), NavigationListener, RefreshRecyclerViewLi } override fun onPageSelected(position: Int) { - invalidateOptionsMenu() + if (mIsGoToTodayVisible != shouldGoToTodayBeVisible()) { + invalidateOptionsMenu() + } + if (config.storedView == YEARLY_VIEW) { val dateTime = Formatter.getDateTimeFromCode(codes[position]) supportActionBar?.title = "${getString(R.string.app_launcher_name)} - ${Formatter.getYear(dateTime)}" @@ -690,7 +697,10 @@ class MainActivity : SimpleActivity(), NavigationListener, RefreshRecyclerViewLi } override fun onPageSelected(position: Int) { - invalidateOptionsMenu() + if (mIsGoToTodayVisible != shouldGoToTodayBeVisible()) { + invalidateOptionsMenu() + } + setupWeeklyActionbarTitle(weekTSs[position]) } }) @@ -753,7 +763,10 @@ class MainActivity : SimpleActivity(), NavigationListener, RefreshRecyclerViewLi } override fun onPageSelected(position: Int) { - invalidateOptionsMenu() + if (mIsGoToTodayVisible != shouldGoToTodayBeVisible()) { + invalidateOptionsMenu() + } + if (position < years.size) { supportActionBar?.title = "${getString(R.string.app_launcher_name)} - ${years[position]}" }