From a9dd78b8bedfc80a8c5a2b24d3bf4a9113cf1121 Mon Sep 17 00:00:00 2001 From: OpenSauce04 Date: Sat, 27 Jul 2024 17:14:08 +0100 Subject: [PATCH] android: Implemented about game dialog (#304) This feature is accessible by long-pressing on a game card, replacing the old method of accessing the cheats menu The cheats menu is now accessed from within the about game dialog Adapted from https://github.com/mandarine3ds/mandarine/commit/69c323289f9e290f95b69dafb31f773ac1b56242 Co-authored-by: Ishan09811 <156402647+ishan09811@users.noreply.github.com> Co-authored-by: kleidis <167202775+kleidis@users.noreply.github.com> --- .../lime3ds/android/adapters/GameAdapter.kt | 54 ++++++- .../android/fragments/GamesFragment.kt | 3 +- .../android/fragments/SearchFragment.kt | 4 +- .../app/src/main/res/layout/card_game.xml | 4 +- .../src/main/res/layout/dialog_about_game.xml | 144 ++++++++++++++++++ .../app/src/main/res/values/strings.xml | 5 +- 6 files changed, 201 insertions(+), 13 deletions(-) create mode 100644 src/android/app/src/main/res/layout/dialog_about_game.xml diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/adapters/GameAdapter.kt b/src/android/app/src/main/java/io/github/lime3ds/android/adapters/GameAdapter.kt index 1b7aa14ec..aaf443d6f 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/adapters/GameAdapter.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/adapters/GameAdapter.kt @@ -1,4 +1,4 @@ -// Copyright 2023 Citra Emulator Project +// Copyright Citra Emulator Project / Lime3DS Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -10,6 +10,8 @@ import android.text.TextUtils import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.content.Context +import android.widget.TextView import android.widget.ImageView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity @@ -23,6 +25,9 @@ import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import com.google.android.material.color.MaterialColors import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.android.material.bottomsheet.BottomSheetDialog +import com.google.android.material.button.MaterialButton import io.github.lime3ds.android.HomeNavigationDirections import io.github.lime3ds.android.LimeApplication import io.github.lime3ds.android.R @@ -32,8 +37,10 @@ import io.github.lime3ds.android.features.cheats.ui.CheatsFragmentDirections import io.github.lime3ds.android.model.Game import io.github.lime3ds.android.utils.GameIconUtils import io.github.lime3ds.android.viewmodel.GamesViewModel +import io.github.lime3ds.android.features.settings.ui.SettingsActivity +import io.github.lime3ds.android.features.settings.utils.SettingsFile -class GameAdapter(private val activity: AppCompatActivity) : +class GameAdapter(private val activity: AppCompatActivity, private val inflater: LayoutInflater) : ListAdapter(AsyncDifferConfig.Builder(DiffCallback()).build()), View.OnClickListener, View.OnLongClickListener { private var lastClickTime = 0L @@ -83,7 +90,7 @@ class GameAdapter(private val activity: AppCompatActivity) : } /** - * Opens the cheats settings for the game that was clicked on. + * Opens the about game dialog for the game that was clicked on. * * @param view The view representing the game the user wants to play. */ @@ -99,8 +106,7 @@ class GameAdapter(private val activity: AppCompatActivity) : .setPositiveButton(android.R.string.ok, null) .show() } else { - val action = CheatsFragmentDirections.actionGlobalCheatsFragment(holder.game.titleId) - view.findNavController().navigate(action) + showAboutGameDialog(context, holder.game, holder, view) } return true } @@ -156,7 +162,8 @@ class GameAdapter(private val activity: AppCompatActivity) : binding.textGameTitle.text = game.title binding.textCompany.text = game.company - binding.textFilename.text = game.filename + binding.textGameRegion.text = game.regions + val backgroundColorId = if ( @@ -181,14 +188,45 @@ class GameAdapter(private val activity: AppCompatActivity) : binding.textCompany.ellipsize = TextUtils.TruncateAt.MARQUEE binding.textCompany.isSelected = true - binding.textFilename.ellipsize = TextUtils.TruncateAt.MARQUEE - binding.textFilename.isSelected = true + binding.textGameRegion.ellipsize = TextUtils.TruncateAt.MARQUEE + binding.textGameRegion.isSelected = true }, 3000 ) } } + private fun showAboutGameDialog(context: Context, game: Game, holder: GameViewHolder, view: View) { + val bottomSheetView = inflater.inflate(R.layout.dialog_about_game, null) + + val bottomSheetDialog = BottomSheetDialog(context) + bottomSheetDialog.setContentView(bottomSheetView) + + bottomSheetView.findViewById(R.id.about_game_title).text = game.title + bottomSheetView.findViewById(R.id.about_game_company).text = game.company + bottomSheetView.findViewById(R.id.about_game_region).text = game.regions + bottomSheetView.findViewById(R.id.about_game_id).text = "ID: " + String.format("%016X", game.titleId) + bottomSheetView.findViewById(R.id.about_game_filename).text = "File: " + game.filename + GameIconUtils.loadGameIcon(activity, game, bottomSheetView.findViewById(R.id.game_icon)) + + bottomSheetView.findViewById(R.id.about_game_play).setOnClickListener { + val action = HomeNavigationDirections.actionGlobalEmulationActivity(holder.game) + view.findNavController().navigate(action) + } + + bottomSheetView.findViewById(R.id.cheats).setOnClickListener { + val action = CheatsFragmentDirections.actionGlobalCheatsFragment(holder.game.titleId) + view.findNavController().navigate(action) + bottomSheetDialog.dismiss() + } + + val bottomSheetBehavior = bottomSheetDialog.getBehavior() + bottomSheetBehavior.skipCollapsed = true + bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED + + bottomSheetDialog.show() + } + private fun isValidGame(extension: String): Boolean { return Game.badExtensions.stream() .noneMatch { extension == it.lowercase() } diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/fragments/GamesFragment.kt b/src/android/app/src/main/java/io/github/lime3ds/android/fragments/GamesFragment.kt index f641594a2..7e7631a8d 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/fragments/GamesFragment.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/fragments/GamesFragment.kt @@ -60,13 +60,14 @@ class GamesFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { homeViewModel.setNavigationVisibility(visible = true, animated = true) homeViewModel.setStatusBarShadeVisibility(visible = true) + val inflater = LayoutInflater.from(requireContext()) binding.gridGames.apply { layoutManager = GridLayoutManager( requireContext(), resources.getInteger(R.integer.game_grid_columns) ) - adapter = GameAdapter(requireActivity() as AppCompatActivity) + adapter = GameAdapter(requireActivity() as AppCompatActivity, inflater) } binding.swipeRefresh.apply { diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/fragments/SearchFragment.kt b/src/android/app/src/main/java/io/github/lime3ds/android/fragments/SearchFragment.kt index fa633d85c..0cf91ee0b 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/fragments/SearchFragment.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/fragments/SearchFragment.kt @@ -71,12 +71,14 @@ class SearchFragment : Fragment() { binding.searchText.setText(savedInstanceState.getString(SEARCH_TEXT)) } + val inflater = LayoutInflater.from(requireContext()) + binding.gridGamesSearch.apply { layoutManager = GridLayoutManager( requireContext(), resources.getInteger(R.integer.game_grid_columns) ) - adapter = GameAdapter(requireActivity() as AppCompatActivity) + adapter = GameAdapter(requireActivity() as AppCompatActivity, inflater) } binding.chipGroup.setOnCheckedStateChangeListener { _, _ -> filterAndSearch() } diff --git a/src/android/app/src/main/res/layout/card_game.xml b/src/android/app/src/main/res/layout/card_game.xml index 6b20567cf..2c9b36895 100644 --- a/src/android/app/src/main/res/layout/card_game.xml +++ b/src/android/app/src/main/res/layout/card_game.xml @@ -64,7 +64,7 @@ tools:text="Nintendo" /> + tools:text="Region" /> diff --git a/src/android/app/src/main/res/layout/dialog_about_game.xml b/src/android/app/src/main/res/layout/dialog_about_game.xml new file mode 100644 index 000000000..696dab2c1 --- /dev/null +++ b/src/android/app/src/main/res/layout/dialog_about_game.xml @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index caf3231ff..72d63373e 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -432,10 +432,13 @@ Fatal Error A fatal error occurred. Check the log for details.\nContinuing emulation may result in crashes and bugs. - + Preparing Shaders Building Shaders + + Play + Cheats Add Cheat