From 9c8bf5a16b6b7526d35b48dfd89077428ee5533c Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 28 Aug 2019 15:26:02 +0200 Subject: [PATCH] properly handle menu item color updating --- .../pro/activities/FavoritesActivity.kt | 27 ++++++++++--------- .../pro/activities/MainActivity.kt | 6 +++++ .../pro/activities/ReadTextActivity.kt | 1 + .../pro/activities/SettingsActivity.kt | 7 +++++ 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/FavoritesActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/FavoritesActivity.kt index 8c7169a2..c0a35164 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/FavoritesActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/FavoritesActivity.kt @@ -20,6 +20,20 @@ class FavoritesActivity : SimpleActivity(), RefreshRecyclerViewListener { updateFavorites() } + override fun onCreateOptionsMenu(menu: Menu?): Boolean { + menuInflater.inflate(R.menu.menu_favorites, menu) + updateMenuItemColors(menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.add_favorite -> addFavorite() + else -> return super.onOptionsItemSelected(item) + } + return true + } + private fun updateFavorites() { val favorites = ArrayList() config.favorites.mapTo(favorites) { it } @@ -40,19 +54,6 @@ class FavoritesActivity : SimpleActivity(), RefreshRecyclerViewListener { } } - override fun onCreateOptionsMenu(menu: Menu?): Boolean { - menuInflater.inflate(R.menu.menu_favorites, menu) - return true - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - when (item.itemId) { - R.id.add_favorite -> addFavorite() - else -> return super.onOptionsItemSelected(item) - } - return true - } - override fun refreshItems() { updateFavorites() } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt index 03ed2948..6e6ecbad 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt @@ -71,6 +71,11 @@ class MainActivity : SimpleActivity() { } } + override fun onResume() { + super.onResume() + invalidateOptionsMenu() + } + override fun onStop() { super.onStop() searchMenuItem?.collapseActionView() @@ -84,6 +89,7 @@ class MainActivity : SimpleActivity() { override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu, menu) setupSearch(menu) + updateMenuItemColors(menu) return true } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/ReadTextActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/ReadTextActivity.kt index cd0714f3..a14323ef 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/ReadTextActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/ReadTextActivity.kt @@ -52,6 +52,7 @@ class ReadTextActivity : SimpleActivity() { override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_editor, menu) setupSearch(menu) + updateMenuItemColors(menu) return true } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SettingsActivity.kt index 1dffad71..30095a86 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SettingsActivity.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.filemanager.pro.activities import android.content.Intent import android.os.Bundle +import android.view.Menu import com.simplemobiletools.commons.dialogs.ChangeDateTimeFormatDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.SecurityDialog @@ -39,6 +40,12 @@ class SettingsActivity : SimpleActivity() { setupEnableRootAccess() updateTextColors(settings_holder) setupSectionColors() + invalidateOptionsMenu() + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + updateMenuItemColors(menu) + return super.onCreateOptionsMenu(menu) } private fun setupSectionColors() {