From fc0b87c9a76132c0cda08f86c359d0db73b4aa69 Mon Sep 17 00:00:00 2001 From: Nikola Trubitsyn Date: Sat, 10 Feb 2018 16:46:27 +0300 Subject: [PATCH] Fix incorrect behaviour of favorites in menu --- .../filemanager/activities/MainActivity.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt index 9d573e2c..30ac6812 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt @@ -66,8 +66,6 @@ class MainActivity : SimpleActivity() { restartActivity() return } - - invalidateOptionsMenu() } override fun onPause() { @@ -89,9 +87,12 @@ class MainActivity : SimpleActivity() { override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu, menu) + return true + } + override fun onPrepareOptionsMenu(menu: Menu?): Boolean { val favorites = config.favorites - menu.apply { + menu!!.apply { findItem(R.id.add_favorite).isVisible = !favorites.contains(fragment.currentPath) findItem(R.id.remove_favorite).isVisible = favorites.contains(fragment.currentPath) findItem(R.id.go_to_favorite).isVisible = favorites.isNotEmpty() @@ -180,7 +181,6 @@ class MainActivity : SimpleActivity() { } (fragment_holder as ItemsFragment).openPath(newPath) - invalidateOptionsMenu() } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -213,12 +213,10 @@ class MainActivity : SimpleActivity() { private fun addFavorite() { config.addFavorite(fragment.currentPath) - invalidateOptionsMenu() } private fun removeFavorite() { config.removeFavorite(fragment.currentPath) - invalidateOptionsMenu() } private fun goToFavorite() { @@ -256,7 +254,6 @@ class MainActivity : SimpleActivity() { private fun toggleTemporarilyShowHidden(show: Boolean) { config.temporarilyShowHidden = show openPath(fragment.currentPath) - invalidateOptionsMenu() } private fun launchAbout() {