From 2f4778247c00c4a439dfd325b131488d3efd04a7 Mon Sep 17 00:00:00 2001 From: lynxnb Date: Thu, 23 Feb 2023 01:02:53 +0100 Subject: [PATCH] Use per-game settings during emulation --- app/src/main/java/emu/skyline/AppDialog.kt | 4 ++- .../java/emu/skyline/EmulationActivity.kt | 32 +++++++++++++++++-- app/src/main/java/emu/skyline/MainActivity.kt | 5 ++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/emu/skyline/AppDialog.kt b/app/src/main/java/emu/skyline/AppDialog.kt index e5d0283b..375b7d18 100644 --- a/app/src/main/java/emu/skyline/AppDialog.kt +++ b/app/src/main/java/emu/skyline/AppDialog.kt @@ -73,7 +73,9 @@ class AppDialog : BottomSheetDialogFragment() { binding.gamePlay.isEnabled = item.loaderResult == LoaderResult.Success binding.gamePlay.setOnClickListener { - startActivity(Intent(activity, EmulationActivity::class.java).apply { data = item.uri }) + startActivity(Intent(activity, EmulationActivity::class.java).apply { + putExtras(requireArguments()) + }) } binding.gameSettings.isEnabled = item.loaderResult == LoaderResult.Success diff --git a/app/src/main/java/emu/skyline/EmulationActivity.kt b/app/src/main/java/emu/skyline/EmulationActivity.kt index cbd7bbbf..0efd5ee9 100644 --- a/app/src/main/java/emu/skyline/EmulationActivity.kt +++ b/app/src/main/java/emu/skyline/EmulationActivity.kt @@ -26,8 +26,10 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.hilt.android.AndroidEntryPoint import emu.skyline.applet.swkbd.SoftwareKeyboardConfig import emu.skyline.applet.swkbd.SoftwareKeyboardDialog +import emu.skyline.data.AppItem import emu.skyline.databinding.EmuActivityBinding import emu.skyline.input.* +import emu.skyline.loader.RomFile import emu.skyline.loader.getRomFormat import emu.skyline.settings.AppSettings import emu.skyline.settings.EmulationSettings @@ -54,6 +56,11 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo private val binding by lazy { EmuActivityBinding.inflate(layoutInflater) } + /** + * The [AppItem] of the app that is being emulated + */ + lateinit var item : AppItem + /** * A map of [Vibrator]s that correspond to [InputManager.controllers] */ @@ -191,8 +198,8 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo shouldFinish = true returnToMain = intent.getBooleanExtra(ReturnToMainTag, false) - val rom = intent.data!! - val romType = getRomFormat(rom, contentResolver).ordinal + val rom = item.uri + val romType = item.format.ordinal @SuppressLint("Recycle") val romFd = contentResolver.openFileDescriptor(rom, "r")!! @@ -206,10 +213,29 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo emulationThread!!.start() } + /** + * Populates the [item] member with data from the intent + */ + private fun populateAppItem() { + val intentItem = intent.getSerializableExtra("item") as AppItem? + if (intentItem != null) { + item = intentItem + return + } + + // The intent did not contain an app item, fall back to the data URI + val uri = intent.data!! + val romFormat = getRomFormat(uri, contentResolver) + val romFile = RomFile(this, romFormat, uri, EmulationSettings.global.systemLanguage) + + item = AppItem(romFile.takeIf { it.valid }!!.appEntry) + } + @SuppressLint("SetTextI18n", "ClickableViewAccessibility") override fun onCreate(savedInstanceState : Bundle?) { super.onCreate(savedInstanceState) - emulationSettings = EmulationSettings.global + populateAppItem() + emulationSettings = EmulationSettings.forEmulation(item.titleId ?: item.key()) requestedOrientation = emulationSettings.orientation window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt index a1bc4dd8..b0ae969b 100644 --- a/app/src/main/java/emu/skyline/MainActivity.kt +++ b/app/src/main/java/emu/skyline/MainActivity.kt @@ -286,7 +286,10 @@ class MainActivity : AppCompatActivity() { if (appSettings.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); addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) }) + startActivity(Intent(this, EmulationActivity::class.java).apply { + putExtra("item", appItem) + putExtra(EmulationActivity.ReturnToMainTag, true) + }) } }