From 221039084e77f418d3a1597466cf6801178c0c76 Mon Sep 17 00:00:00 2001
From: sspacelynx <37104290+sspacelynx@users.noreply.github.com>
Date: Sat, 28 Aug 2021 11:51:15 +0200
Subject: [PATCH] Make languages setting use `IntegerListPreference`
---
.../java/emu/skyline/EmulationActivity.kt | 2 +-
app/src/main/java/emu/skyline/MainActivity.kt | 2 +-
.../preference/IntegerListPreference.kt | 31 +++++++++----------
.../main/java/emu/skyline/utils/Settings.kt | 2 +-
app/src/main/res/values/array.xml | 20 ------------
app/src/main/res/values/attrs.xml | 14 +++++++++
app/src/main/res/xml/preferences.xml | 1 -
7 files changed, 32 insertions(+), 40 deletions(-)
diff --git a/app/src/main/java/emu/skyline/EmulationActivity.kt b/app/src/main/java/emu/skyline/EmulationActivity.kt
index ce131dc8..19ba92c1 100644
--- a/app/src/main/java/emu/skyline/EmulationActivity.kt
+++ b/app/src/main/java/emu/skyline/EmulationActivity.kt
@@ -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)
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)
runOnUiThread {
emulationThread.join()
diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt
index ab3af3f4..ae78f8cb 100644
--- a/app/src/main/java/emu/skyline/MainActivity.kt
+++ b/app/src/main/java/emu/skyline/MainActivity.kt
@@ -292,7 +292,7 @@ class MainActivity : AppCompatActivity() {
}
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
}
diff --git a/app/src/main/java/emu/skyline/preference/IntegerListPreference.kt b/app/src/main/java/emu/skyline/preference/IntegerListPreference.kt
index 3f43171b..5508d71d 100644
--- a/app/src/main/java/emu/skyline/preference/IntegerListPreference.kt
+++ b/app/src/main/java/emu/skyline/preference/IntegerListPreference.kt
@@ -5,7 +5,6 @@
package emu.skyline.preference
-import java.lang.Exception
import android.os.Bundle
import android.os.Parcel
import android.os.Parcelable
@@ -22,6 +21,7 @@ import androidx.core.content.res.TypedArrayUtils
import androidx.preference.R
import androidx.preference.DialogPreference
import androidx.preference.PreferenceDialogFragmentCompat
+import emu.skyline.R as sR
/**
* A Preference that displays a list of entries as a dialog.
@@ -68,31 +68,30 @@ class IntegerListPreference @JvmOverloads constructor(
init {
val res : Resources = context.resources
- val entryValuesId = attrs!!.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "entryValues", 0)
- var a = context.obtainStyledAttributes(
- attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes
+ val a = context.obtainStyledAttributes(
+ attrs, sR.styleable.IntegerListPreference, defStyleAttr, defStyleRes
)
+
entries = TypedArrayUtils.getTextArray(
- a, R.styleable.ListPreference_entries,
- R.styleable.ListPreference_android_entries
+ a, sR.styleable.IntegerListPreference_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(
- a, R.styleable.ListPreference_useSimpleSummaryProvider,
- R.styleable.ListPreference_useSimpleSummaryProvider, false
+ a, sR.styleable.IntegerListPreference_useSimpleSummaryProvider,
+ sR.styleable.IntegerListPreference_useSimpleSummaryProvider, false
)
) {
summaryProvider = SimpleSummaryProvider.instance
}
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()
}
/**
diff --git a/app/src/main/java/emu/skyline/utils/Settings.kt b/app/src/main/java/emu/skyline/utils/Settings.kt
index 7ddba2bc..cd822d8e 100644
--- a/app/src/main/java/emu/skyline/utils/Settings.kt
+++ b/app/src/main/java/emu/skyline/utils/Settings.kt
@@ -38,5 +38,5 @@ class Settings @Inject constructor(@ApplicationContext private val context : Con
var maxRefreshRate by sharedPreferences(context, false)
- var systemLanguage by sharedPreferences(context, "1")
+ var systemLanguage by sharedPreferences(context, 1)
}
diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml
index 3a52726d..873b34b3 100644
--- a/app/src/main/res/values/array.xml
+++ b/app/src/main/res/values/array.xml
@@ -54,24 +54,4 @@
- Traditional Chinese (正體中文)
- Brazilian Portuguese (português do Brasil)
-
- - 0
- - 1
- - 2
- - 3
- - 4
- - 5
- - 6
- - 7
- - 8
- - 9
- - 10
- - 11
- - 12
- - 13
- - 14
- - 15
- - 16
- - 17
-
diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml
index f6efc0b7..f2f3ed59 100644
--- a/app/src/main/res/values/attrs.xml
+++ b/app/src/main/res/values/attrs.xml
@@ -4,4 +4,18 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
index f7bf236a..55252446 100644
--- a/app/src/main/res/xml/preferences.xml
+++ b/app/src/main/res/xml/preferences.xml
@@ -75,7 +75,6 @@