Use a proper tag for AppItem in intent extras and arguments

This commit is contained in:
lynxnb 2023-02-23 01:14:05 +01:00 committed by Niccolò Betto
parent 2f4778247c
commit ddfa9013a9
8 changed files with 21 additions and 8 deletions

View File

@ -21,6 +21,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import emu.skyline.data.AppItem import emu.skyline.data.AppItem
import emu.skyline.data.AppItemTag
import emu.skyline.databinding.AppDialogBinding import emu.skyline.databinding.AppDialogBinding
import emu.skyline.loader.LoaderResult import emu.skyline.loader.LoaderResult
import emu.skyline.settings.SettingsActivity import emu.skyline.settings.SettingsActivity
@ -35,7 +36,7 @@ class AppDialog : BottomSheetDialogFragment() {
*/ */
fun newInstance(item : AppItem) : AppDialog { fun newInstance(item : AppItem) : AppDialog {
val args = Bundle() val args = Bundle()
args.putSerializable("item", item) args.putSerializable(AppItemTag, item)
val fragment = AppDialog() val fragment = AppDialog()
fragment.arguments = args fragment.arguments = args
@ -45,7 +46,7 @@ class AppDialog : BottomSheetDialogFragment() {
private lateinit var binding : AppDialogBinding 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 * This inflates the layout of the dialog after initial view creation

View File

@ -27,6 +27,7 @@ import dagger.hilt.android.AndroidEntryPoint
import emu.skyline.applet.swkbd.SoftwareKeyboardConfig import emu.skyline.applet.swkbd.SoftwareKeyboardConfig
import emu.skyline.applet.swkbd.SoftwareKeyboardDialog import emu.skyline.applet.swkbd.SoftwareKeyboardDialog
import emu.skyline.data.AppItem import emu.skyline.data.AppItem
import emu.skyline.data.AppItemTag
import emu.skyline.databinding.EmuActivityBinding import emu.skyline.databinding.EmuActivityBinding
import emu.skyline.input.* import emu.skyline.input.*
import emu.skyline.loader.RomFile 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 * Populates the [item] member with data from the intent
*/ */
private fun populateAppItem() { private fun populateAppItem() {
val intentItem = intent.getSerializableExtra("item") as AppItem? val intentItem = intent.getSerializableExtra(AppItemTag) as AppItem?
if (intentItem != null) { if (intentItem != null) {
item = intentItem item = intentItem
return return

View File

@ -30,6 +30,7 @@ import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import emu.skyline.adapter.* import emu.skyline.adapter.*
import emu.skyline.data.AppItem import emu.skyline.data.AppItem
import emu.skyline.data.AppItemTag
import emu.skyline.data.DataItem import emu.skyline.data.DataItem
import emu.skyline.data.HeaderItem import emu.skyline.data.HeaderItem
import emu.skyline.databinding.MainActivityBinding import emu.skyline.databinding.MainActivityBinding
@ -287,7 +288,7 @@ class MainActivity : AppCompatActivity() {
AppDialog.newInstance(appItem).show(supportFragmentManager, "game") AppDialog.newInstance(appItem).show(supportFragmentManager, "game")
} else if (appItem.loaderResult == LoaderResult.Success) { } else if (appItem.loaderResult == LoaderResult.Success) {
startActivity(Intent(this, EmulationActivity::class.java).apply { startActivity(Intent(this, EmulationActivity::class.java).apply {
putExtra("item", appItem) putExtra(AppItemTag, appItem)
putExtra(EmulationActivity.ReturnToMainTag, true) putExtra(EmulationActivity.ReturnToMainTag, true)
}) })
} }

View File

@ -6,11 +6,17 @@
package emu.skyline.data package emu.skyline.data
import android.content.Context import android.content.Context
import emu.skyline.BuildConfig
import emu.skyline.R import emu.skyline.R
import emu.skyline.loader.AppEntry import emu.skyline.loader.AppEntry
import emu.skyline.loader.LoaderResult import emu.skyline.loader.LoaderResult
import java.io.Serializable 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 sealed class DataItem : Serializable
class HeaderItem(val title : String) : DataItem() class HeaderItem(val title : String) : DataItem()

View File

@ -23,6 +23,7 @@ import emu.skyline.adapter.GpuDriverViewItem
import emu.skyline.adapter.SelectableGenericAdapter import emu.skyline.adapter.SelectableGenericAdapter
import emu.skyline.adapter.SpacingItemDecoration import emu.skyline.adapter.SpacingItemDecoration
import emu.skyline.data.AppItem import emu.skyline.data.AppItem
import emu.skyline.data.AppItemTag
import emu.skyline.databinding.GpuDriverActivityBinding import emu.skyline.databinding.GpuDriverActivityBinding
import emu.skyline.settings.EmulationSettings import emu.skyline.settings.EmulationSettings
import emu.skyline.utils.GpuDriverHelper import emu.skyline.utils.GpuDriverHelper
@ -39,7 +40,7 @@ import kotlinx.coroutines.launch
class GpuDriverActivity : AppCompatActivity() { class GpuDriverActivity : AppCompatActivity() {
private val binding by lazy { GpuDriverActivityBinding.inflate(layoutInflater) } 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) private val adapter = SelectableGenericAdapter(0)

View File

@ -14,6 +14,7 @@ import androidx.preference.Preference
import androidx.preference.Preference.SummaryProvider import androidx.preference.Preference.SummaryProvider
import androidx.preference.R import androidx.preference.R
import emu.skyline.data.AppItem import emu.skyline.data.AppItem
import emu.skyline.data.AppItemTag
import emu.skyline.settings.EmulationSettings import emu.skyline.settings.EmulationSettings
import emu.skyline.utils.GpuDriverHelper import emu.skyline.utils.GpuDriverHelper
import emu.skyline.R as SkylineR 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 * This launches [GpuDriverActivity] on click to manage driver packages
*/ */
override fun onClick() = driverCallback.launch(Intent(context, GpuDriverActivity::class.java).apply { override fun onClick() = driverCallback.launch(Intent(context, GpuDriverActivity::class.java).apply {
putExtra("item", item) putExtra(AppItemTag, item)
}) })
} }

View File

@ -12,6 +12,7 @@ import androidx.preference.*
import emu.skyline.BuildConfig import emu.skyline.BuildConfig
import emu.skyline.R import emu.skyline.R
import emu.skyline.data.AppItem import emu.skyline.data.AppItem
import emu.skyline.data.AppItemTag
import emu.skyline.preference.GpuDriverPreference import emu.skyline.preference.GpuDriverPreference
import emu.skyline.preference.IntegerListPreference import emu.skyline.preference.IntegerListPreference
import emu.skyline.utils.GpuDriverHelper import emu.skyline.utils.GpuDriverHelper
@ -25,7 +26,7 @@ class GameSettingsFragment : PreferenceFragmentCompat() {
private const val DIALOG_FRAGMENT_TAG = "androidx.preference.PreferenceFragment.DIALOG" 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?) { override fun onViewCreated(view : View, savedInstanceState : Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)

View File

@ -17,6 +17,7 @@ import androidx.core.view.WindowCompat
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import com.google.android.material.internal.ToolbarUtils import com.google.android.material.internal.ToolbarUtils
import emu.skyline.R import emu.skyline.R
import emu.skyline.data.AppItemTag
import emu.skyline.databinding.SettingsActivityBinding import emu.skyline.databinding.SettingsActivityBinding
import emu.skyline.utils.WindowInsetsHelper import emu.skyline.utils.WindowInsetsHelper
@ -28,7 +29,7 @@ class SettingsActivity : AppCompatActivity() {
* Retrieves extras from the intent if any and instantiates the appropriate fragment * Retrieves extras from the intent if any and instantiates the appropriate fragment
*/ */
private val preferenceFragment by lazy { private val preferenceFragment by lazy {
if (intent.hasExtra("item")) if (intent.hasExtra(AppItemTag))
GameSettingsFragment().apply { arguments = intent.extras } GameSettingsFragment().apply { arguments = intent.extras }
else else
GlobalSettingsFragment() GlobalSettingsFragment()