mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-23 15:31:52 +01:00
Rename Settings
Kotlin class to PreferenceSettings
SharedPreferences will be partially swapped out in the future to support per-game settings. In the meantime, make it clear from which class settings are coming from.
This commit is contained in:
parent
3b27540250
commit
5b4ca79dc8
@ -28,8 +28,8 @@ import emu.skyline.applet.swkbd.SoftwareKeyboardDialog
|
||||
import emu.skyline.databinding.EmuActivityBinding
|
||||
import emu.skyline.input.*
|
||||
import emu.skyline.loader.getRomFormat
|
||||
import emu.skyline.utils.PreferenceSettings
|
||||
import emu.skyline.utils.ByteBufferSerializable
|
||||
import emu.skyline.utils.Settings
|
||||
import emu.skyline.utils.SettingsValues
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
@ -74,7 +74,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
var desiredRefreshRate = 60f
|
||||
|
||||
@Inject
|
||||
lateinit var settings : Settings
|
||||
lateinit var preferenceSettings : PreferenceSettings
|
||||
|
||||
@Inject
|
||||
lateinit var inputManager : InputManager
|
||||
@ -172,7 +172,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
if (controller.type != ControllerType.None) {
|
||||
val type = when (controller.type) {
|
||||
ControllerType.None -> throw IllegalArgumentException()
|
||||
ControllerType.HandheldProController -> if (settings.isDocked) ControllerType.ProController.id else ControllerType.HandheldProController.id
|
||||
ControllerType.HandheldProController -> if (preferenceSettings.isDocked) ControllerType.ProController.id else ControllerType.HandheldProController.id
|
||||
ControllerType.ProController, ControllerType.JoyConLeft, ControllerType.JoyConRight -> controller.type.id
|
||||
}
|
||||
|
||||
@ -249,7 +249,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
val romFd = contentResolver.openFileDescriptor(rom, "r")!!
|
||||
|
||||
emulationThread = Thread {
|
||||
executeApplication(rom.toString(), romType, romFd.detachFd(), SettingsValues(settings), applicationContext.getPublicFilesDir().canonicalPath + "/", applicationContext.filesDir.canonicalPath + "/", applicationInfo.nativeLibraryDir + "/", assets)
|
||||
executeApplication(rom.toString(), romType, romFd.detachFd(), SettingsValues(preferenceSettings), applicationContext.getPublicFilesDir().canonicalPath + "/", applicationContext.filesDir.canonicalPath + "/", applicationInfo.nativeLibraryDir + "/", assets)
|
||||
returnFromEmulation()
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
@SuppressLint("SetTextI18n", "ClickableViewAccessibility")
|
||||
override fun onCreate(savedInstanceState : Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
requestedOrientation = settings.orientation
|
||||
requestedOrientation = preferenceSettings.orientation
|
||||
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||
setContentView(binding.root)
|
||||
|
||||
@ -278,7 +278,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.respectDisplayCutout) {
|
||||
if (preferenceSettings.respectDisplayCutout) {
|
||||
binding.perfStats.setOnApplyWindowInsetsListener(insetsOrMarginHandler)
|
||||
binding.onScreenControllerToggle.setOnApplyWindowInsetsListener(insetsOrMarginHandler)
|
||||
}
|
||||
@ -286,14 +286,14 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
binding.gameView.holder.addCallback(this)
|
||||
|
||||
binding.gameView.setAspectRatio(
|
||||
when (settings.aspectRatio) {
|
||||
when (preferenceSettings.aspectRatio) {
|
||||
0 -> Rational(16, 9)
|
||||
1 -> Rational(21, 9)
|
||||
else -> null
|
||||
}
|
||||
)
|
||||
|
||||
if (settings.perfStats) {
|
||||
if (preferenceSettings.perfStats) {
|
||||
binding.perfStats.apply {
|
||||
postDelayed(object : Runnable {
|
||||
override fun run() {
|
||||
@ -305,7 +305,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
}
|
||||
}
|
||||
|
||||
force60HzRefreshRate(!settings.maxRefreshRate)
|
||||
force60HzRefreshRate(!preferenceSettings.maxRefreshRate)
|
||||
getSystemService<DisplayManager>()?.registerDisplayListener(this, null)
|
||||
|
||||
binding.gameView.setOnTouchListener(this)
|
||||
@ -314,11 +314,11 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
binding.onScreenControllerView.apply {
|
||||
inputManager.controllers[0]!!.type.let {
|
||||
controllerType = it
|
||||
isGone = it == ControllerType.None || !settings.onScreenControl
|
||||
isGone = it == ControllerType.None || !preferenceSettings.onScreenControl
|
||||
}
|
||||
setOnButtonStateChangedListener(::onButtonStateChanged)
|
||||
setOnStickStateChangedListener(::onStickStateChanged)
|
||||
recenterSticks = settings.onScreenControlRecenterSticks
|
||||
recenterSticks = preferenceSettings.onScreenControlRecenterSticks
|
||||
}
|
||||
|
||||
binding.onScreenControllerToggle.apply {
|
||||
@ -380,7 +380,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||
// Note: We need FRAME_RATE_COMPATIBILITY_FIXED_SOURCE as there will be a degradation of user experience with FRAME_RATE_COMPATIBILITY_DEFAULT due to game speed alterations when the frame rate doesn't match the display refresh rate
|
||||
holder.surface.setFrameRate(desiredRefreshRate, if (settings.maxRefreshRate) Surface.FRAME_RATE_COMPATIBILITY_DEFAULT else Surface.FRAME_RATE_COMPATIBILITY_FIXED_SOURCE)
|
||||
holder.surface.setFrameRate(desiredRefreshRate, if (preferenceSettings.maxRefreshRate) Surface.FRAME_RATE_COMPATIBILITY_DEFAULT else Surface.FRAME_RATE_COMPATIBILITY_FIXED_SOURCE)
|
||||
|
||||
while (emulationThread!!.isAlive)
|
||||
if (setSurface(holder.surface))
|
||||
@ -394,7 +394,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
Log.d(Tag, "surfaceChanged Holder: $holder, Format: $format, Width: $width, Height: $height")
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||
holder.surface.setFrameRate(desiredRefreshRate, if (settings.maxRefreshRate) Surface.FRAME_RATE_COMPATIBILITY_DEFAULT else Surface.FRAME_RATE_COMPATIBILITY_FIXED_SOURCE)
|
||||
holder.surface.setFrameRate(desiredRefreshRate, if (preferenceSettings.maxRefreshRate) Surface.FRAME_RATE_COMPATIBILITY_DEFAULT else Surface.FRAME_RATE_COMPATIBILITY_FIXED_SOURCE)
|
||||
}
|
||||
|
||||
override fun surfaceDestroyed(holder : SurfaceHolder) {
|
||||
@ -651,7 +651,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
override fun onDisplayChanged(displayId : Int) {
|
||||
val display = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) display!! else windowManager.defaultDisplay
|
||||
if (display.displayId == displayId)
|
||||
force60HzRefreshRate(!settings.maxRefreshRate)
|
||||
force60HzRefreshRate(!preferenceSettings.maxRefreshRate)
|
||||
}
|
||||
|
||||
override fun onDisplayAdded(displayId : Int) {}
|
||||
|
@ -35,8 +35,8 @@ import emu.skyline.databinding.MainActivityBinding
|
||||
import emu.skyline.loader.AppEntry
|
||||
import emu.skyline.loader.LoaderResult
|
||||
import emu.skyline.loader.RomFormat
|
||||
import emu.skyline.utils.PreferenceSettings
|
||||
import emu.skyline.provider.DocumentsProvider
|
||||
import emu.skyline.utils.Settings
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.ceil
|
||||
|
||||
@ -50,11 +50,11 @@ class MainActivity : AppCompatActivity() {
|
||||
private val binding by lazy { MainActivityBinding.inflate(layoutInflater) }
|
||||
|
||||
@Inject
|
||||
lateinit var settings : Settings
|
||||
lateinit var preferenceSettings : PreferenceSettings
|
||||
|
||||
private val adapter = GenericAdapter()
|
||||
|
||||
private val layoutType get() = LayoutType.values()[settings.layoutType]
|
||||
private val layoutType get() = LayoutType.values()[preferenceSettings.layoutType]
|
||||
|
||||
private val missingIcon by lazy { ContextCompat.getDrawable(this, R.drawable.default_icon)!!.toBitmap(256, 256) }
|
||||
|
||||
@ -77,14 +77,14 @@ class MainActivity : AppCompatActivity() {
|
||||
private val documentPicker = registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) {
|
||||
it?.let { uri ->
|
||||
contentResolver.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
settings.searchLocation = uri.toString()
|
||||
preferenceSettings.searchLocation = uri.toString()
|
||||
|
||||
loadRoms(false)
|
||||
}
|
||||
}
|
||||
|
||||
private val settingsCallback = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
if (settings.refreshRequired) loadRoms(false)
|
||||
if (preferenceSettings.refreshRequired) loadRoms(false)
|
||||
}
|
||||
|
||||
private fun AppItem.toViewItem() = AppViewItem(layoutType, this, missingIcon, ::selectStartGame, ::selectShowGameDialog)
|
||||
@ -92,7 +92,7 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState : Bundle?) {
|
||||
// Need to create new instance of settings, dependency injection happens
|
||||
AppCompatDelegate.setDefaultNightMode(
|
||||
when ((Settings(this).appTheme)) {
|
||||
when ((PreferenceSettings(this).appTheme)) {
|
||||
0 -> AppCompatDelegate.MODE_NIGHT_NO
|
||||
1 -> AppCompatDelegate.MODE_NIGHT_YES
|
||||
2 -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
@ -106,8 +106,8 @@ class MainActivity : AppCompatActivity() {
|
||||
PreferenceManager.setDefaultValues(this, R.xml.preferences, false)
|
||||
|
||||
adapter.apply {
|
||||
setHeaderItems(listOf(HeaderRomFilterItem(formatOrder, if (settings.romFormatFilter == 0) null else formatOrder[settings.romFormatFilter - 1]) { romFormat ->
|
||||
settings.romFormatFilter = romFormat?.let { formatOrder.indexOf(romFormat) + 1 } ?: 0
|
||||
setHeaderItems(listOf(HeaderRomFilterItem(formatOrder, if (preferenceSettings.romFormatFilter == 0) null else formatOrder[preferenceSettings.romFormatFilter - 1]) { romFormat ->
|
||||
preferenceSettings.romFormatFilter = romFormat?.let { formatOrder.indexOf(romFormat) + 1 } ?: 0
|
||||
formatFilter = romFormat
|
||||
populateAdapter()
|
||||
}))
|
||||
@ -127,7 +127,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
viewModel.stateData.observe(this, ::handleState)
|
||||
loadRoms(!settings.refreshRequired)
|
||||
loadRoms(!preferenceSettings.refreshRequired)
|
||||
|
||||
binding.searchBar.apply {
|
||||
binding.logIcon.setOnClickListener {
|
||||
@ -236,7 +236,7 @@ class MainActivity : AppCompatActivity() {
|
||||
binding.appList.layoutManager = CustomLayoutManager(gridSpan)
|
||||
setAppListDecoration()
|
||||
|
||||
if (settings.searchLocation.isEmpty()) documentPicker.launch(null)
|
||||
if (preferenceSettings.searchLocation.isEmpty()) documentPicker.launch(null)
|
||||
}
|
||||
|
||||
private fun getDataItems() = mutableListOf<DataItem>().apply {
|
||||
@ -270,7 +270,7 @@ class MainActivity : AppCompatActivity() {
|
||||
private fun selectStartGame(appItem : AppItem) {
|
||||
if (binding.swipeRefreshLayout.isRefreshing) return
|
||||
|
||||
if (settings.selectAction) {
|
||||
if (preferenceSettings.selectAction) {
|
||||
AppDialog.newInstance(appItem).show(supportFragmentManager, "game")
|
||||
} else if (appItem.loaderResult == LoaderResult.Success) {
|
||||
startActivity(Intent(this, EmulationActivity::class.java).apply { data = appItem.uri; putExtra(EmulationActivity.ReturnToMainTag, true) })
|
||||
@ -284,8 +284,8 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun loadRoms(loadFromFile : Boolean) {
|
||||
viewModel.loadRoms(this, loadFromFile, Uri.parse(settings.searchLocation), settings.systemLanguage)
|
||||
settings.refreshRequired = false
|
||||
viewModel.loadRoms(this, loadFromFile, Uri.parse(preferenceSettings.searchLocation), preferenceSettings.systemLanguage)
|
||||
preferenceSettings.refreshRequired = false
|
||||
}
|
||||
|
||||
private fun populateAdapter() {
|
||||
|
@ -11,7 +11,7 @@ import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.EntryPointAccessors
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import emu.skyline.input.InputManager
|
||||
import emu.skyline.utils.Settings
|
||||
import emu.skyline.utils.PreferenceSettings
|
||||
|
||||
@EntryPoint
|
||||
@InstallIn(SingletonComponent::class)
|
||||
@ -24,7 +24,7 @@ fun Context.getInputManager() = EntryPointAccessors.fromApplication(this, InputM
|
||||
@EntryPoint
|
||||
@InstallIn(SingletonComponent::class)
|
||||
interface SettingsProviderEntryPoint {
|
||||
fun settings() : Settings
|
||||
fun preferenceSettings() : PreferenceSettings
|
||||
}
|
||||
|
||||
fun Context.getSettings() = EntryPointAccessors.fromApplication(this, SettingsProviderEntryPoint::class.java).settings()
|
||||
fun Context.getSettings() = EntryPointAccessors.fromApplication(this, SettingsProviderEntryPoint::class.java).preferenceSettings()
|
||||
|
@ -29,7 +29,7 @@ import emu.skyline.input.dialog.ButtonDialog
|
||||
import emu.skyline.input.dialog.RumbleDialog
|
||||
import emu.skyline.input.dialog.StickDialog
|
||||
import emu.skyline.input.onscreen.OnScreenEditActivity
|
||||
import emu.skyline.utils.Settings
|
||||
import emu.skyline.utils.PreferenceSettings
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
@ -61,7 +61,7 @@ class ControllerActivity : AppCompatActivity() {
|
||||
val buttonItems = mutableListOf<ControllerButtonViewItem>()
|
||||
|
||||
@Inject
|
||||
lateinit var settings : Settings
|
||||
lateinit var preferenceSettings : PreferenceSettings
|
||||
|
||||
@Inject
|
||||
lateinit var inputManager : InputManager
|
||||
@ -84,14 +84,14 @@ class ControllerActivity : AppCompatActivity() {
|
||||
items.add(ControllerHeaderItem(getString(R.string.osc)))
|
||||
|
||||
val oscSummary = { checked : Boolean -> getString(if (checked) R.string.osc_shown else R.string.osc_not_shown) }
|
||||
items.add(ControllerCheckBoxViewItem(getString(R.string.osc_enable), oscSummary.invoke(settings.onScreenControl), settings.onScreenControl) { item, position ->
|
||||
items.add(ControllerCheckBoxViewItem(getString(R.string.osc_enable), oscSummary.invoke(preferenceSettings.onScreenControl), preferenceSettings.onScreenControl) { item, position ->
|
||||
item.summary = oscSummary.invoke(item.checked)
|
||||
settings.onScreenControl = item.checked
|
||||
preferenceSettings.onScreenControl = item.checked
|
||||
adapter.notifyItemChanged(position)
|
||||
})
|
||||
|
||||
items.add(ControllerCheckBoxViewItem(getString(R.string.osc_recenter_sticks), "", settings.onScreenControlRecenterSticks) { item, position ->
|
||||
settings.onScreenControlRecenterSticks = item.checked
|
||||
items.add(ControllerCheckBoxViewItem(getString(R.string.osc_recenter_sticks), "", preferenceSettings.onScreenControlRecenterSticks) { item, position ->
|
||||
preferenceSettings.onScreenControlRecenterSticks = item.checked
|
||||
adapter.notifyItemChanged(position)
|
||||
})
|
||||
|
||||
|
@ -15,7 +15,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import emu.skyline.R
|
||||
import emu.skyline.databinding.OnScreenEditActivityBinding
|
||||
import emu.skyline.utils.Settings
|
||||
import emu.skyline.utils.PreferenceSettings
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
@ -26,7 +26,7 @@ class OnScreenEditActivity : AppCompatActivity() {
|
||||
private var editMode = false
|
||||
|
||||
@Inject
|
||||
lateinit var settings : Settings
|
||||
lateinit var preferenceSettings : PreferenceSettings
|
||||
|
||||
private val closeAction : () -> Unit = {
|
||||
if (editMode) {
|
||||
@ -101,7 +101,7 @@ class OnScreenEditActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
binding.onScreenControllerView.recenterSticks = settings.onScreenControlRecenterSticks
|
||||
binding.onScreenControllerView.recenterSticks = preferenceSettings.onScreenControlRecenterSticks
|
||||
|
||||
actions.forEach { pair ->
|
||||
binding.fabParent.addView(LayoutInflater.from(this).inflate(R.layout.on_screen_edit_mini_fab, binding.fabParent, false).apply {
|
||||
|
@ -13,7 +13,7 @@ import javax.inject.Singleton
|
||||
import emu.skyline.R
|
||||
|
||||
@Singleton
|
||||
class Settings @Inject constructor(@ApplicationContext private val context : Context) {
|
||||
class PreferenceSettings @Inject constructor(@ApplicationContext private val context : Context) {
|
||||
// Emulator
|
||||
var searchLocation by sharedPreferences(context, "")
|
||||
var appTheme by sharedPreferences(context, 2)
|
@ -7,7 +7,7 @@ package emu.skyline.utils
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
class SettingsValues(pref: Settings) : Serializable {
|
||||
class SettingsValues(pref: PreferenceSettings) : Serializable {
|
||||
var isDocked : Boolean = pref.isDocked
|
||||
var usernameValue : String = pref.usernameValue
|
||||
var systemLanguage : Int = pref.systemLanguage
|
||||
|
Loading…
Reference in New Issue
Block a user