From ddfa9013a9b5063413ae05f594b66a1cbf09d916 Mon Sep 17 00:00:00 2001 From: lynxnb Date: Thu, 23 Feb 2023 01:14:05 +0100 Subject: [PATCH] Use a proper tag for `AppItem` in intent extras and arguments --- app/src/main/java/emu/skyline/AppDialog.kt | 5 +++-- app/src/main/java/emu/skyline/EmulationActivity.kt | 3 ++- app/src/main/java/emu/skyline/MainActivity.kt | 3 ++- app/src/main/java/emu/skyline/data/DataItem.kt | 6 ++++++ .../main/java/emu/skyline/preference/GpuDriverActivity.kt | 3 ++- .../main/java/emu/skyline/preference/GpuDriverPreference.kt | 3 ++- .../main/java/emu/skyline/settings/GameSettingsFragment.kt | 3 ++- app/src/main/java/emu/skyline/settings/SettingsActivity.kt | 3 ++- 8 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/emu/skyline/AppDialog.kt b/app/src/main/java/emu/skyline/AppDialog.kt index 375b7d18..02076650 100644 --- a/app/src/main/java/emu/skyline/AppDialog.kt +++ b/app/src/main/java/emu/skyline/AppDialog.kt @@ -21,6 +21,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.snackbar.Snackbar import emu.skyline.data.AppItem +import emu.skyline.data.AppItemTag import emu.skyline.databinding.AppDialogBinding import emu.skyline.loader.LoaderResult import emu.skyline.settings.SettingsActivity @@ -35,7 +36,7 @@ class AppDialog : BottomSheetDialogFragment() { */ fun newInstance(item : AppItem) : AppDialog { val args = Bundle() - args.putSerializable("item", item) + args.putSerializable(AppItemTag, item) val fragment = AppDialog() fragment.arguments = args @@ -45,7 +46,7 @@ class AppDialog : BottomSheetDialogFragment() { private lateinit var binding : AppDialogBinding - private val item by lazy { requireArguments().getSerializable("item")!! as AppItem } + private val item by lazy { requireArguments().getSerializable(AppItemTag)!! as AppItem } /** * This inflates the layout of the dialog after initial view creation diff --git a/app/src/main/java/emu/skyline/EmulationActivity.kt b/app/src/main/java/emu/skyline/EmulationActivity.kt index 0efd5ee9..d3b796d7 100644 --- a/app/src/main/java/emu/skyline/EmulationActivity.kt +++ b/app/src/main/java/emu/skyline/EmulationActivity.kt @@ -27,6 +27,7 @@ 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.data.AppItemTag import emu.skyline.databinding.EmuActivityBinding import emu.skyline.input.* import emu.skyline.loader.RomFile @@ -217,7 +218,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo * Populates the [item] member with data from the intent */ private fun populateAppItem() { - val intentItem = intent.getSerializableExtra("item") as AppItem? + val intentItem = intent.getSerializableExtra(AppItemTag) as AppItem? if (intentItem != null) { item = intentItem return diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt index b0ae969b..f84cb99a 100644 --- a/app/src/main/java/emu/skyline/MainActivity.kt +++ b/app/src/main/java/emu/skyline/MainActivity.kt @@ -30,6 +30,7 @@ import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint import emu.skyline.adapter.* import emu.skyline.data.AppItem +import emu.skyline.data.AppItemTag import emu.skyline.data.DataItem import emu.skyline.data.HeaderItem import emu.skyline.databinding.MainActivityBinding @@ -287,7 +288,7 @@ class MainActivity : AppCompatActivity() { AppDialog.newInstance(appItem).show(supportFragmentManager, "game") } else if (appItem.loaderResult == LoaderResult.Success) { startActivity(Intent(this, EmulationActivity::class.java).apply { - putExtra("item", appItem) + putExtra(AppItemTag, appItem) putExtra(EmulationActivity.ReturnToMainTag, true) }) } diff --git a/app/src/main/java/emu/skyline/data/DataItem.kt b/app/src/main/java/emu/skyline/data/DataItem.kt index 4fea8c97..3dfae683 100644 --- a/app/src/main/java/emu/skyline/data/DataItem.kt +++ b/app/src/main/java/emu/skyline/data/DataItem.kt @@ -6,11 +6,17 @@ package emu.skyline.data import android.content.Context +import emu.skyline.BuildConfig import emu.skyline.R import emu.skyline.loader.AppEntry import emu.skyline.loader.LoaderResult import java.io.Serializable +/** + * The tag used to pass [AppItem]s between activities and fragments + */ +const val AppItemTag = BuildConfig.APPLICATION_ID + ".APP_ITEM" + sealed class DataItem : Serializable class HeaderItem(val title : String) : DataItem() diff --git a/app/src/main/java/emu/skyline/preference/GpuDriverActivity.kt b/app/src/main/java/emu/skyline/preference/GpuDriverActivity.kt index ca37cfa1..3c27f4d4 100644 --- a/app/src/main/java/emu/skyline/preference/GpuDriverActivity.kt +++ b/app/src/main/java/emu/skyline/preference/GpuDriverActivity.kt @@ -23,6 +23,7 @@ import emu.skyline.adapter.GpuDriverViewItem import emu.skyline.adapter.SelectableGenericAdapter import emu.skyline.adapter.SpacingItemDecoration import emu.skyline.data.AppItem +import emu.skyline.data.AppItemTag import emu.skyline.databinding.GpuDriverActivityBinding import emu.skyline.settings.EmulationSettings import emu.skyline.utils.GpuDriverHelper @@ -39,7 +40,7 @@ import kotlinx.coroutines.launch class GpuDriverActivity : AppCompatActivity() { private val binding by lazy { GpuDriverActivityBinding.inflate(layoutInflater) } - private val item by lazy { intent.extras?.getSerializable("item") as AppItem? } + private val item by lazy { intent.extras?.getSerializable(AppItemTag) as AppItem? } private val adapter = SelectableGenericAdapter(0) diff --git a/app/src/main/java/emu/skyline/preference/GpuDriverPreference.kt b/app/src/main/java/emu/skyline/preference/GpuDriverPreference.kt index 2d9f19e3..af59e095 100644 --- a/app/src/main/java/emu/skyline/preference/GpuDriverPreference.kt +++ b/app/src/main/java/emu/skyline/preference/GpuDriverPreference.kt @@ -14,6 +14,7 @@ import androidx.preference.Preference import androidx.preference.Preference.SummaryProvider import androidx.preference.R import emu.skyline.data.AppItem +import emu.skyline.data.AppItemTag import emu.skyline.settings.EmulationSettings import emu.skyline.utils.GpuDriverHelper import emu.skyline.R as SkylineR @@ -56,6 +57,6 @@ class GpuDriverPreference @JvmOverloads constructor(context : Context, attrs : A * This launches [GpuDriverActivity] on click to manage driver packages */ override fun onClick() = driverCallback.launch(Intent(context, GpuDriverActivity::class.java).apply { - putExtra("item", item) + putExtra(AppItemTag, item) }) } diff --git a/app/src/main/java/emu/skyline/settings/GameSettingsFragment.kt b/app/src/main/java/emu/skyline/settings/GameSettingsFragment.kt index af67d6b6..3e9765aa 100644 --- a/app/src/main/java/emu/skyline/settings/GameSettingsFragment.kt +++ b/app/src/main/java/emu/skyline/settings/GameSettingsFragment.kt @@ -12,6 +12,7 @@ import androidx.preference.* import emu.skyline.BuildConfig import emu.skyline.R import emu.skyline.data.AppItem +import emu.skyline.data.AppItemTag import emu.skyline.preference.GpuDriverPreference import emu.skyline.preference.IntegerListPreference import emu.skyline.utils.GpuDriverHelper @@ -25,7 +26,7 @@ class GameSettingsFragment : PreferenceFragmentCompat() { private const val DIALOG_FRAGMENT_TAG = "androidx.preference.PreferenceFragment.DIALOG" } - private val item by lazy { requireArguments().getSerializable("item")!! as AppItem } + private val item by lazy { requireArguments().getSerializable(AppItemTag)!! as AppItem } override fun onViewCreated(view : View, savedInstanceState : Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/app/src/main/java/emu/skyline/settings/SettingsActivity.kt b/app/src/main/java/emu/skyline/settings/SettingsActivity.kt index 868a9b90..e3f70be0 100644 --- a/app/src/main/java/emu/skyline/settings/SettingsActivity.kt +++ b/app/src/main/java/emu/skyline/settings/SettingsActivity.kt @@ -17,6 +17,7 @@ import androidx.core.view.WindowCompat import androidx.preference.PreferenceFragmentCompat import com.google.android.material.internal.ToolbarUtils import emu.skyline.R +import emu.skyline.data.AppItemTag import emu.skyline.databinding.SettingsActivityBinding import emu.skyline.utils.WindowInsetsHelper @@ -28,7 +29,7 @@ class SettingsActivity : AppCompatActivity() { * Retrieves extras from the intent if any and instantiates the appropriate fragment */ private val preferenceFragment by lazy { - if (intent.hasExtra("item")) + if (intent.hasExtra(AppItemTag)) GameSettingsFragment().apply { arguments = intent.extras } else GlobalSettingsFragment()