@ -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 onViewCreated ( ) {
loadSettingsList( )
}
fun putSetting ( setting : Setting ) {
settings !! . getSection ( setting . section ) !! . putSetting ( 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 ( ) {
loadSettingsList ( )
}
fun setSettings ( settings : Settings ) {
if ( settingsList == null ) {
this . settings = settings
loadSettingsList ( )
} else {
fragmentView . fragmentActivity . setTitle ( R . string . preferences _settings )
fragmentView . showSettingsList ( settingsList !! )
}
}
private fun loadSettingsList ( ) {
fun loadSettingsList ( ) {
if ( ! TextUtils . isEmpty ( gameId ) ) {
fragmentView. fragment Activity. 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. fragment Activity. setTitle ( R . string . preferences _settings )
settings Activity. 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. fragment Activity. setTitle ( R . string . preferences _general )
val rendererSection = settings !! . getSection ( Settings . SECTION _RENDERER )
settings Activity. 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. fragment Activity. setTitle ( R . string . preferences _system )
val systemSection = settings !! . getSection ( Settings . SECTION _SYSTEM )
settings Activity. 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. fragment Activity. setTitle ( R . string . preferences _graphics )
val rendererSection = settings !! . getSection ( Settings . SECTION _RENDERER )
settings Activity. 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. fragment Activity. setTitle ( R . string . preferences _audio )
val audioSection = settings !! . getSection ( Settings . SECTION _AUDIO )
settings Activity. setTitle ( R . string . preferences _audio )
val audioSection = settings . getSection ( Settings . SECTION _AUDIO )
val audioVolume = audioSection !! . getSetting ( SettingsFile . KEY _AUDIO _VOLUME )
sl . add (
SliderSetting (