From 8baed5d95d27c9947b1bf3ef6cb39c4344f47486 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Thu, 14 Sep 2023 15:05:44 -0400 Subject: [PATCH] android: Refactor menu tags to enum --- .../features/settings/model/Settings.kt | 11 +++++ .../settings/model/view/SubmenuSetting.kt | 4 +- .../features/settings/ui/SettingsFragment.kt | 10 +++-- .../settings/ui/SettingsFragmentPresenter.kt | 45 ++++++------------- .../yuzu_emu/fragments/EmulationFragment.kt | 3 +- .../fragments/HomeSettingsFragment.kt | 5 +-- .../org/yuzu/yuzu_emu/ui/main/MainActivity.kt | 3 +- .../main/res/navigation/home_navigation.xml | 2 +- .../res/navigation/settings_navigation.xml | 2 +- 9 files changed, 39 insertions(+), 46 deletions(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt index 0702236e81..08e2a973db 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt @@ -80,6 +80,17 @@ object Settings { const val SECTION_THEME = "Theme" const val SECTION_DEBUG = "Debug" + enum class MenuTag(val titleId: Int) { + SECTION_ROOT(R.string.advanced_settings), + SECTION_GENERAL(R.string.preferences_general), + SECTION_SYSTEM(R.string.preferences_system), + SECTION_RENDERER(R.string.preferences_graphics), + SECTION_AUDIO(R.string.preferences_audio), + SECTION_CPU(R.string.cpu), + SECTION_THEME(R.string.preferences_theme), + SECTION_DEBUG(R.string.preferences_debug); + } + const val PREF_MEMORY_WARNING_SHOWN = "MemoryWarningShown" const val PREF_OVERLAY_VERSION = "OverlayVersion" diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SubmenuSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SubmenuSetting.kt index 91c273964a..b343e527ef 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SubmenuSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SubmenuSetting.kt @@ -3,10 +3,12 @@ package org.yuzu.yuzu_emu.features.settings.model.view +import org.yuzu.yuzu_emu.features.settings.model.Settings + class SubmenuSetting( titleId: Int, descriptionId: Int, - val menuKey: String + val menuKey: Settings.MenuTag ) : SettingsItem(emptySetting, titleId, descriptionId) { override val type = TYPE_SUBMENU } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.kt index 2a816183ab..70d8ec14bb 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.kt @@ -3,6 +3,7 @@ package org.yuzu.yuzu_emu.features.settings.ui +import android.annotation.SuppressLint import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -21,10 +22,11 @@ import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.divider.MaterialDividerItemDecoration import com.google.android.material.transition.MaterialSharedAxis +import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import org.yuzu.yuzu_emu.R import org.yuzu.yuzu_emu.databinding.FragmentSettingsBinding -import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile +import org.yuzu.yuzu_emu.features.settings.model.Settings import org.yuzu.yuzu_emu.model.SettingsViewModel class SettingsFragment : Fragment() { @@ -62,10 +64,10 @@ class SettingsFragment : Fragment() { presenter = SettingsFragmentPresenter( settingsViewModel, settingsAdapter!!, - args.menuTag, - args.game?.gameId ?: "" + args.menuTag ) + binding.toolbarSettingsLayout.title = getString(args.menuTag.titleId) val dividerDecoration = MaterialDividerItemDecoration( requireContext(), LinearLayoutManager.VERTICAL @@ -105,7 +107,7 @@ class SettingsFragment : Fragment() { } } - if (args.menuTag == SettingsFile.FILE_NAME_CONFIG) { + if (args.menuTag == Settings.MenuTag.SECTION_ROOT) { binding.toolbarSettings.inflateMenu(R.menu.menu_settings) binding.toolbarSettings.setOnMenuItemClickListener { when (it.itemId) { diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt index 22a529b1ba..766414a6c8 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt @@ -6,7 +6,6 @@ package org.yuzu.yuzu_emu.features.settings.ui import android.content.Context import android.content.SharedPreferences import android.os.Build -import android.text.TextUtils import android.widget.Toast import androidx.preference.PreferenceManager import org.yuzu.yuzu_emu.R @@ -20,15 +19,13 @@ import org.yuzu.yuzu_emu.features.settings.model.LongSetting import org.yuzu.yuzu_emu.features.settings.model.Settings import org.yuzu.yuzu_emu.features.settings.model.ShortSetting import org.yuzu.yuzu_emu.features.settings.model.view.* -import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile import org.yuzu.yuzu_emu.model.SettingsViewModel import org.yuzu.yuzu_emu.utils.NativeConfig class SettingsFragmentPresenter( private val settingsViewModel: SettingsViewModel, private val adapter: SettingsAdapter, - private var menuTag: String, - private var gameId: String + private var menuTag: Settings.MenuTag ) { private var settingsList = ArrayList() @@ -53,24 +50,15 @@ class SettingsFragmentPresenter( } fun loadSettingsList() { - if (!TextUtils.isEmpty(gameId)) { - settingsViewModel.setToolbarTitle( - context.getString( - R.string.advanced_settings_game, - gameId - ) - ) - } - val sl = ArrayList() when (menuTag) { - SettingsFile.FILE_NAME_CONFIG -> addConfigSettings(sl) - Settings.SECTION_GENERAL -> addGeneralSettings(sl) - Settings.SECTION_SYSTEM -> addSystemSettings(sl) - Settings.SECTION_RENDERER -> addGraphicsSettings(sl) - Settings.SECTION_AUDIO -> addAudioSettings(sl) - Settings.SECTION_THEME -> addThemeSettings(sl) - Settings.SECTION_DEBUG -> addDebugSettings(sl) + Settings.MenuTag.SECTION_ROOT -> addConfigSettings(sl) + Settings.MenuTag.SECTION_GENERAL -> addGeneralSettings(sl) + Settings.MenuTag.SECTION_SYSTEM -> addSystemSettings(sl) + Settings.MenuTag.SECTION_RENDERER -> addGraphicsSettings(sl) + Settings.MenuTag.SECTION_AUDIO -> addAudioSettings(sl) + Settings.MenuTag.SECTION_THEME -> addThemeSettings(sl) + Settings.MenuTag.SECTION_DEBUG -> addDebugSettings(sl) else -> { val context = YuzuApplication.appContext Toast.makeText( @@ -86,13 +74,12 @@ class SettingsFragmentPresenter( } private fun addConfigSettings(sl: ArrayList) { - settingsViewModel.setToolbarTitle(context.getString(R.string.advanced_settings)) sl.apply { - add(SubmenuSetting(R.string.preferences_general, 0, Settings.SECTION_GENERAL)) - add(SubmenuSetting(R.string.preferences_system, 0, Settings.SECTION_SYSTEM)) - add(SubmenuSetting(R.string.preferences_graphics, 0, Settings.SECTION_RENDERER)) - add(SubmenuSetting(R.string.preferences_audio, 0, Settings.SECTION_AUDIO)) - add(SubmenuSetting(R.string.preferences_debug, 0, Settings.SECTION_DEBUG)) + add(SubmenuSetting(R.string.preferences_general, 0, Settings.MenuTag.SECTION_GENERAL)) + add(SubmenuSetting(R.string.preferences_system, 0, Settings.MenuTag.SECTION_SYSTEM)) + add(SubmenuSetting(R.string.preferences_graphics, 0, Settings.MenuTag.SECTION_RENDERER)) + add(SubmenuSetting(R.string.preferences_audio, 0, Settings.MenuTag.SECTION_AUDIO)) + add(SubmenuSetting(R.string.preferences_debug, 0, Settings.MenuTag.SECTION_DEBUG)) add( RunnableSetting(R.string.reset_to_default, 0, false) { settingsViewModel.setShouldShowResetSettingsDialog(true) @@ -102,7 +89,6 @@ class SettingsFragmentPresenter( } private fun addGeneralSettings(sl: ArrayList) { - settingsViewModel.setToolbarTitle(context.getString(R.string.preferences_general)) sl.apply { add(BooleanSetting.RENDERER_USE_SPEED_LIMIT.key) add(ShortSetting.RENDERER_SPEED_LIMIT.key) @@ -112,7 +98,6 @@ class SettingsFragmentPresenter( } private fun addSystemSettings(sl: ArrayList) { - settingsViewModel.setToolbarTitle(context.getString(R.string.preferences_system)) sl.apply { add(BooleanSetting.USE_DOCKED_MODE.key) add(IntSetting.REGION_INDEX.key) @@ -123,7 +108,6 @@ class SettingsFragmentPresenter( } private fun addGraphicsSettings(sl: ArrayList) { - settingsViewModel.setToolbarTitle(context.getString(R.string.preferences_graphics)) sl.apply { add(IntSetting.RENDERER_ACCURACY.key) add(IntSetting.RENDERER_RESOLUTION.key) @@ -140,7 +124,6 @@ class SettingsFragmentPresenter( } private fun addAudioSettings(sl: ArrayList) { - settingsViewModel.setToolbarTitle(context.getString(R.string.preferences_audio)) sl.apply { add(IntSetting.AUDIO_OUTPUT_ENGINE.key) add(ByteSetting.AUDIO_VOLUME.key) @@ -148,7 +131,6 @@ class SettingsFragmentPresenter( } private fun addThemeSettings(sl: ArrayList) { - settingsViewModel.setToolbarTitle(context.getString(R.string.preferences_theme)) sl.apply { val theme: AbstractIntSetting = object : AbstractIntSetting { override val int: Int @@ -261,7 +243,6 @@ class SettingsFragmentPresenter( } private fun addDebugSettings(sl: ArrayList) { - settingsViewModel.setToolbarTitle(context.getString(R.string.preferences_debug)) sl.apply { add(HeaderSetting(R.string.gpu)) add(IntSetting.RENDERER_BACKEND.key) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt index 1addb23265..3e6c157c7f 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt @@ -50,7 +50,6 @@ import org.yuzu.yuzu_emu.databinding.DialogOverlayAdjustBinding import org.yuzu.yuzu_emu.databinding.FragmentEmulationBinding import org.yuzu.yuzu_emu.features.settings.model.IntSetting import org.yuzu.yuzu_emu.features.settings.model.Settings -import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile import org.yuzu.yuzu_emu.model.Game import org.yuzu.yuzu_emu.model.EmulationViewModel import org.yuzu.yuzu_emu.overlay.InputOverlay @@ -166,7 +165,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { R.id.menu_settings -> { val action = HomeNavigationDirections.actionGlobalSettingsActivity( null, - SettingsFile.FILE_NAME_CONFIG + Settings.MenuTag.SECTION_ROOT ) binding.root.findNavController().navigate(action) true diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt index cbbe14d220..c119e69c97 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt @@ -37,7 +37,6 @@ import org.yuzu.yuzu_emu.adapters.HomeSettingAdapter import org.yuzu.yuzu_emu.databinding.FragmentHomeSettingsBinding import org.yuzu.yuzu_emu.features.DocumentProvider import org.yuzu.yuzu_emu.features.settings.model.Settings -import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile import org.yuzu.yuzu_emu.model.HomeSetting import org.yuzu.yuzu_emu.model.HomeViewModel import org.yuzu.yuzu_emu.ui.main.MainActivity @@ -78,7 +77,7 @@ class HomeSettingsFragment : Fragment() { { val action = HomeNavigationDirections.actionGlobalSettingsActivity( null, - SettingsFile.FILE_NAME_CONFIG + Settings.MenuTag.SECTION_ROOT ) binding.root.findNavController().navigate(action) } @@ -100,7 +99,7 @@ class HomeSettingsFragment : Fragment() { { val action = HomeNavigationDirections.actionGlobalSettingsActivity( null, - Settings.SECTION_THEME + Settings.MenuTag.SECTION_THEME ) binding.root.findNavController().navigate(action) } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt index 1ee833cf63..b6b6c6c171 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt @@ -42,7 +42,6 @@ import org.yuzu.yuzu_emu.activities.EmulationActivity import org.yuzu.yuzu_emu.databinding.ActivityMainBinding import org.yuzu.yuzu_emu.databinding.DialogProgressBarBinding import org.yuzu.yuzu_emu.features.settings.model.Settings -import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile import org.yuzu.yuzu_emu.fragments.IndeterminateProgressDialogFragment import org.yuzu.yuzu_emu.fragments.MessageDialogFragment import org.yuzu.yuzu_emu.model.GamesViewModel @@ -109,7 +108,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider { R.id.homeSettingsFragment -> { val action = HomeNavigationDirections.actionGlobalSettingsActivity( null, - SettingsFile.FILE_NAME_CONFIG + Settings.MenuTag.SECTION_ROOT ) navHostFragment.navController.navigate(action) } diff --git a/src/android/app/src/main/res/navigation/home_navigation.xml b/src/android/app/src/main/res/navigation/home_navigation.xml index 2085430bf8..2e0ce7a3dc 100644 --- a/src/android/app/src/main/res/navigation/home_navigation.xml +++ b/src/android/app/src/main/res/navigation/home_navigation.xml @@ -82,7 +82,7 @@ app:nullable="true" /> + app:argType="org.yuzu.yuzu_emu.features.settings.model.Settings$MenuTag" /> + app:argType="org.yuzu.yuzu_emu.features.settings.model.Settings$MenuTag" />