From 48ae52976241e446b3ed7ad77bba7914005dd1df Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 11 Feb 2024 10:58:42 +0100 Subject: [PATCH 1/2] Android: Update Load Wii System Menu string in onPrepareOptionsMenu Because the wording of the Load Wii System Menu string can change depending on the contents of the NAND, we should update that menu item in a method that's guaranteed to get called every time the user opens the menu rather than one that's only guaranteed to be called once. --- .../java/org/dolphinemu/dolphinemu/ui/main/MainActivity.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.kt index 84d870c921..5e601dfe2f 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.kt @@ -121,13 +121,17 @@ class MainActivity : AppCompatActivity(), MainView, OnRefreshListener, ThemeProv override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_game_grid, menu) + return true + } + + override fun onPrepareOptionsMenu(menu: Menu): Boolean { if (WiiUtils.isSystemMenuInstalled()) { val resId = if (WiiUtils.isSystemMenuvWii()) R.string.grid_menu_load_vwii_system_menu_installed else R.string.grid_menu_load_wii_system_menu_installed menu.findItem(R.id.menu_load_wii_system_menu).title = getString(resId, WiiUtils.getSystemMenuVersion()) } - return true + return super.onPrepareOptionsMenu(menu) } /** From 06964a921d32965f1434896b50fd7ed936092ea1 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 11 Feb 2024 11:15:18 +0100 Subject: [PATCH 2/2] Android: Don't check Wii Menu version before directory initialization Fixes a crash. --- .../dolphinemu/ui/main/MainActivity.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.kt index 5e601dfe2f..7f43d3094f 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.kt @@ -47,6 +47,8 @@ class MainActivity : AppCompatActivity(), MainView, OnRefreshListener, ThemeProv private lateinit var binding: ActivityMainBinding + private lateinit var menu: Menu + override fun onCreate(savedInstanceState: Bundle?) { installSplashScreen().setKeepOnScreenCondition { !DirectoryInitialization.areDolphinDirectoriesReady() } @@ -121,15 +123,22 @@ class MainActivity : AppCompatActivity(), MainView, OnRefreshListener, ThemeProv override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_game_grid, menu) + this.menu = menu return true } override fun onPrepareOptionsMenu(menu: Menu): Boolean { - if (WiiUtils.isSystemMenuInstalled()) { - val resId = - if (WiiUtils.isSystemMenuvWii()) R.string.grid_menu_load_vwii_system_menu_installed else R.string.grid_menu_load_wii_system_menu_installed - menu.findItem(R.id.menu_load_wii_system_menu).title = - getString(resId, WiiUtils.getSystemMenuVersion()) + AfterDirectoryInitializationRunner().runWithLifecycle(this) { + if (WiiUtils.isSystemMenuInstalled()) { + val resId = + if (WiiUtils.isSystemMenuvWii()) R.string.grid_menu_load_vwii_system_menu_installed else R.string.grid_menu_load_wii_system_menu_installed + + // If this callback ends up running after another call to onCreateOptionsMenu, + // we need to use the new Menu passed to the latest call of onCreateOptionsMenu. + // Therefore, we use a field here instead of the onPrepareOptionsMenu argument. + this.menu.findItem(R.id.menu_load_wii_system_menu).title = + getString(resId, WiiUtils.getSystemMenuVersion()) + } } return super.onPrepareOptionsMenu(menu) }