android: Expose custom RTC setting

This commit is contained in:
Charles Lombardo 2023-05-13 18:43:35 -04:00 committed by bunnei
parent f7934bdaf7
commit c31a37c828
9 changed files with 72 additions and 31 deletions

View File

@ -8,8 +8,7 @@ enum class BooleanSetting(
override val section: String, override val section: String,
override val defaultValue: Boolean override val defaultValue: Boolean
) : AbstractBooleanSetting { ) : AbstractBooleanSetting {
// No boolean settings currently exist USE_CUSTOM_RTC("custom_rtc_enabled", Settings.SECTION_SYSTEM, false);
EMPTY_SETTING("", "", false);
override var boolean: Boolean = defaultValue override var boolean: Boolean = defaultValue
@ -27,7 +26,9 @@ enum class BooleanSetting(
} }
companion object { companion object {
private val NOT_RUNTIME_EDITABLE = emptyList<BooleanSetting>() private val NOT_RUNTIME_EDITABLE = listOf(
USE_CUSTOM_RTC
)
fun from(key: String): BooleanSetting? = fun from(key: String): BooleanSetting? =
BooleanSetting.values().firstOrNull { it.key == key } BooleanSetting.values().firstOrNull { it.key == key }

View File

@ -8,8 +8,7 @@ enum class StringSetting(
override val section: String, override val section: String,
override val defaultValue: String override val defaultValue: String
) : AbstractStringSetting { ) : AbstractStringSetting {
// No string settings currently exist CUSTOM_RTC("custom_rtc", Settings.SECTION_SYSTEM, "0");
EMPTY_SETTING("", "", "");
override var string: String = defaultValue override var string: String = defaultValue
@ -27,7 +26,9 @@ enum class StringSetting(
} }
companion object { companion object {
private val NOT_RUNTIME_EDITABLE = emptyList<StringSetting>() private val NOT_RUNTIME_EDITABLE = listOf(
CUSTOM_RTC
)
fun from(key: String): StringSetting? = StringSetting.values().firstOrNull { it.key == key } fun from(key: String): StringSetting? = StringSetting.values().firstOrNull { it.key == key }
} }

View File

@ -7,10 +7,10 @@ import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractStringSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractStringSetting
class DateTimeSetting( class DateTimeSetting(
val key: String? = null,
setting: AbstractSetting?, setting: AbstractSetting?,
titleId: Int, titleId: Int,
descriptionId: Int, descriptionId: Int,
val key: String? = null,
private val defaultValue: String? = null private val defaultValue: String? = null
) : SettingsItem(setting, titleId, descriptionId) { ) : SettingsItem(setting, titleId, descriptionId) {
override val type = TYPE_DATETIME_SETTING override val type = TYPE_DATETIME_SETTING

View File

@ -15,14 +15,14 @@ class SwitchSetting(
titleId: Int, titleId: Int,
descriptionId: Int, descriptionId: Int,
val key: String? = null, val key: String? = null,
val defaultValue: Boolean? = null val defaultValue: Any? = null
) : SettingsItem(setting, titleId, descriptionId) { ) : SettingsItem(setting, titleId, descriptionId) {
override val type = TYPE_SWITCH override val type = TYPE_SWITCH
val isChecked: Boolean val isChecked: Boolean
get() { get() {
if (setting == null) { if (setting == null) {
return defaultValue!! return defaultValue as Boolean
} }
// Try integer setting // Try integer setting
@ -38,7 +38,7 @@ class SwitchSetting(
return setting.boolean return setting.boolean
} catch (_: ClassCastException) { } catch (_: ClassCastException) {
} }
return defaultValue!! return defaultValue as Boolean
} }
/** /**

View File

@ -182,10 +182,11 @@ class SettingsAdapter(
epochTime += timePicker.minute.toLong() * 60 epochTime += timePicker.minute.toLong() * 60
val rtcString = epochTime.toString() val rtcString = epochTime.toString()
if (item.value != rtcString) { if (item.value != rtcString) {
notifyItemChanged(clickedPosition)
fragmentView.onSettingChanged() fragmentView.onSettingChanged()
} }
item.setSelectedValue(rtcString) notifyItemChanged(clickedPosition)
val setting = item.setSelectedValue(rtcString)
fragmentView.putSetting(setting)
clickedItem = null clickedItem = null
} }
datePicker.show( datePicker.show(

View File

@ -13,8 +13,10 @@ import org.yuzu.yuzu_emu.YuzuApplication
import org.yuzu.yuzu_emu.features.settings.model.AbstractBooleanSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractBooleanSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting
import org.yuzu.yuzu_emu.features.settings.model.IntSetting 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.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
import org.yuzu.yuzu_emu.utils.ThemeHelper import org.yuzu.yuzu_emu.utils.ThemeHelper
@ -121,7 +123,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.frame_limit_enable, R.string.frame_limit_enable,
R.string.frame_limit_enable_description, R.string.frame_limit_enable_description,
IntSetting.RENDERER_USE_SPEED_LIMIT.key, IntSetting.RENDERER_USE_SPEED_LIMIT.key,
true IntSetting.RENDERER_USE_SPEED_LIMIT.defaultValue
) )
) )
add( add(
@ -133,7 +135,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
200, 200,
"%", "%",
IntSetting.RENDERER_SPEED_LIMIT.key, IntSetting.RENDERER_SPEED_LIMIT.key,
100 IntSetting.RENDERER_SPEED_LIMIT.defaultValue
) )
) )
add( add(
@ -144,7 +146,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.array.cpuAccuracyNames, R.array.cpuAccuracyNames,
R.array.cpuAccuracyValues, R.array.cpuAccuracyValues,
IntSetting.CPU_ACCURACY.key, IntSetting.CPU_ACCURACY.key,
0 IntSetting.CPU_ACCURACY.defaultValue
) )
) )
} }
@ -159,7 +161,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.use_docked_mode, R.string.use_docked_mode,
R.string.use_docked_mode_description, R.string.use_docked_mode_description,
IntSetting.USE_DOCKED_MODE.key, IntSetting.USE_DOCKED_MODE.key,
false IntSetting.USE_DOCKED_MODE.defaultValue
) )
) )
add( add(
@ -170,7 +172,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.array.regionNames, R.array.regionNames,
R.array.regionValues, R.array.regionValues,
IntSetting.REGION_INDEX.key, IntSetting.REGION_INDEX.key,
-1 IntSetting.REGION_INDEX.defaultValue
) )
) )
add( add(
@ -181,7 +183,25 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.array.languageNames, R.array.languageNames,
R.array.languageValues, R.array.languageValues,
IntSetting.LANGUAGE_INDEX.key, IntSetting.LANGUAGE_INDEX.key,
1 IntSetting.LANGUAGE_INDEX.defaultValue
)
)
add(
SwitchSetting(
BooleanSetting.USE_CUSTOM_RTC,
R.string.use_custom_rtc,
R.string.use_custom_rtc_description,
BooleanSetting.USE_CUSTOM_RTC.key,
BooleanSetting.USE_CUSTOM_RTC.defaultValue
)
)
add(
DateTimeSetting(
StringSetting.CUSTOM_RTC,
R.string.set_custom_rtc,
0,
StringSetting.CUSTOM_RTC.key,
StringSetting.CUSTOM_RTC.defaultValue
) )
) )
} }
@ -198,7 +218,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.array.rendererApiNames, R.array.rendererApiNames,
R.array.rendererApiValues, R.array.rendererApiValues,
IntSetting.RENDERER_BACKEND.key, IntSetting.RENDERER_BACKEND.key,
1 IntSetting.RENDERER_BACKEND.defaultValue
) )
) )
add( add(
@ -209,7 +229,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.array.rendererAccuracyNames, R.array.rendererAccuracyNames,
R.array.rendererAccuracyValues, R.array.rendererAccuracyValues,
IntSetting.RENDERER_ACCURACY.key, IntSetting.RENDERER_ACCURACY.key,
0 IntSetting.RENDERER_ACCURACY.defaultValue
) )
) )
add( add(
@ -220,7 +240,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.array.rendererResolutionNames, R.array.rendererResolutionNames,
R.array.rendererResolutionValues, R.array.rendererResolutionValues,
IntSetting.RENDERER_RESOLUTION.key, IntSetting.RENDERER_RESOLUTION.key,
2 IntSetting.RENDERER_RESOLUTION.defaultValue
) )
) )
add( add(
@ -231,7 +251,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.array.rendererScalingFilterNames, R.array.rendererScalingFilterNames,
R.array.rendererScalingFilterValues, R.array.rendererScalingFilterValues,
IntSetting.RENDERER_SCALING_FILTER.key, IntSetting.RENDERER_SCALING_FILTER.key,
1 IntSetting.RENDERER_SCALING_FILTER.defaultValue
) )
) )
add( add(
@ -242,7 +262,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.array.rendererAntiAliasingNames, R.array.rendererAntiAliasingNames,
R.array.rendererAntiAliasingValues, R.array.rendererAntiAliasingValues,
IntSetting.RENDERER_ANTI_ALIASING.key, IntSetting.RENDERER_ANTI_ALIASING.key,
0 IntSetting.RENDERER_ANTI_ALIASING.defaultValue
) )
) )
add( add(
@ -253,7 +273,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.array.rendererAspectRatioNames, R.array.rendererAspectRatioNames,
R.array.rendererAspectRatioValues, R.array.rendererAspectRatioValues,
IntSetting.RENDERER_ASPECT_RATIO.key, IntSetting.RENDERER_ASPECT_RATIO.key,
0 IntSetting.RENDERER_ASPECT_RATIO.defaultValue
) )
) )
add( add(
@ -262,7 +282,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.use_disk_shader_cache, R.string.use_disk_shader_cache,
R.string.use_disk_shader_cache_description, R.string.use_disk_shader_cache_description,
IntSetting.RENDERER_USE_DISK_SHADER_CACHE.key, IntSetting.RENDERER_USE_DISK_SHADER_CACHE.key,
true IntSetting.RENDERER_USE_DISK_SHADER_CACHE.defaultValue
) )
) )
add( add(
@ -271,7 +291,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.renderer_force_max_clock, R.string.renderer_force_max_clock,
R.string.renderer_force_max_clock_description, R.string.renderer_force_max_clock_description,
IntSetting.RENDERER_FORCE_MAX_CLOCK.key, IntSetting.RENDERER_FORCE_MAX_CLOCK.key,
true IntSetting.RENDERER_FORCE_MAX_CLOCK.defaultValue
) )
) )
add( add(
@ -280,7 +300,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.renderer_asynchronous_shaders, R.string.renderer_asynchronous_shaders,
R.string.renderer_asynchronous_shaders_description, R.string.renderer_asynchronous_shaders_description,
IntSetting.RENDERER_ASYNCHRONOUS_SHADERS.key, IntSetting.RENDERER_ASYNCHRONOUS_SHADERS.key,
false IntSetting.RENDERER_ASYNCHRONOUS_SHADERS.defaultValue
) )
) )
add( add(
@ -289,7 +309,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.renderer_debug, R.string.renderer_debug,
R.string.renderer_debug_description, R.string.renderer_debug_description,
IntSetting.RENDERER_DEBUG.key, IntSetting.RENDERER_DEBUG.key,
false IntSetting.RENDERER_DEBUG.defaultValue
) )
) )
} }
@ -306,7 +326,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
100, 100,
"%", "%",
IntSetting.AUDIO_VOLUME.key, IntSetting.AUDIO_VOLUME.key,
100 IntSetting.AUDIO_VOLUME.defaultValue
) )
) )
} }

View File

@ -5,10 +5,14 @@ package org.yuzu.yuzu_emu.features.settings.ui.viewholder
import android.view.View import android.view.View
import org.yuzu.yuzu_emu.databinding.ListItemSettingBinding import org.yuzu.yuzu_emu.databinding.ListItemSettingBinding
import org.yuzu.yuzu_emu.features.settings.model.AbstractStringSetting
import org.yuzu.yuzu_emu.features.settings.model.view.DateTimeSetting import org.yuzu.yuzu_emu.features.settings.model.view.DateTimeSetting
import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem
import org.yuzu.yuzu_emu.features.settings.ui.SettingsAdapter import org.yuzu.yuzu_emu.features.settings.ui.SettingsAdapter
import java.time.Instant
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
class DateTimeViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAdapter) : class DateTimeViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAdapter) :
SettingViewHolder(binding.root, adapter) { SettingViewHolder(binding.root, adapter) {
@ -21,7 +25,11 @@ class DateTimeViewHolder(val binding: ListItemSettingBinding, adapter: SettingsA
binding.textSettingDescription.setText(item.descriptionId) binding.textSettingDescription.setText(item.descriptionId)
binding.textSettingDescription.visibility = View.VISIBLE binding.textSettingDescription.visibility = View.VISIBLE
} else { } else {
binding.textSettingDescription.visibility = View.GONE val epochTime = setting.value.toLong()
val instant = Instant.ofEpochMilli(epochTime * 1000)
val zonedTime = ZonedDateTime.ofInstant(instant, ZoneId.of("UTC"))
val dateFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)
binding.textSettingDescription.text = dateFormatter.format(zonedTime)
} }
} }

View File

@ -209,6 +209,13 @@ object SettingsFile {
floatSetting.float = value.toFloat() floatSetting.float = value.toFloat()
return floatSetting return floatSetting
} }
val stringSetting = StringSetting.from(key)
if (stringSetting != null) {
stringSetting.string = value
return stringSetting
}
return StringSetting.from(key) return StringSetting.from(key)
} }

View File

@ -114,6 +114,9 @@
<string name="emulated_language">Emulated language</string> <string name="emulated_language">Emulated language</string>
<string name="select_rtc_date">Select RTC Date</string> <string name="select_rtc_date">Select RTC Date</string>
<string name="select_rtc_time">Select RTC Time</string> <string name="select_rtc_time">Select RTC Time</string>
<string name="use_custom_rtc">Enable Custom RTC</string>
<string name="use_custom_rtc_description">This setting allows you to set a custom real time clock separate from your current system time</string>
<string name="set_custom_rtc">Set Custom RTC</string>
<!-- Graphics settings strings --> <!-- Graphics settings strings -->
<string name="renderer_api">API</string> <string name="renderer_api">API</string>