summaryrefslogtreecommitdiffstats
path: root/src/android
diff options
context:
space:
mode:
authorCharles Lombardo <clombardo169@gmail.com>2023-03-23 08:46:04 +0100
committerbunnei <bunneidev@gmail.com>2023-06-03 09:05:47 +0200
commit295ffd4d478e93cc1e0c4937403e47e44298beda (patch)
tree0c5175e5c26229e4d8297c78336fa27b1d9e9443 /src/android
parentandroid: Store settings object in viewmodel (diff)
downloadyuzu-295ffd4d478e93cc1e0c4937403e47e44298beda.tar
yuzu-295ffd4d478e93cc1e0c4937403e47e44298beda.tar.gz
yuzu-295ffd4d478e93cc1e0c4937403e47e44298beda.tar.bz2
yuzu-295ffd4d478e93cc1e0c4937403e47e44298beda.tar.lz
yuzu-295ffd4d478e93cc1e0c4937403e47e44298beda.tar.xz
yuzu-295ffd4d478e93cc1e0c4937403e47e44298beda.tar.zst
yuzu-295ffd4d478e93cc1e0c4937403e47e44298beda.zip
Diffstat (limited to 'src/android')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt3
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/SettingsViewModel.kt2
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt12
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.kt4
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityView.kt12
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsAdapter.kt9
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.kt26
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt59
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentView.kt17
9 files changed, 51 insertions, 93 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 b59815770..bbe0097d6 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
@@ -13,6 +13,8 @@ import java.util.*
class Settings {
private var gameId: String? = null
+ var isLoaded = false
+
/**
* A HashMap<String></String>, SettingSection> that constructs a new SettingSection instead of returning null
* when getting a key not already in the map
@@ -43,6 +45,7 @@ class Settings {
if (!TextUtils.isEmpty(gameId)) {
loadCustomGameSettings(gameId!!, view)
}
+ isLoaded = true
}
private fun loadYuzuSettings(view: SettingsActivityView) {
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/SettingsViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/SettingsViewModel.kt
index 0e33a85bb..7141604d5 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/SettingsViewModel.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/SettingsViewModel.kt
@@ -3,5 +3,5 @@ package org.yuzu.yuzu_emu.features.settings.model
import androidx.lifecycle.ViewModel
class SettingsViewModel : ViewModel() {
- var settings = Settings()
+ val settings = Settings()
}
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt
index 1683f511f..60858ecd6 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt
@@ -35,11 +35,7 @@ class SettingsActivity : AppCompatActivity(), SettingsActivityView {
private val settingsViewModel: SettingsViewModel by viewModels()
- override var settings: Settings
- get() = settingsViewModel.settings
- set(settings) {
- settingsViewModel.settings = settings
- }
+ override val settings: Settings get() = settingsViewModel.settings
override fun onCreate(savedInstanceState: Bundle?) {
ThemeHelper.setTheme(this)
@@ -179,14 +175,14 @@ class SettingsActivity : AppCompatActivity(), SettingsActivityView {
).show()
}
- override fun onSettingsFileLoaded(settings: Settings) {
+ override fun onSettingsFileLoaded() {
val fragment: SettingsFragmentView? = settingsFragment
- fragment?.onSettingsFileLoaded(settings)
+ fragment?.loadSettingsList()
}
override fun onSettingsFileNotFound() {
val fragment: SettingsFragmentView? = settingsFragment
- fragment?.loadDefaultSettings()
+ fragment?.loadSettingsList()
}
override fun showToastMessage(message: String, is_long: Boolean) {
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.kt
index 60df9d5b5..2a86e4463 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.kt
@@ -36,7 +36,7 @@ class SettingsActivityPresenter(private val activityView: SettingsActivityView)
}
private fun loadSettingsUI() {
- if (settings.isEmpty) {
+ if (!settings.isLoaded) {
if (!TextUtils.isEmpty(gameId)) {
settings.loadSettings(gameId, activityView)
} else {
@@ -44,7 +44,7 @@ class SettingsActivityPresenter(private val activityView: SettingsActivityView)
}
}
activityView.showSettingsFragment(menuTag, false, gameId)
- activityView.onSettingsFileLoaded(settings)
+ activityView.onSettingsFileLoaded()
}
private fun prepareDirectoriesIfNeeded() {
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityView.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityView.kt
index f19ca0e30..2b6dd2fce 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityView.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityView.kt
@@ -24,19 +24,17 @@ interface SettingsActivityView {
* loaded from disk, so that each Fragment doesn't need to perform its own
* read operation.
*
- * @return A possibly null HashMap of Settings.
+ * @return A HashMap of Settings.
*/
- var settings: Settings
+ val settings: Settings
/**
- * Called when an asynchronous load operation completes.
- *
- * @param settings The (possibly null) result of the ini load operation.
+ * Called when a load operation completes.
*/
- fun onSettingsFileLoaded(settings: Settings)
+ fun onSettingsFileLoaded()
/**
- * Called when an asynchronous load operation fails.
+ * Called when a load operation fails.
*/
fun onSettingsFileNotFound()
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsAdapter.kt
index 1f81f6e62..cdbdc78a0 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsAdapter.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsAdapter.kt
@@ -12,6 +12,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
+import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.android.material.dialog.MaterialAlertDialogBuilder
@@ -93,7 +94,7 @@ class SettingsAdapter(
return getItem(position).type
}
- fun setSettings(settings: ArrayList<SettingsItem>?) {
+ fun setSettingsList(settings: ArrayList<SettingsItem>?) {
this.settings = settings
notifyDataSetChanged()
}
@@ -144,7 +145,7 @@ class SettingsAdapter(
calendar.timeZone = TimeZone.getTimeZone("UTC")
var timeFormat: Int = TimeFormat.CLOCK_12H
- if (DateFormat.is24HourFormat(fragmentView.fragmentActivity)) {
+ if (DateFormat.is24HourFormat(fragmentView.activityView as AppCompatActivity)) {
timeFormat = TimeFormat.CLOCK_24H
}
@@ -161,7 +162,7 @@ class SettingsAdapter(
datePicker.addOnPositiveButtonClickListener {
timePicker.show(
- fragmentView.fragmentActivity.supportFragmentManager,
+ (fragmentView.activityView as AppCompatActivity).supportFragmentManager,
"TimePicker"
)
}
@@ -177,7 +178,7 @@ class SettingsAdapter(
item.setSelectedValue(rtcString)
clickedItem = null
}
- datePicker.show(fragmentView.fragmentActivity.supportFragmentManager, "DatePicker")
+ datePicker.show((fragmentView.activityView as AppCompatActivity).supportFragmentManager, "DatePicker")
}
fun onSliderClick(item: SliderSetting, position: Int) {
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 f522a82b7..a9cfdc21f 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
@@ -12,7 +12,6 @@ import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
-import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.divider.MaterialDividerItemDecoration
import org.yuzu.yuzu_emu.databinding.FragmentSettingsBinding
@@ -21,10 +20,9 @@ import org.yuzu.yuzu_emu.features.settings.model.Settings
import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem
class SettingsFragment : Fragment(), SettingsFragmentView {
- override lateinit var fragmentActivity: FragmentActivity
+ override var activityView: SettingsActivityView? = null
- private val presenter = SettingsFragmentPresenter(this)
- private var activityView: SettingsActivityView? = null
+ private val fragmentPresenter = SettingsFragmentPresenter(this)
private var settingsAdapter: SettingsAdapter? = null
private var _binding: FragmentSettingsBinding? = null
@@ -32,15 +30,14 @@ class SettingsFragment : Fragment(), SettingsFragmentView {
override fun onAttach(context: Context) {
super.onAttach(context)
- activityView = context as SettingsActivityView
- fragmentActivity = requireActivity()
+ activityView = requireActivity() as SettingsActivityView
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val menuTag = requireArguments().getString(ARGUMENT_MENU_TAG)
val gameId = requireArguments().getString(ARGUMENT_GAME_ID)
- presenter.onCreate(menuTag!!, gameId!!)
+ fragmentPresenter.onCreate(menuTag!!, gameId!!)
}
override fun onCreateView(
@@ -61,8 +58,7 @@ class SettingsFragment : Fragment(), SettingsFragmentView {
layoutManager = LinearLayoutManager(activity)
addItemDecoration(dividerDecoration)
}
- val activity = activity as SettingsActivityView?
- presenter.onViewCreated(activity!!.settings)
+ fragmentPresenter.onViewCreated()
setInsets()
}
@@ -75,16 +71,12 @@ class SettingsFragment : Fragment(), SettingsFragmentView {
}
}
- override fun onSettingsFileLoaded(settings: Settings) {
- presenter.setSettings(settings)
- }
-
override fun showSettingsList(settingsList: ArrayList<SettingsItem>) {
- settingsAdapter!!.setSettings(settingsList)
+ settingsAdapter!!.setSettingsList(settingsList)
}
- override fun loadDefaultSettings() {
- presenter.loadDefaultSettings()
+ override fun loadSettingsList() {
+ fragmentPresenter.loadSettingsList()
}
override fun loadSubMenu(menuKey: String) {
@@ -100,7 +92,7 @@ class SettingsFragment : Fragment(), SettingsFragmentView {
}
override fun putSetting(setting: Setting) {
- presenter.putSetting(setting)
+ fragmentPresenter.putSetting(setting)
}
override fun onSettingChanged() {
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 8eaa0a0fa..e2b1326f8 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
@@ -4,58 +4,37 @@
package org.yuzu.yuzu_emu.features.settings.ui
import android.text.TextUtils
+import androidx.appcompat.app.AppCompatActivity
import org.yuzu.yuzu_emu.R
import org.yuzu.yuzu_emu.features.settings.model.Setting
import org.yuzu.yuzu_emu.features.settings.model.Settings
-import org.yuzu.yuzu_emu.features.settings.model.StringSetting
import org.yuzu.yuzu_emu.features.settings.model.view.*
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) {
private var menuTag: String? = null
private lateinit var gameId: String
- private var settings: Settings? = null
private var settingsList: ArrayList<SettingsItem>? = null
+ private val settingsActivity get() = fragmentView.activityView as AppCompatActivity
+ private val settings get() = fragmentView.activityView!!.settings
+
fun onCreate(menuTag: String, gameId: String) {
this.gameId = gameId
this.menuTag = menuTag
}
- fun onViewCreated(settings: Settings) {
- setSettings(settings)
- }
-
- fun putSetting(setting: Setting) {
- settings!!.getSection(setting.section)!!.putSetting(setting)
- }
-
- private fun asStringSetting(setting: Setting?): StringSetting? {
- if (setting == null) {
- return null
- }
- val stringSetting = StringSetting(setting.key, setting.section, setting.valueAsString)
- putSetting(stringSetting)
- return stringSetting
- }
-
- fun loadDefaultSettings() {
+ fun onViewCreated() {
loadSettingsList()
}
- fun setSettings(settings: Settings) {
- if (settingsList == null) {
- this.settings = settings
- loadSettingsList()
- } else {
- fragmentView.fragmentActivity.setTitle(R.string.preferences_settings)
- fragmentView.showSettingsList(settingsList!!)
- }
+ fun putSetting(setting: Setting) {
+ settings.getSection(setting.section)!!.putSetting(setting)
}
- private fun loadSettingsList() {
+ fun loadSettingsList() {
if (!TextUtils.isEmpty(gameId)) {
- fragmentView.fragmentActivity.title = "Game Settings: $gameId"
+ settingsActivity.title = "Game Settings: $gameId"
}
val sl = ArrayList<SettingsItem>()
if (menuTag == null) {
@@ -77,7 +56,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
}
private fun addConfigSettings(sl: ArrayList<SettingsItem>) {
- fragmentView.fragmentActivity.setTitle(R.string.preferences_settings)
+ settingsActivity.setTitle(R.string.preferences_settings)
sl.apply {
add(
SubmenuSetting(
@@ -119,12 +98,12 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
}
private fun addGeneralSettings(sl: ArrayList<SettingsItem>) {
- fragmentView.fragmentActivity.setTitle(R.string.preferences_general)
- val rendererSection = settings!!.getSection(Settings.SECTION_RENDERER)
+ settingsActivity.setTitle(R.string.preferences_general)
+ val rendererSection = settings.getSection(Settings.SECTION_RENDERER)
val frameLimitEnable =
rendererSection!!.getSetting(SettingsFile.KEY_RENDERER_USE_SPEED_LIMIT)
val frameLimitValue = rendererSection.getSetting(SettingsFile.KEY_RENDERER_SPEED_LIMIT)
- val cpuSection = settings!!.getSection(Settings.SECTION_CPU)
+ val cpuSection = settings.getSection(Settings.SECTION_CPU)
val cpuAccuracy = cpuSection!!.getSetting(SettingsFile.KEY_CPU_ACCURACY)
sl.apply {
add(
@@ -166,8 +145,8 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
}
private fun addSystemSettings(sl: ArrayList<SettingsItem>) {
- fragmentView.fragmentActivity.setTitle(R.string.preferences_system)
- val systemSection = settings!!.getSection(Settings.SECTION_SYSTEM)
+ settingsActivity.setTitle(R.string.preferences_system)
+ val systemSection = settings.getSection(Settings.SECTION_SYSTEM)
val dockedMode = systemSection!!.getSetting(SettingsFile.KEY_USE_DOCKED_MODE)
val region = systemSection.getSetting(SettingsFile.KEY_REGION_INDEX)
val language = systemSection.getSetting(SettingsFile.KEY_LANGUAGE_INDEX)
@@ -210,8 +189,8 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
}
private fun addGraphicsSettings(sl: ArrayList<SettingsItem>) {
- fragmentView.fragmentActivity.setTitle(R.string.preferences_graphics)
- val rendererSection = settings!!.getSection(Settings.SECTION_RENDERER)
+ settingsActivity.setTitle(R.string.preferences_graphics)
+ val rendererSection = settings.getSection(Settings.SECTION_RENDERER)
val rendererBackend = rendererSection!!.getSetting(SettingsFile.KEY_RENDERER_BACKEND)
val rendererAccuracy = rendererSection.getSetting(SettingsFile.KEY_RENDERER_ACCURACY)
val rendererResolution = rendererSection.getSetting(SettingsFile.KEY_RENDERER_RESOLUTION)
@@ -305,8 +284,8 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
}
private fun addAudioSettings(sl: ArrayList<SettingsItem>) {
- fragmentView.fragmentActivity.setTitle(R.string.preferences_audio)
- val audioSection = settings!!.getSection(Settings.SECTION_AUDIO)
+ settingsActivity.setTitle(R.string.preferences_audio)
+ val audioSection = settings.getSection(Settings.SECTION_AUDIO)
val audioVolume = audioSection!!.getSetting(SettingsFile.KEY_AUDIO_VOLUME)
sl.add(
SliderSetting(
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentView.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentView.kt
index 2d9700fca..9a14c5795 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentView.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentView.kt
@@ -3,9 +3,7 @@
package org.yuzu.yuzu_emu.features.settings.ui
-import androidx.fragment.app.FragmentActivity
import org.yuzu.yuzu_emu.features.settings.model.Setting
-import org.yuzu.yuzu_emu.features.settings.model.Settings
import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem
/**
@@ -14,14 +12,6 @@ import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem
*/
interface SettingsFragmentView {
/**
- * Called by the containing Activity to notify the Fragment that an
- * asynchronous load operation completed.
- *
- * @param settings The (possibly null) result of the ini load operation.
- */
- fun onSettingsFileLoaded(settings: Settings)
-
- /**
* Pass an ArrayList to the View so that it can be displayed on screen.
*
* @param settingsList The result of converting the HashMap to an ArrayList
@@ -29,15 +19,14 @@ interface SettingsFragmentView {
fun showSettingsList(settingsList: ArrayList<SettingsItem>)
/**
- * Called by the containing Activity when an asynchronous load operation fails.
- * Instructs the Fragment to load the settings screen with defaults selected.
+ * Instructs the Fragment to load the settings screen.
*/
- fun loadDefaultSettings()
+ fun loadSettingsList()
/**
* @return The Fragment's containing activity.
*/
- val fragmentActivity: FragmentActivity
+ val activityView: SettingsActivityView?
/**
* Tell the Fragment to tell the containing Activity to show a new