From a683978e8cec503e157ca9e2a88f213e550e3ecf Mon Sep 17 00:00:00 2001 From: lynxnb Date: Wed, 15 Feb 2023 12:21:20 +0100 Subject: [PATCH] Split preferences to multiple files for reusability --- app/src/main/java/emu/skyline/MainActivity.kt | 5 +- .../skyline/settings/PreferenceSettings.kt | 9 + .../emu/skyline/settings/SettingsActivity.kt | 12 +- app/src/main/res/xml/app_preferences.xml | 75 ++++ app/src/main/res/xml/credits_preferences.xml | 163 +++++++ .../main/res/xml/emulation_preferences.xml | 162 +++++++ app/src/main/res/xml/input_preferences.xml | 16 + app/src/main/res/xml/preferences.xml | 407 ------------------ 8 files changed, 433 insertions(+), 416 deletions(-) create mode 100644 app/src/main/res/xml/app_preferences.xml create mode 100644 app/src/main/res/xml/credits_preferences.xml create mode 100644 app/src/main/res/xml/emulation_preferences.xml create mode 100644 app/src/main/res/xml/input_preferences.xml delete mode 100644 app/src/main/res/xml/preferences.xml diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt index 8fcb2d88..3a80ff21 100644 --- a/app/src/main/java/emu/skyline/MainActivity.kt +++ b/app/src/main/java/emu/skyline/MainActivity.kt @@ -23,7 +23,6 @@ import androidx.core.view.WindowCompat import androidx.core.view.isInvisible import androidx.core.view.isVisible import androidx.documentfile.provider.DocumentFile -import androidx.preference.PreferenceManager import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import com.google.android.material.snackbar.Snackbar @@ -37,9 +36,9 @@ import emu.skyline.loader.AppEntry import emu.skyline.loader.LoaderResult import emu.skyline.loader.RomFormat import emu.skyline.provider.DocumentsProvider -import emu.skyline.utils.GpuDriverHelper import emu.skyline.settings.PreferenceSettings import emu.skyline.settings.SettingsActivity +import emu.skyline.utils.GpuDriverHelper import emu.skyline.utils.WindowInsetsHelper import javax.inject.Inject import kotlin.math.ceil @@ -113,7 +112,7 @@ class MainActivity : AppCompatActivity() { WindowCompat.setDecorFitsSystemWindows(window, false) WindowInsetsHelper.applyToActivity(binding.root, binding.appList) - PreferenceManager.setDefaultValues(this, R.xml.preferences, false) + PreferenceSettings.setDefaultValues(this) adapter.apply { setHeaderItems(listOf(HeaderRomFilterItem(formatOrder, if (preferenceSettings.romFormatFilter == 0) null else formatOrder[preferenceSettings.romFormatFilter - 1]) { romFormat -> diff --git a/app/src/main/java/emu/skyline/settings/PreferenceSettings.kt b/app/src/main/java/emu/skyline/settings/PreferenceSettings.kt index 94d509a8..31f3dcc9 100644 --- a/app/src/main/java/emu/skyline/settings/PreferenceSettings.kt +++ b/app/src/main/java/emu/skyline/settings/PreferenceSettings.kt @@ -7,6 +7,7 @@ package emu.skyline.settings import android.content.Context import android.content.pm.ActivityInfo +import androidx.preference.PreferenceManager import dagger.hilt.android.qualifiers.ApplicationContext import emu.skyline.R import emu.skyline.utils.sharedPreferences @@ -70,5 +71,13 @@ class PreferenceSettings @Inject constructor(@ApplicationContext private val con companion object { const val SYSTEM_GPU_DRIVER = "system" + + /** + * Sets the default values for global preferences + */ + fun setDefaultValues(context : Context) { + PreferenceManager.setDefaultValues(context, R.xml.app_preferences, false) + PreferenceManager.setDefaultValues(context, R.xml.emulation_preferences, false) + } } } diff --git a/app/src/main/java/emu/skyline/settings/SettingsActivity.kt b/app/src/main/java/emu/skyline/settings/SettingsActivity.kt index e176629e..bf870186 100644 --- a/app/src/main/java/emu/skyline/settings/SettingsActivity.kt +++ b/app/src/main/java/emu/skyline/settings/SettingsActivity.kt @@ -10,10 +10,7 @@ import android.view.* import androidx.appcompat.app.AppCompatActivity import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.view.* -import androidx.preference.CheckBoxPreference -import androidx.preference.Preference -import androidx.preference.PreferenceCategory -import androidx.preference.PreferenceFragmentCompat +import androidx.preference.* import emu.skyline.BuildConfig import emu.skyline.R import emu.skyline.databinding.SettingsActivityBinding @@ -92,10 +89,13 @@ class SettingsActivity : AppCompatActivity() { } /** - * This constructs the preferences from [R.xml.preferences] + * This constructs the preferences from XML preference resources */ override fun onCreatePreferences(savedInstanceState : Bundle?, rootKey : String?) { - setPreferencesFromResource(R.xml.preferences, rootKey) + addPreferencesFromResource(R.xml.app_preferences) + addPreferencesFromResource(R.xml.game_preferences) + addPreferencesFromResource(R.xml.input_preferences) + addPreferencesFromResource(R.xml.credits_preferences) // Uncheck `disable_frame_throttling` if `force_triple_buffering` gets disabled val disableFrameThrottlingPref = findPreference("disable_frame_throttling")!! diff --git a/app/src/main/res/xml/app_preferences.xml b/app/src/main/res/xml/app_preferences.xml new file mode 100644 index 00000000..21942ac2 --- /dev/null +++ b/app/src/main/res/xml/app_preferences.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/credits_preferences.xml b/app/src/main/res/xml/credits_preferences.xml new file mode 100644 index 00000000..67fb1ed8 --- /dev/null +++ b/app/src/main/res/xml/credits_preferences.xml @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/emulation_preferences.xml b/app/src/main/res/xml/emulation_preferences.xml new file mode 100644 index 00000000..0457fcb8 --- /dev/null +++ b/app/src/main/res/xml/emulation_preferences.xml @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/input_preferences.xml b/app/src/main/res/xml/input_preferences.xml new file mode 100644 index 00000000..885051af --- /dev/null +++ b/app/src/main/res/xml/input_preferences.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml deleted file mode 100644 index 09938e97..00000000 --- a/app/src/main/res/xml/preferences.xml +++ /dev/null @@ -1,407 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -