diff options
| author | 2023-05-22 18:32:18 -0400 | |
|---|---|---|
| committer | 2023-06-03 00:06:03 -0700 | |
| commit | 5dbf842a46a68de87471c3f8e265f284ebc2c362 (patch) | |
| tree | 3a5bc0415ee8c9658dee42d443f7a906a6478e19 /src/android | |
| parent | android: Clean up dependencies (diff) | |
| download | yuzu-5dbf842a46a68de87471c3f8e265f284ebc2c362.tar.gz yuzu-5dbf842a46a68de87471c3f8e265f284ebc2c362.tar.xz yuzu-5dbf842a46a68de87471c3f8e265f284ebc2c362.zip | |
android: Improve missing game handling
Previously the app would crash if you selected a game that no longer existed. Now we show an error message and reload the games list to remove any invalid games from the list.
Diffstat (limited to 'src/android')
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt | 19 | ||||
| -rw-r--r-- | src/android/app/src/main/res/values/strings.xml | 1 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt index a9653475f..7f9e2e2d4 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt | |||
| @@ -3,15 +3,18 @@ | |||
| 3 | 3 | ||
| 4 | package org.yuzu.yuzu_emu.adapters | 4 | package org.yuzu.yuzu_emu.adapters |
| 5 | 5 | ||
| 6 | import android.annotation.SuppressLint | ||
| 7 | import android.graphics.Bitmap | 6 | import android.graphics.Bitmap |
| 8 | import android.graphics.BitmapFactory | 7 | import android.graphics.BitmapFactory |
| 8 | import android.net.Uri | ||
| 9 | import android.text.TextUtils | 9 | import android.text.TextUtils |
| 10 | import android.view.LayoutInflater | 10 | import android.view.LayoutInflater |
| 11 | import android.view.View | 11 | import android.view.View |
| 12 | import android.view.ViewGroup | 12 | import android.view.ViewGroup |
| 13 | import android.widget.ImageView | 13 | import android.widget.ImageView |
| 14 | import android.widget.Toast | ||
| 14 | import androidx.appcompat.app.AppCompatActivity | 15 | import androidx.appcompat.app.AppCompatActivity |
| 16 | import androidx.documentfile.provider.DocumentFile | ||
| 17 | import androidx.lifecycle.ViewModelProvider | ||
| 15 | import androidx.lifecycle.lifecycleScope | 18 | import androidx.lifecycle.lifecycleScope |
| 16 | import androidx.preference.PreferenceManager | 19 | import androidx.preference.PreferenceManager |
| 17 | import androidx.recyclerview.widget.AsyncDifferConfig | 20 | import androidx.recyclerview.widget.AsyncDifferConfig |
| @@ -27,6 +30,7 @@ import org.yuzu.yuzu_emu.databinding.CardGameBinding | |||
| 27 | import org.yuzu.yuzu_emu.activities.EmulationActivity | 30 | import org.yuzu.yuzu_emu.activities.EmulationActivity |
| 28 | import org.yuzu.yuzu_emu.model.Game | 31 | import org.yuzu.yuzu_emu.model.Game |
| 29 | import org.yuzu.yuzu_emu.adapters.GameAdapter.GameViewHolder | 32 | import org.yuzu.yuzu_emu.adapters.GameAdapter.GameViewHolder |
| 33 | import org.yuzu.yuzu_emu.model.GamesViewModel | ||
| 30 | 34 | ||
| 31 | class GameAdapter(private val activity: AppCompatActivity) : | 35 | class GameAdapter(private val activity: AppCompatActivity) : |
| 32 | ListAdapter<Game, GameViewHolder>(AsyncDifferConfig.Builder(DiffCallback()).build()), | 36 | ListAdapter<Game, GameViewHolder>(AsyncDifferConfig.Builder(DiffCallback()).build()), |
| @@ -53,6 +57,19 @@ class GameAdapter(private val activity: AppCompatActivity) : | |||
| 53 | */ | 57 | */ |
| 54 | override fun onClick(view: View) { | 58 | override fun onClick(view: View) { |
| 55 | val holder = view.tag as GameViewHolder | 59 | val holder = view.tag as GameViewHolder |
| 60 | |||
| 61 | val gameExists = DocumentFile.fromSingleUri(YuzuApplication.appContext, Uri.parse(holder.game.path))?.exists() == true | ||
| 62 | if (!gameExists) { | ||
| 63 | Toast.makeText( | ||
| 64 | YuzuApplication.appContext, | ||
| 65 | R.string.loader_error_file_not_found, | ||
| 66 | Toast.LENGTH_LONG | ||
| 67 | ).show() | ||
| 68 | |||
| 69 | ViewModelProvider(activity)[GamesViewModel::class.java].reloadGames(true) | ||
| 70 | return | ||
| 71 | } | ||
| 72 | |||
| 56 | val preferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) | 73 | val preferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) |
| 57 | preferences.edit() | 74 | preferences.edit() |
| 58 | .putLong( | 75 | .putLong( |
diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index e171cf799..03a5ffc7e 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml | |||
| @@ -177,6 +177,7 @@ | |||
| 177 | <string name="loader_error_video_core">An error occurred initializing the video core</string> | 177 | <string name="loader_error_video_core">An error occurred initializing the video core</string> |
| 178 | <string name="loader_error_video_core_description">This is usually caused by an incompatible GPU driver. Installing a custom GPU driver may resolve this problem.</string> | 178 | <string name="loader_error_video_core_description">This is usually caused by an incompatible GPU driver. Installing a custom GPU driver may resolve this problem.</string> |
| 179 | <string name="loader_error_invalid_format">Unable to load ROM</string> | 179 | <string name="loader_error_invalid_format">Unable to load ROM</string> |
| 180 | <string name="loader_error_file_not_found">ROM file does not exist</string> | ||
| 180 | 181 | ||
| 181 | <!-- Emulation Menu --> | 182 | <!-- Emulation Menu --> |
| 182 | <string name="emulation_exit">Exit Emulation</string> | 183 | <string name="emulation_exit">Exit Emulation</string> |