From 2dbe067d746608a5c6c66c7af6a6c3d8ea3d79bf Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Tue, 29 Aug 2023 02:44:11 -0400 Subject: [PATCH] android: Support intents to emulation activity --- src/android/app/src/main/AndroidManifest.xml | 8 ++++++ .../yuzu_emu/fragments/EmulationFragment.kt | 25 ++++++++++++++++--- .../org/yuzu/yuzu_emu/utils/GameHelper.kt | 16 ++++++------ .../res/navigation/emulation_navigation.xml | 4 ++- .../main/res/navigation/home_navigation.xml | 4 ++- 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/android/app/src/main/AndroidManifest.xml b/src/android/app/src/main/AndroidManifest.xml index 933244140..832c08e15 100644 --- a/src/android/app/src/main/AndroidManifest.xml +++ b/src/android/app/src/main/AndroidManifest.xml @@ -66,6 +66,14 @@ SPDX-License-Identifier: GPL-3.0-or-later + + + + + + diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt index 09e93a017..956c35c0a 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt @@ -11,6 +11,7 @@ import android.content.SharedPreferences import android.content.pm.ActivityInfo import android.content.res.Configuration import android.graphics.Color +import android.net.Uri import android.os.Bundle import android.os.Handler import android.os.Looper @@ -47,6 +48,7 @@ import org.yuzu.yuzu_emu.features.settings.model.IntSetting import org.yuzu.yuzu_emu.features.settings.model.Settings import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile +import org.yuzu.yuzu_emu.model.Game import org.yuzu.yuzu_emu.overlay.InputOverlay import org.yuzu.yuzu_emu.utils.* @@ -59,7 +61,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { private var _binding: FragmentEmulationBinding? = null private val binding get() = _binding!! - val args by navArgs() + private val args by navArgs() + + private lateinit var game: Game private var isInFoldableLayout = false @@ -87,10 +91,25 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + val intentUri: Uri? = requireActivity().intent.data + var intentGame: Game? = null + if (intentUri != null) { + intentGame = if (Game.extensions.contains(FileUtil.getExtension(intentUri))) { + GameHelper.getGame(requireActivity().intent.data!!, false) + } else { + null + } + } + game = if (args.game != null) { + args.game!! + } else { + intentGame ?: error("[EmulationFragment] No bootable game present!") + } + // So this fragment doesn't restart on configuration changes; i.e. rotation. retainInstance = true preferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) - emulationState = EmulationState(args.game.path) + emulationState = EmulationState(game.path) } /** @@ -114,7 +133,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { updateShowFpsOverlay() binding.inGameMenu.getHeaderView(0).findViewById(R.id.text_game_title).text = - args.game.title + game.title binding.inGameMenu.setNavigationItemSelectedListener { when (it.itemId) { R.id.menu_pause_emulation -> { diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameHelper.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameHelper.kt index f71d0a098..e0ee29c9b 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameHelper.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameHelper.kt @@ -63,13 +63,13 @@ object GameHelper { ) } else { if (Game.extensions.contains(FileUtil.getExtension(it.uri))) { - games.add(getGame(it.uri)) + games.add(getGame(it.uri, true)) } } } } - private fun getGame(uri: Uri): Game { + fun getGame(uri: Uri, addedToLibrary: Boolean): Game { val filePath = uri.toString() var name = NativeLibrary.getTitle(filePath) @@ -94,11 +94,13 @@ object GameHelper { NativeLibrary.isHomebrew(filePath) ) - val addedTime = preferences.getLong(newGame.keyAddedToLibraryTime, 0L) - if (addedTime == 0L) { - preferences.edit() - .putLong(newGame.keyAddedToLibraryTime, System.currentTimeMillis()) - .apply() + if (addedToLibrary) { + val addedTime = preferences.getLong(newGame.keyAddedToLibraryTime, 0L) + if (addedTime == 0L) { + preferences.edit() + .putLong(newGame.keyAddedToLibraryTime, System.currentTimeMillis()) + .apply() + } } return newGame diff --git a/src/android/app/src/main/res/navigation/emulation_navigation.xml b/src/android/app/src/main/res/navigation/emulation_navigation.xml index 8208f4c2c..cd1d36a12 100644 --- a/src/android/app/src/main/res/navigation/emulation_navigation.xml +++ b/src/android/app/src/main/res/navigation/emulation_navigation.xml @@ -12,7 +12,9 @@ tools:layout="@layout/fragment_emulation" > + app:argType="org.yuzu.yuzu_emu.model.Game" + app:nullable="true" + android:defaultValue="@null" /> diff --git a/src/android/app/src/main/res/navigation/home_navigation.xml b/src/android/app/src/main/res/navigation/home_navigation.xml index fcebba726..42f987fed 100644 --- a/src/android/app/src/main/res/navigation/home_navigation.xml +++ b/src/android/app/src/main/res/navigation/home_navigation.xml @@ -62,7 +62,9 @@ android:label="EmulationActivity"> + app:argType="org.yuzu.yuzu_emu.model.Game" + app:nullable="true" + android:defaultValue="@null" />