mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-26 15:04:16 +01:00
Make integer settings use IntegerListPreference
Avoids unnecessary type casting of setting values and duplication in resource files.
This commit is contained in:
parent
cbc896c8f8
commit
365ca66b1b
@ -54,7 +54,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private val adapter = GenericAdapter()
|
private val adapter = GenericAdapter()
|
||||||
|
|
||||||
private val layoutType get() = LayoutType.values()[settings.layoutType.toInt()]
|
private val layoutType get() = LayoutType.values()[settings.layoutType]
|
||||||
|
|
||||||
private val missingIcon by lazy { ContextCompat.getDrawable(this, R.drawable.default_icon)!!.toBitmap(256, 256) }
|
private val missingIcon by lazy { ContextCompat.getDrawable(this, R.drawable.default_icon)!!.toBitmap(256, 256) }
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onCreate(savedInstanceState : Bundle?) {
|
override fun onCreate(savedInstanceState : Bundle?) {
|
||||||
// Need to create new instance of settings, dependency injection happens
|
// Need to create new instance of settings, dependency injection happens
|
||||||
AppCompatDelegate.setDefaultNightMode(
|
AppCompatDelegate.setDefaultNightMode(
|
||||||
when ((Settings(this).appTheme.toInt())) {
|
when ((Settings(this).appTheme)) {
|
||||||
0 -> AppCompatDelegate.MODE_NIGHT_NO
|
0 -> AppCompatDelegate.MODE_NIGHT_NO
|
||||||
1 -> AppCompatDelegate.MODE_NIGHT_YES
|
1 -> AppCompatDelegate.MODE_NIGHT_YES
|
||||||
2 -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
2 -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||||
@ -106,8 +106,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
PreferenceManager.setDefaultValues(this, R.xml.preferences, false)
|
PreferenceManager.setDefaultValues(this, R.xml.preferences, false)
|
||||||
|
|
||||||
adapter.apply {
|
adapter.apply {
|
||||||
setHeaderItems(listOf(HeaderRomFilterItem(formatOrder, if (settings.filter == 0) null else formatOrder[settings.filter - 1]) { romFormat ->
|
setHeaderItems(listOf(HeaderRomFilterItem(formatOrder, if (settings.romFormatFilter == 0) null else formatOrder[settings.romFormatFilter - 1]) { romFormat ->
|
||||||
settings.filter = romFormat?.let { formatOrder.indexOf(romFormat) + 1 } ?: 0
|
settings.romFormatFilter = romFormat?.let { formatOrder.indexOf(romFormat) + 1 } ?: 0
|
||||||
formatFilter = romFormat
|
formatFilter = romFormat
|
||||||
populateAdapter()
|
populateAdapter()
|
||||||
}))
|
}))
|
||||||
|
@ -36,6 +36,6 @@ class SkylineApplication : Application() {
|
|||||||
|
|
||||||
val appFilesPath = applicationContext.getPublicFilesDir().canonicalPath
|
val appFilesPath = applicationContext.getPublicFilesDir().canonicalPath
|
||||||
File("$appFilesPath/logs/").mkdirs()
|
File("$appFilesPath/logs/").mkdirs()
|
||||||
initializeLog("$appFilesPath/", getSettings().logLevel.toInt())
|
initializeLog("$appFilesPath/", getSettings().logLevel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ import emu.skyline.R as sR
|
|||||||
* @see androidx.preference.ListPreference
|
* @see androidx.preference.ListPreference
|
||||||
*/
|
*/
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
class IntegerListPreference @JvmOverloads constructor(
|
open class IntegerListPreference @JvmOverloads constructor(
|
||||||
context : Context,
|
context : Context,
|
||||||
attrs : AttributeSet? = null,
|
attrs : AttributeSet? = null,
|
||||||
defStyleAttr : Int = TypedArrayUtils.getAttr(
|
defStyleAttr : Int = TypedArrayUtils.getAttr(
|
||||||
|
@ -14,12 +14,12 @@ import androidx.preference.R
|
|||||||
/**
|
/**
|
||||||
* This preference is used to set the theme to Light/Dark mode
|
* This preference is used to set the theme to Light/Dark mode
|
||||||
*/
|
*/
|
||||||
class ThemePreference @JvmOverloads constructor(context : Context, attrs : AttributeSet? = null, defStyleAttr : Int = R.attr.dialogPreferenceStyle) : ListPreference(context, attrs, defStyleAttr) {
|
class ThemePreference @JvmOverloads constructor(context : Context, attrs : AttributeSet? = null, defStyleAttr : Int = R.attr.dialogPreferenceStyle) : IntegerListPreference(context, attrs, defStyleAttr) {
|
||||||
/**
|
/**
|
||||||
* This changes [AppCompatDelegate.sDefaultNightMode] based on what the user's selection is
|
* This changes [AppCompatDelegate.sDefaultNightMode] based on what the user's selection is
|
||||||
*/
|
*/
|
||||||
override fun callChangeListener(newValue : Any?) : Boolean {
|
override fun callChangeListener(newValue : Any?) : Boolean {
|
||||||
AppCompatDelegate.setDefaultNightMode(when ((newValue as String).toInt()) {
|
AppCompatDelegate.setDefaultNightMode(when (newValue as Int) {
|
||||||
0 -> AppCompatDelegate.MODE_NIGHT_NO
|
0 -> AppCompatDelegate.MODE_NIGHT_NO
|
||||||
1 -> AppCompatDelegate.MODE_NIGHT_YES
|
1 -> AppCompatDelegate.MODE_NIGHT_YES
|
||||||
2 -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
2 -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||||
|
@ -10,40 +10,37 @@ import android.content.pm.ActivityInfo
|
|||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
import emu.skyline.R
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class Settings @Inject constructor(@ApplicationContext private val context : Context) {
|
class Settings @Inject constructor(@ApplicationContext private val context : Context) {
|
||||||
var layoutType by sharedPreferences(context, "1")
|
// Emulator
|
||||||
|
|
||||||
var searchLocation by sharedPreferences(context, "")
|
var searchLocation by sharedPreferences(context, "")
|
||||||
|
var appTheme by sharedPreferences(context, 2)
|
||||||
var refreshRequired by sharedPreferences(context, false)
|
var layoutType by sharedPreferences(context, 1)
|
||||||
|
|
||||||
var appTheme by sharedPreferences(context, "2")
|
|
||||||
|
|
||||||
var selectAction by sharedPreferences(context, false)
|
var selectAction by sharedPreferences(context, false)
|
||||||
|
|
||||||
var perfStats by sharedPreferences(context, false)
|
var perfStats by sharedPreferences(context, false)
|
||||||
|
var logLevel by sharedPreferences(context, 3)
|
||||||
var operationMode by sharedPreferences(context, true)
|
|
||||||
|
|
||||||
var onScreenControl by sharedPreferences(context, true)
|
|
||||||
|
|
||||||
var onScreenControlRecenterSticks by sharedPreferences(context, true)
|
|
||||||
|
|
||||||
var logCompact by sharedPreferences(context, false)
|
var logCompact by sharedPreferences(context, false)
|
||||||
|
|
||||||
var logLevel by sharedPreferences(context, "3")
|
// System
|
||||||
|
var operationMode by sharedPreferences(context, true)
|
||||||
var filter by sharedPreferences(context, 0)
|
var usernameValue by sharedPreferences(context, context.getString(R.string.username_default))
|
||||||
|
|
||||||
var maxRefreshRate by sharedPreferences(context, false)
|
|
||||||
|
|
||||||
var aspectRatio by sharedPreferences(context, 0)
|
|
||||||
|
|
||||||
var systemLanguage by sharedPreferences(context, 1)
|
var systemLanguage by sharedPreferences(context, 1)
|
||||||
|
|
||||||
|
// Display
|
||||||
|
var forceTripleBuffering by sharedPreferences(context, true)
|
||||||
|
var disableFrameThrottling by sharedPreferences(context, false)
|
||||||
|
var maxRefreshRate by sharedPreferences(context, false)
|
||||||
|
var aspectRatio by sharedPreferences(context, 0)
|
||||||
var orientation by sharedPreferences(context, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
|
var orientation by sharedPreferences(context, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
|
||||||
|
|
||||||
var respectDisplayCutout by sharedPreferences(context, false)
|
var respectDisplayCutout by sharedPreferences(context, false)
|
||||||
|
|
||||||
|
// Input
|
||||||
|
var onScreenControl by sharedPreferences(context, true)
|
||||||
|
var onScreenControlRecenterSticks by sharedPreferences(context, true)
|
||||||
|
|
||||||
|
// Other
|
||||||
|
var romFormatFilter by sharedPreferences(context, 0)
|
||||||
|
var refreshRequired by sharedPreferences(context, false)
|
||||||
}
|
}
|
||||||
|
@ -7,33 +7,16 @@
|
|||||||
<item>Debug</item>
|
<item>Debug</item>
|
||||||
<item>Verbose</item>
|
<item>Verbose</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="log_level_val">
|
|
||||||
<item>0</item>
|
|
||||||
<item>1</item>
|
|
||||||
<item>2</item>
|
|
||||||
<item>3</item>
|
|
||||||
<item>4</item>
|
|
||||||
</string-array>
|
|
||||||
<string-array name="layout_type">
|
<string-array name="layout_type">
|
||||||
<item>List</item>
|
<item>List</item>
|
||||||
<item>Grid</item>
|
<item>Grid</item>
|
||||||
<item>Grid Compact</item>
|
<item>Grid Compact</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="layout_type_val">
|
|
||||||
<item>0</item>
|
|
||||||
<item>1</item>
|
|
||||||
<item>2</item>
|
|
||||||
</string-array>
|
|
||||||
<string-array name="app_theme">
|
<string-array name="app_theme">
|
||||||
<item>Light</item>
|
<item>Light</item>
|
||||||
<item>Dark</item>
|
<item>Dark</item>
|
||||||
<item>Use System Default</item>
|
<item>Use System Default</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="app_theme_val">
|
|
||||||
<item>0</item>
|
|
||||||
<item>1</item>
|
|
||||||
<item>2</item>
|
|
||||||
</string-array>
|
|
||||||
<string-array name="system_languages">
|
<string-array name="system_languages">
|
||||||
<item>American English</item>
|
<item>American English</item>
|
||||||
<item>British English</item>
|
<item>British English</item>
|
||||||
|
@ -13,14 +13,12 @@
|
|||||||
<emu.skyline.preference.ThemePreference
|
<emu.skyline.preference.ThemePreference
|
||||||
android:defaultValue="2"
|
android:defaultValue="2"
|
||||||
android:entries="@array/app_theme"
|
android:entries="@array/app_theme"
|
||||||
android:entryValues="@array/app_theme_val"
|
|
||||||
app:key="app_theme"
|
app:key="app_theme"
|
||||||
app:title="@string/theme"
|
app:title="@string/theme"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
<ListPreference
|
<emu.skyline.preference.IntegerListPreference
|
||||||
android:defaultValue="1"
|
android:defaultValue="1"
|
||||||
android:entries="@array/layout_type"
|
android:entries="@array/layout_type"
|
||||||
android:entryValues="@array/layout_type_val"
|
|
||||||
app:key="layout_type"
|
app:key="layout_type"
|
||||||
app:title="@string/layout_type"
|
app:title="@string/layout_type"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
@ -36,10 +34,9 @@
|
|||||||
android:summaryOn="@string/perf_stats_desc_on"
|
android:summaryOn="@string/perf_stats_desc_on"
|
||||||
app:key="perf_stats"
|
app:key="perf_stats"
|
||||||
app:title="@string/perf_stats" />
|
app:title="@string/perf_stats" />
|
||||||
<ListPreference
|
<emu.skyline.preference.IntegerListPreference
|
||||||
android:defaultValue="2"
|
android:defaultValue="2"
|
||||||
android:entries="@array/log_level"
|
android:entries="@array/log_level"
|
||||||
android:entryValues="@array/log_level_val"
|
|
||||||
app:key="log_level"
|
app:key="log_level"
|
||||||
app:title="@string/log_level"
|
app:title="@string/log_level"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
Loading…
Reference in New Issue
Block a user