From c070a588b9ee286d2b5844b615e53026e8e5bd5a Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Thu, 27 Apr 2023 22:59:01 -0400 Subject: android: Change organization of the settings tab in the home screen --- .../yuzu/yuzu_emu/adapters/HomeOptionAdapter.kt | 55 --------- .../yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt | 55 +++++++++ .../yuzu_emu/fragments/HomeSettingsFragment.kt | 123 +++++++++++++++++++++ .../org/yuzu/yuzu_emu/fragments/OptionsFragment.kt | 123 --------------------- .../java/org/yuzu/yuzu_emu/model/HomeOption.kt | 11 -- .../java/org/yuzu/yuzu_emu/model/HomeSetting.kt | 11 ++ .../src/main/res/layout/fragment_home_settings.xml | 30 +++++ .../app/src/main/res/layout/fragment_options.xml | 30 ----- .../app/src/main/res/menu/menu_navigation.xml | 6 +- .../src/main/res/navigation/home_navigation.xml | 6 +- src/android/app/src/main/res/values/strings.xml | 4 +- 11 files changed, 227 insertions(+), 227 deletions(-) delete mode 100644 src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeOptionAdapter.kt create mode 100644 src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt create mode 100644 src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt delete mode 100644 src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/OptionsFragment.kt delete mode 100644 src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeOption.kt create mode 100644 src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeSetting.kt create mode 100644 src/android/app/src/main/res/layout/fragment_home_settings.xml delete mode 100644 src/android/app/src/main/res/layout/fragment_options.xml diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeOptionAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeOptionAdapter.kt deleted file mode 100644 index 2bec2de87..000000000 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeOptionAdapter.kt +++ /dev/null @@ -1,55 +0,0 @@ -package org.yuzu.yuzu_emu.adapters - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.appcompat.app.AppCompatActivity -import androidx.core.content.res.ResourcesCompat -import androidx.recyclerview.widget.RecyclerView -import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding -import org.yuzu.yuzu_emu.model.HomeOption - -class HomeOptionAdapter(private val activity: AppCompatActivity, var options: List) : - RecyclerView.Adapter(), - View.OnClickListener { - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder { - val binding = CardHomeOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false) - binding.root.setOnClickListener(this) - return HomeOptionViewHolder(binding) - } - - override fun getItemCount(): Int { - return options.size - } - - override fun onBindViewHolder(holder: HomeOptionViewHolder, position: Int) { - holder.bind(options[position]) - } - - override fun onClick(view: View) { - val holder = view.tag as HomeOptionViewHolder - holder.option.onClick.invoke() - } - - inner class HomeOptionViewHolder(val binding: CardHomeOptionBinding) : - RecyclerView.ViewHolder(binding.root) { - lateinit var option: HomeOption - - init { - itemView.tag = this - } - - fun bind(option: HomeOption) { - this.option = option - binding.optionTitle.text = activity.resources.getString(option.titleId) - binding.optionDescription.text = activity.resources.getString(option.descriptionId) - binding.optionIcon.setImageDrawable( - ResourcesCompat.getDrawable( - activity.resources, - option.iconId, - activity.theme - ) - ) - } - } -} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt new file mode 100644 index 000000000..2b3956e6d --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt @@ -0,0 +1,55 @@ +package org.yuzu.yuzu_emu.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.res.ResourcesCompat +import androidx.recyclerview.widget.RecyclerView +import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding +import org.yuzu.yuzu_emu.model.HomeSetting + +class HomeSettingAdapter(private val activity: AppCompatActivity, var options: List) : + RecyclerView.Adapter(), + View.OnClickListener { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder { + val binding = CardHomeOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false) + binding.root.setOnClickListener(this) + return HomeOptionViewHolder(binding) + } + + override fun getItemCount(): Int { + return options.size + } + + override fun onBindViewHolder(holder: HomeOptionViewHolder, position: Int) { + holder.bind(options[position]) + } + + override fun onClick(view: View) { + val holder = view.tag as HomeOptionViewHolder + holder.option.onClick.invoke() + } + + inner class HomeOptionViewHolder(val binding: CardHomeOptionBinding) : + RecyclerView.ViewHolder(binding.root) { + lateinit var option: HomeSetting + + init { + itemView.tag = this + } + + fun bind(option: HomeSetting) { + this.option = option + binding.optionTitle.text = activity.resources.getString(option.titleId) + binding.optionDescription.text = activity.resources.getString(option.descriptionId) + binding.optionIcon.setImageDrawable( + ResourcesCompat.getDrawable( + activity.resources, + option.iconId, + activity.theme + ) + ) + } + } +} 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 new file mode 100644 index 000000000..aba2a188e --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt @@ -0,0 +1,123 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.yuzu.yuzu_emu.fragments + +import android.content.DialogInterface +import android.content.Intent +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import androidx.fragment.app.Fragment +import androidx.recyclerview.widget.LinearLayoutManager +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import org.yuzu.yuzu_emu.R +import org.yuzu.yuzu_emu.adapters.HomeSettingAdapter +import org.yuzu.yuzu_emu.databinding.FragmentHomeSettingsBinding +import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity +import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile +import org.yuzu.yuzu_emu.model.HomeSetting +import org.yuzu.yuzu_emu.ui.main.MainActivity +import org.yuzu.yuzu_emu.utils.GpuDriverHelper + +class HomeSettingsFragment : Fragment() { + private var _binding: FragmentHomeSettingsBinding? = null + private val binding get() = _binding!! + + private lateinit var mainActivity: MainActivity + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = FragmentHomeSettingsBinding.inflate(layoutInflater) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + mainActivity = requireActivity() as MainActivity + + val optionsList: List = listOf( + HomeSetting( + R.string.advanced_settings, + R.string.settings_description, + R.drawable.ic_settings + ) { SettingsActivity.launch(requireContext(), SettingsFile.FILE_NAME_CONFIG, "") }, + HomeSetting( + R.string.install_gpu_driver, + R.string.install_gpu_driver_description, + R.drawable.ic_input + ) { driverInstaller() }, + HomeSetting( + R.string.install_amiibo_keys, + R.string.install_amiibo_keys_description, + R.drawable.ic_nfc + ) { mainActivity.getAmiiboKey.launch(arrayOf("*/*")) }, + HomeSetting( + R.string.add_games, + R.string.add_games_description, + R.drawable.ic_add + ) { mainActivity.getGamesDirectory.launch(Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).data) }, + HomeSetting( + R.string.install_prod_keys, + R.string.install_prod_keys_description, + R.drawable.ic_unlock + ) { mainActivity.getProdKey.launch(arrayOf("*/*")) } + ) + + binding.homeSettingsList.apply { + layoutManager = LinearLayoutManager(requireContext()) + adapter = HomeSettingAdapter(requireActivity() as AppCompatActivity, optionsList) + } + + setInsets() + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } + + private fun driverInstaller() { + // Get the driver name for the dialog message. + var driverName = GpuDriverHelper.customDriverName + if (driverName == null) { + driverName = getString(R.string.system_gpu_driver) + } + + MaterialAlertDialogBuilder(requireContext()) + .setTitle(getString(R.string.select_gpu_driver_title)) + .setMessage(driverName) + .setNegativeButton(android.R.string.cancel, null) + .setPositiveButton(R.string.select_gpu_driver_default) { _: DialogInterface?, _: Int -> + GpuDriverHelper.installDefaultDriver(requireContext()) + Toast.makeText( + requireContext(), + R.string.select_gpu_driver_use_default, + Toast.LENGTH_SHORT + ).show() + } + .setNeutralButton(R.string.select_gpu_driver_install) { _: DialogInterface?, _: Int -> + mainActivity.getDriver.launch(arrayOf("application/zip")) + } + .show() + } + + private fun setInsets() = + ViewCompat.setOnApplyWindowInsetsListener(binding.scrollViewSettings) { view: View, windowInsets: WindowInsetsCompat -> + val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) + view.setPadding( + insets.left, + insets.top, + insets.right, + insets.bottom + resources.getDimensionPixelSize(R.dimen.spacing_navigation) + ) + windowInsets + } +} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/OptionsFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/OptionsFragment.kt deleted file mode 100644 index 1cf0d0f52..000000000 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/OptionsFragment.kt +++ /dev/null @@ -1,123 +0,0 @@ -// SPDX-FileCopyrightText: 2023 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.yuzu.yuzu_emu.fragments - -import android.content.DialogInterface -import android.content.Intent -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.Toast -import androidx.appcompat.app.AppCompatActivity -import androidx.core.view.ViewCompat -import androidx.core.view.WindowInsetsCompat -import androidx.fragment.app.Fragment -import androidx.recyclerview.widget.LinearLayoutManager -import com.google.android.material.dialog.MaterialAlertDialogBuilder -import org.yuzu.yuzu_emu.R -import org.yuzu.yuzu_emu.adapters.HomeOptionAdapter -import org.yuzu.yuzu_emu.databinding.FragmentOptionsBinding -import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity -import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile -import org.yuzu.yuzu_emu.model.HomeOption -import org.yuzu.yuzu_emu.ui.main.MainActivity -import org.yuzu.yuzu_emu.utils.GpuDriverHelper - -class OptionsFragment : Fragment() { - private var _binding: FragmentOptionsBinding? = null - private val binding get() = _binding!! - - private lateinit var mainActivity: MainActivity - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - _binding = FragmentOptionsBinding.inflate(layoutInflater) - return binding.root - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - mainActivity = requireActivity() as MainActivity - - val optionsList: List = listOf( - HomeOption( - R.string.add_games, - R.string.add_games_description, - R.drawable.ic_add - ) { mainActivity.getGamesDirectory.launch(Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).data) }, - HomeOption( - R.string.install_prod_keys, - R.string.install_prod_keys_description, - R.drawable.ic_unlock - ) { mainActivity.getProdKey.launch(arrayOf("*/*")) }, - HomeOption( - R.string.install_amiibo_keys, - R.string.install_amiibo_keys_description, - R.drawable.ic_nfc - ) { mainActivity.getAmiiboKey.launch(arrayOf("*/*")) }, - HomeOption( - R.string.install_gpu_driver, - R.string.install_gpu_driver_description, - R.drawable.ic_input - ) { driverInstaller() }, - HomeOption( - R.string.settings, - R.string.settings_description, - R.drawable.ic_settings - ) { SettingsActivity.launch(requireContext(), SettingsFile.FILE_NAME_CONFIG, "") } - ) - - binding.optionsList.apply { - layoutManager = LinearLayoutManager(requireContext()) - adapter = HomeOptionAdapter(requireActivity() as AppCompatActivity, optionsList) - } - - setInsets() - } - - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - - private fun driverInstaller() { - // Get the driver name for the dialog message. - var driverName = GpuDriverHelper.customDriverName - if (driverName == null) { - driverName = getString(R.string.system_gpu_driver) - } - - MaterialAlertDialogBuilder(requireContext()) - .setTitle(getString(R.string.select_gpu_driver_title)) - .setMessage(driverName) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(R.string.select_gpu_driver_default) { _: DialogInterface?, _: Int -> - GpuDriverHelper.installDefaultDriver(requireContext()) - Toast.makeText( - requireContext(), - R.string.select_gpu_driver_use_default, - Toast.LENGTH_SHORT - ).show() - } - .setNeutralButton(R.string.select_gpu_driver_install) { _: DialogInterface?, _: Int -> - mainActivity.getDriver.launch(arrayOf("application/zip")) - } - .show() - } - - private fun setInsets() = - ViewCompat.setOnApplyWindowInsetsListener(binding.scrollViewOptions) { view: View, windowInsets: WindowInsetsCompat -> - val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) - view.setPadding( - insets.left, - insets.top, - insets.right, - insets.bottom + resources.getDimensionPixelSize(R.dimen.spacing_navigation) - ) - windowInsets - } -} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeOption.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeOption.kt deleted file mode 100644 index c995ff12c..000000000 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeOption.kt +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-FileCopyrightText: 2023 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.yuzu.yuzu_emu.model - -data class HomeOption( - val titleId: Int, - val descriptionId: Int, - val iconId: Int, - val onClick: () -> Unit -) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeSetting.kt new file mode 100644 index 000000000..7049f2fa5 --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeSetting.kt @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.yuzu.yuzu_emu.model + +data class HomeSetting( + val titleId: Int, + val descriptionId: Int, + val iconId: Int, + val onClick: () -> Unit +) diff --git a/src/android/app/src/main/res/layout/fragment_home_settings.xml b/src/android/app/src/main/res/layout/fragment_home_settings.xml new file mode 100644 index 000000000..e0c609309 --- /dev/null +++ b/src/android/app/src/main/res/layout/fragment_home_settings.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/src/android/app/src/main/res/layout/fragment_options.xml b/src/android/app/src/main/res/layout/fragment_options.xml deleted file mode 100644 index 3bae8b0c4..000000000 --- a/src/android/app/src/main/res/layout/fragment_options.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - diff --git a/src/android/app/src/main/res/menu/menu_navigation.xml b/src/android/app/src/main/res/menu/menu_navigation.xml index ca5a656a6..e46133604 100644 --- a/src/android/app/src/main/res/menu/menu_navigation.xml +++ b/src/android/app/src/main/res/menu/menu_navigation.xml @@ -7,8 +7,8 @@ android:title="@string/home_games" /> + android:id="@+id/homeSettingsFragment" + android:icon="@drawable/ic_settings" + android:title="@string/home_settings" /> 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 d0077bbea..d500d165b 100644 --- a/src/android/app/src/main/res/navigation/home_navigation.xml +++ b/src/android/app/src/main/res/navigation/home_navigation.xml @@ -10,9 +10,9 @@ android:label="PlatformGamesFragment" /> + android:id="@+id/homeSettingsFragment" + android:name="org.yuzu.yuzu_emu.fragments.HomeSettingsFragment" + android:label="HomeSettingsFragment" /> Games - Options + Settings Add Games Select your games folder Search Games @@ -41,7 +41,7 @@ Keys file (key_retail.bin) is invalid Install GPU Driver Use a different driver for potentially better performance or accuracy - Settings + Advanced Settings Configure emulator settings -- cgit v1.2.3