Make languages setting use IntegerListPreference

This commit is contained in:
sspacelynx 2021-08-28 11:51:15 +02:00 committed by ◱ Mark
parent c1a3ddcd1c
commit 221039084e
7 changed files with 32 additions and 40 deletions

View File

@ -173,7 +173,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
val preferenceFd = ParcelFileDescriptor.open(File("${applicationInfo.dataDir}/shared_prefs/${applicationInfo.packageName}_preferences.xml"), ParcelFileDescriptor.MODE_READ_WRITE) val preferenceFd = ParcelFileDescriptor.open(File("${applicationInfo.dataDir}/shared_prefs/${applicationInfo.packageName}_preferences.xml"), ParcelFileDescriptor.MODE_READ_WRITE)
emulationThread = Thread { emulationThread = Thread {
executeApplication(rom.toString(), romType, romFd.detachFd(), preferenceFd.detachFd(), Integer.parseInt(settings.systemLanguage), applicationContext.filesDir.canonicalPath + "/", assets) executeApplication(rom.toString(), romType, romFd.detachFd(), preferenceFd.detachFd(), settings.systemLanguage, applicationContext.filesDir.canonicalPath + "/", assets)
if (shouldFinish) if (shouldFinish)
runOnUiThread { runOnUiThread {
emulationThread.join() emulationThread.join()

View File

@ -292,7 +292,7 @@ class MainActivity : AppCompatActivity() {
} }
private fun loadRoms(loadFromFile : Boolean) { private fun loadRoms(loadFromFile : Boolean) {
viewModel.loadRoms(loadFromFile, Uri.parse(settings.searchLocation), Integer.parseInt(settings.systemLanguage)) viewModel.loadRoms(loadFromFile, Uri.parse(settings.searchLocation), settings.systemLanguage)
settings.refreshRequired = false settings.refreshRequired = false
} }

View File

@ -5,7 +5,6 @@
package emu.skyline.preference package emu.skyline.preference
import java.lang.Exception
import android.os.Bundle import android.os.Bundle
import android.os.Parcel import android.os.Parcel
import android.os.Parcelable import android.os.Parcelable
@ -22,6 +21,7 @@ import androidx.core.content.res.TypedArrayUtils
import androidx.preference.R import androidx.preference.R
import androidx.preference.DialogPreference import androidx.preference.DialogPreference
import androidx.preference.PreferenceDialogFragmentCompat import androidx.preference.PreferenceDialogFragmentCompat
import emu.skyline.R as sR
/** /**
* A Preference that displays a list of entries as a dialog. * A Preference that displays a list of entries as a dialog.
@ -68,31 +68,30 @@ class IntegerListPreference @JvmOverloads constructor(
init { init {
val res : Resources = context.resources val res : Resources = context.resources
val entryValuesId = attrs!!.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "entryValues", 0)
var a = context.obtainStyledAttributes( val a = context.obtainStyledAttributes(
attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes attrs, sR.styleable.IntegerListPreference, defStyleAttr, defStyleRes
) )
entries = TypedArrayUtils.getTextArray( entries = TypedArrayUtils.getTextArray(
a, R.styleable.ListPreference_entries, a, sR.styleable.IntegerListPreference_entries,
R.styleable.ListPreference_android_entries sR.styleable.IntegerListPreference_android_entries
) )
entryValues = try { res.getIntArray(entryValuesId) } catch (e : Exception) { null }
val entryValuesId = TypedArrayUtils.getResourceId(
a, sR.styleable.IntegerListPreference_android_entryValues,
sR.styleable.IntegerListPreference_android_entryValues, 0
)
entryValues = if (entryValuesId != 0) res.getIntArray(entryValuesId) else null
if (TypedArrayUtils.getBoolean( if (TypedArrayUtils.getBoolean(
a, R.styleable.ListPreference_useSimpleSummaryProvider, a, sR.styleable.IntegerListPreference_useSimpleSummaryProvider,
R.styleable.ListPreference_useSimpleSummaryProvider, false sR.styleable.IntegerListPreference_useSimpleSummaryProvider, false
) )
) { ) {
summaryProvider = SimpleSummaryProvider.instance summaryProvider = SimpleSummaryProvider.instance
} }
a.recycle() a.recycle()
//Retrieve the Preference summary attribute since it's private in the Preference class.
a = context.obtainStyledAttributes(
attrs,
R.styleable.Preference, defStyleAttr, defStyleRes
)
a.recycle()
} }
/** /**

View File

@ -38,5 +38,5 @@ class Settings @Inject constructor(@ApplicationContext private val context : Con
var maxRefreshRate by sharedPreferences(context, false) var maxRefreshRate by sharedPreferences(context, false)
var systemLanguage by sharedPreferences(context, "1") var systemLanguage by sharedPreferences(context, 1)
} }

View File

@ -54,24 +54,4 @@
<item>Traditional Chinese (正體中文)</item> <item>Traditional Chinese (正體中文)</item>
<item>Brazilian Portuguese (português do Brasil)</item> <item>Brazilian Portuguese (português do Brasil)</item>
</string-array> </string-array>
<string-array name="system_lang_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>10</item>
<item>11</item>
<item>12</item>
<item>13</item>
<item>14</item>
<item>15</item>
<item>16</item>
<item>17</item>
</string-array>
</resources> </resources>

View File

@ -4,4 +4,18 @@
<attr name="limit" format="integer" /> <attr name="limit" format="integer" />
</declare-styleable> </declare-styleable>
<attr name="chipChoiceStyle" format="reference" /> <attr name="chipChoiceStyle" format="reference" />
<declare-styleable name="IntegerListPreference">
<!-- The human-readable array to present as a list. Each entry must have a corresponding
index in entryValues. -->
<attr format="reference" name="entries"/>
<attr name="android:entries"/>
<!-- The array to find the value to save for a preference when an entry from
entries is selected. If a user clicks on the second item in entries, the
second item in this array will be saved to the preference. -->
<attr format="reference" name="entryValues"/>
<attr name="android:entryValues"/>
<!-- Whether the preference should automatically set its summary to the value saved for the
preference, and update the summary when the value is changed. Defaults to false. -->
<attr format="boolean" name="useSimpleSummaryProvider"/>
</declare-styleable>
</resources> </resources>

View File

@ -75,7 +75,6 @@
<emu.skyline.preference.IntegerListPreference <emu.skyline.preference.IntegerListPreference
android:defaultValue="1" android:defaultValue="1"
android:entries="@array/system_languages" android:entries="@array/system_languages"
android:entryValues="@array/system_lang_values"
app:key="system_language" app:key="system_language"
app:title="@string/system_language" app:title="@string/system_language"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />