@ -4,58 +4,37 @@
package org.yuzu.yuzu_emu.features.settings.ui
package org.yuzu.yuzu_emu.features.settings.ui
import android.text.TextUtils
import android.text.TextUtils
import androidx.appcompat.app.AppCompatActivity
import org.yuzu.yuzu_emu.R
import org.yuzu.yuzu_emu.R
import org.yuzu.yuzu_emu.features.settings.model.Setting
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.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.model.view.*
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
class SettingsFragmentPresenter ( private val fragmentView : SettingsFragmentView ) {
class SettingsFragmentPresenter ( private val fragmentView : SettingsFragmentView ) {
private var menuTag : String ? = null
private var menuTag : String ? = null
private lateinit var gameId : String
private lateinit var gameId : String
private var settings : Settings ? = null
private var settingsList : ArrayList < SettingsItem > ? = 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 ) {
fun onCreate ( menuTag : String , gameId : String ) {
this . gameId = gameId
this . gameId = gameId
this . menuTag = menuTag
this . menuTag = menuTag
}
}
fun onViewCreated ( settings : Settings ) {
fun onViewCreated ( ) {
setSettings( settings )
loadSettingsList( )
}
}
fun putSetting ( setting : Setting ) {
fun putSetting ( setting : Setting ) {
settings !! . getSection ( setting . section ) !! . putSetting ( setting )
settings . getSection ( setting . section ) !! . putSetting ( setting )
}
}
private fun asStringSetting ( setting : Setting ? ) : StringSetting ? {
fun loadSettingsList ( ) {
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 ( ) {
if ( ! TextUtils . isEmpty ( gameId ) ) {
if ( ! TextUtils . isEmpty ( gameId ) ) {
fragmentView. fragment Activity. title = " Game Settings: $gameId "
settingsActivity . title = " Game Settings: $gameId "
}
}
val sl = ArrayList < SettingsItem > ( )
val sl = ArrayList < SettingsItem > ( )
if ( menuTag == null ) {
if ( menuTag == null ) {
@ -77,7 +56,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
}
}
private fun addConfigSettings ( sl : ArrayList < SettingsItem > ) {
private fun addConfigSettings ( sl : ArrayList < SettingsItem > ) {
fragmentView. fragment Activity. setTitle ( R . string . preferences _settings )
settings Activity. setTitle ( R . string . preferences _settings )
sl . apply {
sl . apply {
add (
add (
SubmenuSetting (
SubmenuSetting (
@ -119,12 +98,12 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
}
}
private fun addGeneralSettings ( sl : ArrayList < SettingsItem > ) {
private fun addGeneralSettings ( sl : ArrayList < SettingsItem > ) {
fragmentView. fragment Activity. setTitle ( R . string . preferences _general )
settings Activity. setTitle ( R . string . preferences _general )
val rendererSection = settings !! . getSection ( Settings . SECTION _RENDERER )
val rendererSection = settings . getSection ( Settings . SECTION _RENDERER )
val frameLimitEnable =
val frameLimitEnable =
rendererSection !! . getSetting ( SettingsFile . KEY _RENDERER _USE _SPEED _LIMIT )
rendererSection !! . getSetting ( SettingsFile . KEY _RENDERER _USE _SPEED _LIMIT )
val frameLimitValue = rendererSection . getSetting ( SettingsFile . KEY _RENDERER _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 )
val cpuAccuracy = cpuSection !! . getSetting ( SettingsFile . KEY _CPU _ACCURACY )
sl . apply {
sl . apply {
add (
add (
@ -166,8 +145,8 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
}
}
private fun addSystemSettings ( sl : ArrayList < SettingsItem > ) {
private fun addSystemSettings ( sl : ArrayList < SettingsItem > ) {
fragmentView. fragment Activity. setTitle ( R . string . preferences _system )
settings Activity. setTitle ( R . string . preferences _system )
val systemSection = settings !! . getSection ( Settings . SECTION _SYSTEM )
val systemSection = settings . getSection ( Settings . SECTION _SYSTEM )
val dockedMode = systemSection !! . getSetting ( SettingsFile . KEY _USE _DOCKED _MODE )
val dockedMode = systemSection !! . getSetting ( SettingsFile . KEY _USE _DOCKED _MODE )
val region = systemSection . getSetting ( SettingsFile . KEY _REGION _INDEX )
val region = systemSection . getSetting ( SettingsFile . KEY _REGION _INDEX )
val language = systemSection . getSetting ( SettingsFile . KEY _LANGUAGE _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 > ) {
private fun addGraphicsSettings ( sl : ArrayList < SettingsItem > ) {
fragmentView. fragment Activity. setTitle ( R . string . preferences _graphics )
settings Activity. setTitle ( R . string . preferences _graphics )
val rendererSection = settings !! . getSection ( Settings . SECTION _RENDERER )
val rendererSection = settings . getSection ( Settings . SECTION _RENDERER )
val rendererBackend = rendererSection !! . getSetting ( SettingsFile . KEY _RENDERER _BACKEND )
val rendererBackend = rendererSection !! . getSetting ( SettingsFile . KEY _RENDERER _BACKEND )
val rendererAccuracy = rendererSection . getSetting ( SettingsFile . KEY _RENDERER _ACCURACY )
val rendererAccuracy = rendererSection . getSetting ( SettingsFile . KEY _RENDERER _ACCURACY )
val rendererResolution = rendererSection . getSetting ( SettingsFile . KEY _RENDERER _RESOLUTION )
val rendererResolution = rendererSection . getSetting ( SettingsFile . KEY _RENDERER _RESOLUTION )
@ -305,8 +284,8 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
}
}
private fun addAudioSettings ( sl : ArrayList < SettingsItem > ) {
private fun addAudioSettings ( sl : ArrayList < SettingsItem > ) {
fragmentView. fragment Activity. setTitle ( R . string . preferences _audio )
settings Activity. setTitle ( R . string . preferences _audio )
val audioSection = settings !! . getSection ( Settings . SECTION _AUDIO )
val audioSection = settings . getSection ( Settings . SECTION _AUDIO )
val audioVolume = audioSection !! . getSetting ( SettingsFile . KEY _AUDIO _VOLUME )
val audioVolume = audioSection !! . getSetting ( SettingsFile . KEY _AUDIO _VOLUME )
sl . add (
sl . add (
SliderSetting (
SliderSetting (