diff options
| author | 2023-04-04 04:03:55 -0400 | |
|---|---|---|
| committer | 2023-06-03 00:05:49 -0700 | |
| commit | a8274863917c8941d296361f46779a98377e7337 (patch) | |
| tree | f5b9f644f47b96b1e11f5642afa6119d07b41a53 /src/android | |
| parent | android: Remove game database (diff) | |
| download | yuzu-a8274863917c8941d296361f46779a98377e7337.tar.gz yuzu-a8274863917c8941d296361f46779a98377e7337.tar.xz yuzu-a8274863917c8941d296361f46779a98377e7337.zip | |
android: Remove LocalBroadcastManager
This causes a couple of minor changes to directory initialization. We don't have a lengthy initialization step so we could spend less time creating state receivers and just run initialization on the main thread. We also don't have a situation where external storage will be a concern so checks are removed in favor of a binary check to see if initialization is ready.
This additionally removes the unused DoFrame callback.
Diffstat (limited to 'src/android')
11 files changed, 17 insertions, 225 deletions
diff --git a/src/android/app/build.gradle b/src/android/app/build.gradle index a82d2706b..221232712 100644 --- a/src/android/app/build.gradle +++ b/src/android/app/build.gradle | |||
| @@ -142,7 +142,6 @@ dependencies { | |||
| 142 | implementation 'androidx.window:window:1.0.0' | 142 | implementation 'androidx.window:window:1.0.0' |
| 143 | implementation 'org.ini4j:ini4j:0.5.4' | 143 | implementation 'org.ini4j:ini4j:0.5.4' |
| 144 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | 144 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' |
| 145 | implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0' | ||
| 146 | implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' | 145 | implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' |
| 147 | } | 146 | } |
| 148 | 147 | ||
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.java index 5def17f2b..50ec34e22 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.java | |||
| @@ -218,8 +218,6 @@ public final class NativeLibrary { | |||
| 218 | 218 | ||
| 219 | public static native void SurfaceDestroyed(); | 219 | public static native void SurfaceDestroyed(); |
| 220 | 220 | ||
| 221 | public static native void DoFrame(); | ||
| 222 | |||
| 223 | /** | 221 | /** |
| 224 | * Unpauses emulation from a paused state. | 222 | * Unpauses emulation from a paused state. |
| 225 | */ | 223 | */ |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt index 60858ecd6..a655500f8 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt | |||
| @@ -5,31 +5,25 @@ package org.yuzu.yuzu_emu.features.settings.ui | |||
| 5 | 5 | ||
| 6 | import android.content.Context | 6 | import android.content.Context |
| 7 | import android.content.Intent | 7 | import android.content.Intent |
| 8 | import android.content.IntentFilter | ||
| 9 | import android.os.Bundle | 8 | import android.os.Bundle |
| 10 | import android.view.Menu | 9 | import android.view.Menu |
| 11 | import android.view.View | 10 | import android.view.View |
| 12 | import android.widget.Toast | 11 | import android.widget.Toast |
| 13 | import androidx.activity.viewModels | 12 | import androidx.activity.viewModels |
| 14 | import androidx.appcompat.app.AlertDialog | ||
| 15 | import androidx.appcompat.app.AppCompatActivity | 13 | import androidx.appcompat.app.AppCompatActivity |
| 16 | import androidx.core.view.ViewCompat | 14 | import androidx.core.view.ViewCompat |
| 17 | import androidx.core.view.WindowCompat | 15 | import androidx.core.view.WindowCompat |
| 18 | import androidx.core.view.WindowInsetsCompat | 16 | import androidx.core.view.WindowInsetsCompat |
| 19 | import androidx.core.view.updatePadding | 17 | import androidx.core.view.updatePadding |
| 20 | import androidx.localbroadcastmanager.content.LocalBroadcastManager | ||
| 21 | import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
| 22 | import org.yuzu.yuzu_emu.NativeLibrary | 18 | import org.yuzu.yuzu_emu.NativeLibrary |
| 23 | import org.yuzu.yuzu_emu.R | 19 | import org.yuzu.yuzu_emu.R |
| 24 | import org.yuzu.yuzu_emu.databinding.ActivitySettingsBinding | 20 | import org.yuzu.yuzu_emu.databinding.ActivitySettingsBinding |
| 25 | import org.yuzu.yuzu_emu.databinding.DialogProgressBarBinding | ||
| 26 | import org.yuzu.yuzu_emu.features.settings.model.Settings | 21 | import org.yuzu.yuzu_emu.features.settings.model.Settings |
| 27 | import org.yuzu.yuzu_emu.features.settings.model.SettingsViewModel | 22 | import org.yuzu.yuzu_emu.features.settings.model.SettingsViewModel |
| 28 | import org.yuzu.yuzu_emu.utils.* | 23 | import org.yuzu.yuzu_emu.utils.* |
| 29 | 24 | ||
| 30 | class SettingsActivity : AppCompatActivity(), SettingsActivityView { | 25 | class SettingsActivity : AppCompatActivity(), SettingsActivityView { |
| 31 | private val presenter = SettingsActivityPresenter(this) | 26 | private val presenter = SettingsActivityPresenter(this) |
| 32 | private var dialog: AlertDialog? = null | ||
| 33 | 27 | ||
| 34 | private lateinit var binding: ActivitySettingsBinding | 28 | private lateinit var binding: ActivitySettingsBinding |
| 35 | 29 | ||
| @@ -134,47 +128,6 @@ class SettingsActivity : AppCompatActivity(), SettingsActivityView { | |||
| 134 | return duration != 0f && transition != 0f | 128 | return duration != 0f && transition != 0f |
| 135 | } | 129 | } |
| 136 | 130 | ||
| 137 | override fun startDirectoryInitializationService( | ||
| 138 | receiver: DirectoryStateReceiver?, | ||
| 139 | filter: IntentFilter | ||
| 140 | ) { | ||
| 141 | LocalBroadcastManager.getInstance(this).registerReceiver( | ||
| 142 | receiver!!, | ||
| 143 | filter | ||
| 144 | ) | ||
| 145 | DirectoryInitialization.start(this) | ||
| 146 | } | ||
| 147 | |||
| 148 | override fun stopListeningToDirectoryInitializationService(receiver: DirectoryStateReceiver) { | ||
| 149 | LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver) | ||
| 150 | } | ||
| 151 | |||
| 152 | override fun showLoading() { | ||
| 153 | if (dialog == null) { | ||
| 154 | val loadingBinding = DialogProgressBarBinding.inflate(layoutInflater) | ||
| 155 | loadingBinding.progressBar.isIndeterminate = true | ||
| 156 | |||
| 157 | dialog = MaterialAlertDialogBuilder(this) | ||
| 158 | .setTitle(R.string.load_settings) | ||
| 159 | .setView(loadingBinding.root) | ||
| 160 | .setCancelable(false) | ||
| 161 | .create() | ||
| 162 | } | ||
| 163 | dialog!!.show() | ||
| 164 | } | ||
| 165 | |||
| 166 | override fun hideLoading() { | ||
| 167 | dialog!!.dismiss() | ||
| 168 | } | ||
| 169 | |||
| 170 | override fun showExternalStorageNotMountedHint() { | ||
| 171 | Toast.makeText( | ||
| 172 | this, | ||
| 173 | R.string.external_storage_not_mounted, | ||
| 174 | Toast.LENGTH_SHORT | ||
| 175 | ).show() | ||
| 176 | } | ||
| 177 | |||
| 178 | override fun onSettingsFileLoaded() { | 131 | override fun onSettingsFileLoaded() { |
| 179 | val fragment: SettingsFragmentView? = settingsFragment | 132 | val fragment: SettingsFragmentView? = settingsFragment |
| 180 | fragment?.loadSettingsList() | 133 | fragment?.loadSettingsList() |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.kt index 2a86e4463..8c90156e3 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.kt | |||
| @@ -3,15 +3,13 @@ | |||
| 3 | 3 | ||
| 4 | package org.yuzu.yuzu_emu.features.settings.ui | 4 | package org.yuzu.yuzu_emu.features.settings.ui |
| 5 | 5 | ||
| 6 | import android.content.IntentFilter | 6 | import android.content.Context |
| 7 | import android.os.Bundle | 7 | import android.os.Bundle |
| 8 | import android.text.TextUtils | 8 | import android.text.TextUtils |
| 9 | import org.yuzu.yuzu_emu.NativeLibrary | 9 | import org.yuzu.yuzu_emu.NativeLibrary |
| 10 | import org.yuzu.yuzu_emu.features.settings.model.Settings | 10 | import org.yuzu.yuzu_emu.features.settings.model.Settings |
| 11 | import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile | 11 | import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile |
| 12 | import org.yuzu.yuzu_emu.utils.DirectoryInitialization | 12 | import org.yuzu.yuzu_emu.utils.DirectoryInitialization |
| 13 | import org.yuzu.yuzu_emu.utils.DirectoryInitialization.DirectoryInitializationState | ||
| 14 | import org.yuzu.yuzu_emu.utils.DirectoryStateReceiver | ||
| 15 | import org.yuzu.yuzu_emu.utils.Log | 13 | import org.yuzu.yuzu_emu.utils.Log |
| 16 | import java.io.File | 14 | import java.io.File |
| 17 | 15 | ||
| @@ -19,7 +17,6 @@ class SettingsActivityPresenter(private val activityView: SettingsActivityView) | |||
| 19 | val settings: Settings get() = activityView.settings | 17 | val settings: Settings get() = activityView.settings |
| 20 | 18 | ||
| 21 | private var shouldSave = false | 19 | private var shouldSave = false |
| 22 | private var directoryStateReceiver: DirectoryStateReceiver? = null | ||
| 23 | private lateinit var menuTag: String | 20 | private lateinit var menuTag: String |
| 24 | private lateinit var gameId: String | 21 | private lateinit var gameId: String |
| 25 | 22 | ||
| @@ -54,33 +51,14 @@ class SettingsActivityPresenter(private val activityView: SettingsActivityView) | |||
| 54 | Log.error(DirectoryInitialization.userDirectory + "/config/" + SettingsFile.FILE_NAME_CONFIG + ".ini") | 51 | Log.error(DirectoryInitialization.userDirectory + "/config/" + SettingsFile.FILE_NAME_CONFIG + ".ini") |
| 55 | Log.error("yuzu config file could not be found!") | 52 | Log.error("yuzu config file could not be found!") |
| 56 | } | 53 | } |
| 57 | if (DirectoryInitialization.areDirectoriesReady()) { | 54 | |
| 58 | loadSettingsUI() | 55 | if (!DirectoryInitialization.areDirectoriesReady) { |
| 59 | } else { | 56 | DirectoryInitialization.start(activityView as Context) |
| 60 | activityView.showLoading() | ||
| 61 | val statusIntentFilter = IntentFilter(DirectoryInitialization.BROADCAST_ACTION) | ||
| 62 | directoryStateReceiver = | ||
| 63 | DirectoryStateReceiver { directoryInitializationState: DirectoryInitializationState -> | ||
| 64 | if (directoryInitializationState == DirectoryInitializationState.YUZU_DIRECTORIES_INITIALIZED) { | ||
| 65 | activityView.hideLoading() | ||
| 66 | loadSettingsUI() | ||
| 67 | } else if (directoryInitializationState == DirectoryInitializationState.CANT_FIND_EXTERNAL_STORAGE) { | ||
| 68 | activityView.showExternalStorageNotMountedHint() | ||
| 69 | activityView.hideLoading() | ||
| 70 | } | ||
| 71 | } | ||
| 72 | activityView.startDirectoryInitializationService( | ||
| 73 | directoryStateReceiver, | ||
| 74 | statusIntentFilter | ||
| 75 | ) | ||
| 76 | } | 57 | } |
| 58 | loadSettingsUI() | ||
| 77 | } | 59 | } |
| 78 | 60 | ||
| 79 | fun onStop(finishing: Boolean) { | 61 | fun onStop(finishing: Boolean) { |
| 80 | if (directoryStateReceiver != null) { | ||
| 81 | activityView.stopListeningToDirectoryInitializationService(directoryStateReceiver!!) | ||
| 82 | directoryStateReceiver = null | ||
| 83 | } | ||
| 84 | if (finishing && shouldSave) { | 62 | if (finishing && shouldSave) { |
| 85 | Log.debug("[SettingsActivity] Settings activity stopping. Saving settings to INI...") | 63 | Log.debug("[SettingsActivity] Settings activity stopping. Saving settings to INI...") |
| 86 | settings.saveSettings(activityView) | 64 | settings.saveSettings(activityView) |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityView.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityView.kt index 2b6dd2fce..c186fc388 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityView.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityView.kt | |||
| @@ -3,9 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | package org.yuzu.yuzu_emu.features.settings.ui | 4 | package org.yuzu.yuzu_emu.features.settings.ui |
| 5 | 5 | ||
| 6 | import android.content.IntentFilter | ||
| 7 | import org.yuzu.yuzu_emu.features.settings.model.Settings | 6 | import org.yuzu.yuzu_emu.features.settings.model.Settings |
| 8 | import org.yuzu.yuzu_emu.utils.DirectoryStateReceiver | ||
| 9 | 7 | ||
| 10 | /** | 8 | /** |
| 11 | * Abstraction for the Activity that manages SettingsFragments. | 9 | * Abstraction for the Activity that manages SettingsFragments. |
| @@ -56,37 +54,4 @@ interface SettingsActivityView { | |||
| 56 | * unless this has been called, the Activity will not save to disk. | 54 | * unless this has been called, the Activity will not save to disk. |
| 57 | */ | 55 | */ |
| 58 | fun onSettingChanged() | 56 | fun onSettingChanged() |
| 59 | |||
| 60 | /** | ||
| 61 | * Show loading dialog while loading the settings | ||
| 62 | */ | ||
| 63 | fun showLoading() | ||
| 64 | |||
| 65 | /** | ||
| 66 | * Hide the loading the dialog | ||
| 67 | */ | ||
| 68 | fun hideLoading() | ||
| 69 | |||
| 70 | /** | ||
| 71 | * Show a hint to the user that the app needs the external storage to be mounted | ||
| 72 | */ | ||
| 73 | fun showExternalStorageNotMountedHint() | ||
| 74 | |||
| 75 | /** | ||
| 76 | * Start the DirectoryInitialization and listen for the result. | ||
| 77 | * | ||
| 78 | * @param receiver the broadcast receiver for the DirectoryInitialization | ||
| 79 | * @param filter the Intent broadcasts to be received. | ||
| 80 | */ | ||
| 81 | fun startDirectoryInitializationService( | ||
| 82 | receiver: DirectoryStateReceiver?, | ||
| 83 | filter: IntentFilter | ||
| 84 | ) | ||
| 85 | |||
| 86 | /** | ||
| 87 | * Stop listening to the DirectoryInitialization. | ||
| 88 | * | ||
| 89 | * @param receiver The broadcast receiver to unregister. | ||
| 90 | */ | ||
| 91 | fun stopListeningToDirectoryInitializationService(receiver: DirectoryStateReceiver) | ||
| 92 | } | 57 | } |
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 703d4623b..daee937ca 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 | |||
| @@ -4,14 +4,13 @@ | |||
| 4 | package org.yuzu.yuzu_emu.fragments | 4 | package org.yuzu.yuzu_emu.fragments |
| 5 | 5 | ||
| 6 | import android.content.Context | 6 | import android.content.Context |
| 7 | import android.content.IntentFilter | ||
| 8 | import android.content.SharedPreferences | 7 | import android.content.SharedPreferences |
| 9 | import android.graphics.Color | 8 | import android.graphics.Color |
| 10 | import android.os.Bundle | 9 | import android.os.Bundle |
| 11 | import android.os.Handler | 10 | import android.os.Handler |
| 11 | import android.os.Looper | ||
| 12 | import android.view.* | 12 | import android.view.* |
| 13 | import android.widget.TextView | 13 | import android.widget.TextView |
| 14 | import android.widget.Toast | ||
| 15 | import androidx.activity.OnBackPressedCallback | 14 | import androidx.activity.OnBackPressedCallback |
| 16 | import androidx.appcompat.widget.PopupMenu | 15 | import androidx.appcompat.widget.PopupMenu |
| 17 | import androidx.core.content.res.ResourcesCompat | 16 | import androidx.core.content.res.ResourcesCompat |
| @@ -19,7 +18,6 @@ import androidx.core.graphics.Insets | |||
| 19 | import androidx.core.view.ViewCompat | 18 | import androidx.core.view.ViewCompat |
| 20 | import androidx.core.view.WindowInsetsCompat | 19 | import androidx.core.view.WindowInsetsCompat |
| 21 | import androidx.fragment.app.Fragment | 20 | import androidx.fragment.app.Fragment |
| 22 | import androidx.localbroadcastmanager.content.LocalBroadcastManager | ||
| 23 | import androidx.preference.PreferenceManager | 21 | import androidx.preference.PreferenceManager |
| 24 | import com.google.android.material.dialog.MaterialAlertDialogBuilder | 22 | import com.google.android.material.dialog.MaterialAlertDialogBuilder |
| 25 | import org.yuzu.yuzu_emu.NativeLibrary | 23 | import org.yuzu.yuzu_emu.NativeLibrary |
| @@ -32,13 +30,11 @@ import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity | |||
| 32 | import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile | 30 | import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile |
| 33 | import org.yuzu.yuzu_emu.model.Game | 31 | import org.yuzu.yuzu_emu.model.Game |
| 34 | import org.yuzu.yuzu_emu.utils.* | 32 | import org.yuzu.yuzu_emu.utils.* |
| 35 | import org.yuzu.yuzu_emu.utils.DirectoryInitialization.DirectoryInitializationState | ||
| 36 | import org.yuzu.yuzu_emu.utils.SerializableHelper.parcelable | 33 | import org.yuzu.yuzu_emu.utils.SerializableHelper.parcelable |
| 37 | 34 | ||
| 38 | class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.FrameCallback { | 35 | class EmulationFragment : Fragment(), SurfaceHolder.Callback { |
| 39 | private lateinit var preferences: SharedPreferences | 36 | private lateinit var preferences: SharedPreferences |
| 40 | private lateinit var emulationState: EmulationState | 37 | private lateinit var emulationState: EmulationState |
| 41 | private var directoryStateReceiver: DirectoryStateReceiver? = null | ||
| 42 | private var emulationActivity: EmulationActivity? = null | 38 | private var emulationActivity: EmulationActivity? = null |
| 43 | private var perfStatsUpdater: (() -> Unit)? = null | 39 | private var perfStatsUpdater: (() -> Unit)? = null |
| 44 | 40 | ||
| @@ -144,25 +140,16 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram | |||
| 144 | 140 | ||
| 145 | override fun onResume() { | 141 | override fun onResume() { |
| 146 | super.onResume() | 142 | super.onResume() |
| 147 | Choreographer.getInstance().postFrameCallback(this) | 143 | if (!DirectoryInitialization.areDirectoriesReady) { |
| 148 | if (DirectoryInitialization.areDirectoriesReady()) { | 144 | DirectoryInitialization.start(requireContext()) |
| 149 | emulationState.run(emulationActivity!!.isActivityRecreated) | ||
| 150 | } else { | ||
| 151 | setupDirectoriesThenStartEmulation() | ||
| 152 | } | 145 | } |
| 146 | emulationState.run(emulationActivity!!.isActivityRecreated) | ||
| 153 | } | 147 | } |
| 154 | 148 | ||
| 155 | override fun onPause() { | 149 | override fun onPause() { |
| 156 | if (directoryStateReceiver != null) { | ||
| 157 | LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver( | ||
| 158 | directoryStateReceiver!! | ||
| 159 | ) | ||
| 160 | directoryStateReceiver = null | ||
| 161 | } | ||
| 162 | if (emulationState.isRunning) { | 150 | if (emulationState.isRunning) { |
| 163 | emulationState.pause() | 151 | emulationState.pause() |
| 164 | } | 152 | } |
| 165 | Choreographer.getInstance().removeFrameCallback(this) | ||
| 166 | super.onPause() | 153 | super.onPause() |
| 167 | } | 154 | } |
| 168 | 155 | ||
| @@ -176,36 +163,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram | |||
| 176 | super.onDetach() | 163 | super.onDetach() |
| 177 | } | 164 | } |
| 178 | 165 | ||
| 179 | private fun setupDirectoriesThenStartEmulation() { | ||
| 180 | val statusIntentFilter = IntentFilter( | ||
| 181 | DirectoryInitialization.BROADCAST_ACTION | ||
| 182 | ) | ||
| 183 | directoryStateReceiver = | ||
| 184 | DirectoryStateReceiver { directoryInitializationState: DirectoryInitializationState -> | ||
| 185 | if (directoryInitializationState == | ||
| 186 | DirectoryInitializationState.YUZU_DIRECTORIES_INITIALIZED | ||
| 187 | ) { | ||
| 188 | emulationState.run(emulationActivity!!.isActivityRecreated) | ||
| 189 | } else if (directoryInitializationState == | ||
| 190 | DirectoryInitializationState.CANT_FIND_EXTERNAL_STORAGE | ||
| 191 | ) { | ||
| 192 | Toast.makeText( | ||
| 193 | context, | ||
| 194 | R.string.external_storage_not_mounted, | ||
| 195 | Toast.LENGTH_SHORT | ||
| 196 | ) | ||
| 197 | .show() | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | // Registers the DirectoryStateReceiver and its intent filters | ||
| 202 | LocalBroadcastManager.getInstance(requireActivity()).registerReceiver( | ||
| 203 | directoryStateReceiver!!, | ||
| 204 | statusIntentFilter | ||
| 205 | ) | ||
| 206 | DirectoryInitialization.start(requireContext()) | ||
| 207 | } | ||
| 208 | |||
| 209 | fun refreshInputOverlay() { | 166 | fun refreshInputOverlay() { |
| 210 | binding.surfaceInputOverlay.refreshControls() | 167 | binding.surfaceInputOverlay.refreshControls() |
| 211 | } | 168 | } |
| @@ -259,11 +216,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram | |||
| 259 | emulationState.clearSurface() | 216 | emulationState.clearSurface() |
| 260 | } | 217 | } |
| 261 | 218 | ||
| 262 | override fun doFrame(frameTimeNanos: Long) { | ||
| 263 | Choreographer.getInstance().postFrameCallback(this) | ||
| 264 | NativeLibrary.DoFrame() | ||
| 265 | } | ||
| 266 | |||
| 267 | private fun showOverlayOptions() { | 219 | private fun showOverlayOptions() { |
| 268 | val anchor = binding.inGameMenu.findViewById<View>(R.id.menu_overlay_controls) | 220 | val anchor = binding.inGameMenu.findViewById<View>(R.id.menu_overlay_controls) |
| 269 | val popup = PopupMenu(requireContext(), anchor) | 221 | val popup = PopupMenu(requireContext(), anchor) |
| @@ -474,7 +426,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram | |||
| 474 | } | 426 | } |
| 475 | 427 | ||
| 476 | companion object { | 428 | companion object { |
| 477 | private val perfStatsUpdateHandler = Handler() | 429 | private val perfStatsUpdateHandler = Handler(Looper.myLooper()!!) |
| 478 | 430 | ||
| 479 | fun newInstance(game: Game): EmulationFragment { | 431 | fun newInstance(game: Game): EmulationFragment { |
| 480 | val args = Bundle() | 432 | val args = Bundle() |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt index 4885bc4bc..b6ad72591 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt | |||
| @@ -41,7 +41,7 @@ class MainActivity : AppCompatActivity(), MainView { | |||
| 41 | 41 | ||
| 42 | override fun onCreate(savedInstanceState: Bundle?) { | 42 | override fun onCreate(savedInstanceState: Bundle?) { |
| 43 | val splashScreen = installSplashScreen() | 43 | val splashScreen = installSplashScreen() |
| 44 | splashScreen.setKeepOnScreenCondition { !DirectoryInitialization.areDirectoriesReady() } | 44 | splashScreen.setKeepOnScreenCondition { !DirectoryInitialization.areDirectoriesReady } |
| 45 | 45 | ||
| 46 | ThemeHelper.setTheme(this) | 46 | ThemeHelper.setTheme(this) |
| 47 | 47 | ||
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/DirectoryInitialization.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/DirectoryInitialization.kt index a02d8fb01..7b66bf220 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/DirectoryInitialization.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/DirectoryInitialization.kt | |||
| @@ -4,46 +4,26 @@ | |||
| 4 | package org.yuzu.yuzu_emu.utils | 4 | package org.yuzu.yuzu_emu.utils |
| 5 | 5 | ||
| 6 | import android.content.Context | 6 | import android.content.Context |
| 7 | import android.content.Intent | ||
| 8 | import androidx.localbroadcastmanager.content.LocalBroadcastManager | ||
| 9 | import org.yuzu.yuzu_emu.NativeLibrary | 7 | import org.yuzu.yuzu_emu.NativeLibrary |
| 10 | import java.io.IOException | 8 | import java.io.IOException |
| 11 | import java.util.concurrent.atomic.AtomicBoolean | ||
| 12 | 9 | ||
| 13 | object DirectoryInitialization { | 10 | object DirectoryInitialization { |
| 14 | const val BROADCAST_ACTION = "org.yuzu.yuzu_emu.BROADCAST" | ||
| 15 | const val EXTRA_STATE = "directoryState" | ||
| 16 | |||
| 17 | @Volatile | ||
| 18 | private var directoryState: DirectoryInitializationState? = null | ||
| 19 | private var userPath: String? = null | 11 | private var userPath: String? = null |
| 20 | private val isDirectoryInitializationRunning = AtomicBoolean(false) | 12 | |
| 13 | var areDirectoriesReady: Boolean = false | ||
| 21 | 14 | ||
| 22 | @JvmStatic | 15 | @JvmStatic |
| 23 | fun start(context: Context) { | 16 | fun start(context: Context) { |
| 24 | // Can take a few seconds to run, so don't block UI thread. | 17 | if (!areDirectoriesReady) { |
| 25 | Runnable { init(context) }.run() | ||
| 26 | } | ||
| 27 | |||
| 28 | private fun init(context: Context) { | ||
| 29 | if (!isDirectoryInitializationRunning.compareAndSet(false, true)) return | ||
| 30 | if (directoryState != DirectoryInitializationState.YUZU_DIRECTORIES_INITIALIZED) { | ||
| 31 | initializeInternalStorage(context) | 18 | initializeInternalStorage(context) |
| 32 | NativeLibrary.InitializeEmulation() | 19 | NativeLibrary.InitializeEmulation() |
| 33 | directoryState = DirectoryInitializationState.YUZU_DIRECTORIES_INITIALIZED | 20 | areDirectoriesReady = true |
| 34 | } | 21 | } |
| 35 | isDirectoryInitializationRunning.set(false) | ||
| 36 | sendBroadcastState(directoryState, context) | ||
| 37 | } | ||
| 38 | |||
| 39 | fun areDirectoriesReady(): Boolean { | ||
| 40 | return directoryState == DirectoryInitializationState.YUZU_DIRECTORIES_INITIALIZED | ||
| 41 | } | 22 | } |
| 42 | 23 | ||
| 43 | val userDirectory: String? | 24 | val userDirectory: String? |
| 44 | get() { | 25 | get() { |
| 45 | checkNotNull(directoryState) { "DirectoryInitialization has to run at least once!" } | 26 | check(areDirectoriesReady) { "Directory initialization is not ready!" } |
| 46 | check(!isDirectoryInitializationRunning.get()) { "DirectoryInitialization has to finish running first!" } | ||
| 47 | return userPath | 27 | return userPath |
| 48 | } | 28 | } |
| 49 | 29 | ||
| @@ -55,15 +35,4 @@ object DirectoryInitialization { | |||
| 55 | e.printStackTrace() | 35 | e.printStackTrace() |
| 56 | } | 36 | } |
| 57 | } | 37 | } |
| 58 | |||
| 59 | private fun sendBroadcastState(state: DirectoryInitializationState?, context: Context) { | ||
| 60 | val localIntent = Intent(BROADCAST_ACTION) | ||
| 61 | .putExtra(EXTRA_STATE, state) | ||
| 62 | LocalBroadcastManager.getInstance(context).sendBroadcast(localIntent) | ||
| 63 | } | ||
| 64 | |||
| 65 | enum class DirectoryInitializationState { | ||
| 66 | YUZU_DIRECTORIES_INITIALIZED, | ||
| 67 | CANT_FIND_EXTERNAL_STORAGE | ||
| 68 | } | ||
| 69 | } | 38 | } |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/DirectoryStateReceiver.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/DirectoryStateReceiver.kt deleted file mode 100644 index 06e00cfc8..000000000 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/DirectoryStateReceiver.kt +++ /dev/null | |||
| @@ -1,18 +0,0 @@ | |||
| 1 | // SPDX-FileCopyrightText: 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | package org.yuzu.yuzu_emu.utils | ||
| 5 | |||
| 6 | import android.content.BroadcastReceiver | ||
| 7 | import android.content.Context | ||
| 8 | import android.content.Intent | ||
| 9 | import org.yuzu.yuzu_emu.utils.DirectoryInitialization.DirectoryInitializationState | ||
| 10 | |||
| 11 | class DirectoryStateReceiver(var callback: (DirectoryInitializationState) -> Unit) : | ||
| 12 | BroadcastReceiver() { | ||
| 13 | override fun onReceive(context: Context, intent: Intent) { | ||
| 14 | val state = intent | ||
| 15 | .getSerializableExtra(DirectoryInitialization.EXTRA_STATE) as DirectoryInitializationState | ||
| 16 | callback.invoke(state) | ||
| 17 | } | ||
| 18 | } | ||
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index 86994f734..ce713b80f 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp | |||
| @@ -367,8 +367,6 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_SurfaceDestroyed(JNIEnv* env, | |||
| 367 | EmulationSession::GetInstance().SurfaceChanged(); | 367 | EmulationSession::GetInstance().SurfaceChanged(); |
| 368 | } | 368 | } |
| 369 | 369 | ||
| 370 | void Java_org_yuzu_yuzu_1emu_NativeLibrary_DoFrame(JNIEnv* env, [[maybe_unused]] jclass clazz) {} | ||
| 371 | |||
| 372 | void Java_org_yuzu_yuzu_1emu_NativeLibrary_NotifyOrientationChange(JNIEnv* env, | 370 | void Java_org_yuzu_yuzu_1emu_NativeLibrary_NotifyOrientationChange(JNIEnv* env, |
| 373 | [[maybe_unused]] jclass clazz, | 371 | [[maybe_unused]] jclass clazz, |
| 374 | jint layout_option, | 372 | jint layout_option, |
diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 29c1b1691..98a06c45d 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml | |||
| @@ -98,8 +98,6 @@ | |||
| 98 | 98 | ||
| 99 | <string name="load_settings">Loading Settingsā¦</string> | 99 | <string name="load_settings">Loading Settingsā¦</string> |
| 100 | 100 | ||
| 101 | <string name="external_storage_not_mounted">The external storage needs to be available in order to use yuzu</string> | ||
| 102 | |||
| 103 | <string name="empty_gamelist">No files were found or no game directory has been selected yet.</string> | 101 | <string name="empty_gamelist">No files were found or no game directory has been selected yet.</string> |
| 104 | 102 | ||
| 105 | <!-- Software keyboard --> | 103 | <!-- Software keyboard --> |