From c5c080b235bec64afe1379290ae538a532aaae95 Mon Sep 17 00:00:00 2001 From: Ryan Meredith Date: Thu, 23 Apr 2020 19:31:41 -0400 Subject: [PATCH] Android: Run installWAD on separate thread --- .../dolphinemu/dolphinemu/NativeLibrary.java | 2 +- .../fragments/EmulationFragment.java | 6 ++-- .../dolphinemu/ui/main/MainPresenter.java | 33 +++++++++++++++---- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index 89ded1289d..f37169ddee 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -511,7 +511,7 @@ public final class NativeLibrary } // Show the AlertDialog on the main thread. - emulationActivity.runOnUiThread(() -> builder.show()); + emulationActivity.runOnUiThread(builder::show); // Wait for the lock to notify that it is complete. synchronized (lock) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java index 881fd3c554..ebb4dd48ef 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java @@ -262,7 +262,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C } private final String[] mGamePaths; - private Thread mEmulationThread; private State state; private Surface mSurface; private boolean mRunWhenSurfaceIsValid; @@ -399,7 +398,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C mRunWhenSurfaceIsValid = false; if (state == State.STOPPED) { - mEmulationThread = new Thread(() -> + Thread emulationThread = new Thread(() -> { NativeLibrary.SurfaceChanged(mSurface); if (loadPreviousTemporaryState) @@ -413,8 +412,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C NativeLibrary.Run(mGamePaths); } }, "NativeEmulation"); - mEmulationThread.start(); - + emulationThread.start(); } else if (state == State.PAUSED) { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java index f7cb972624..b107f415d6 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java @@ -1,11 +1,13 @@ package org.dolphinemu.dolphinemu.ui.main; +import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.widget.Toast; +import androidx.appcompat.app.AlertDialog; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import org.dolphinemu.dolphinemu.BuildConfig; @@ -121,13 +123,30 @@ public final class MainPresenter public void installWAD(String file) { - if (NativeLibrary.InstallWAD(file)) + final Activity mainPresenterActivity = (Activity) mContext; + + AlertDialog dialog = new AlertDialog.Builder(mContext, R.style.DolphinDialogBase).create(); + dialog.setTitle("Installing WAD"); + dialog.setMessage("Installing..."); + dialog.setCancelable(false); + dialog.show(); + + Thread installWADThread = new Thread(() -> { - Toast.makeText(mContext, R.string.wad_install_success, Toast.LENGTH_SHORT).show(); - } - else - { - Toast.makeText(mContext, R.string.wad_install_failure, Toast.LENGTH_SHORT).show(); - } + if (NativeLibrary.InstallWAD(file)) + { + mainPresenterActivity.runOnUiThread( + () -> Toast.makeText(mContext, R.string.wad_install_success, Toast.LENGTH_SHORT) + .show()); + } + else + { + mainPresenterActivity.runOnUiThread( + () -> Toast.makeText(mContext, R.string.wad_install_failure, Toast.LENGTH_SHORT) + .show()); + } + mainPresenterActivity.runOnUiThread(dialog::dismiss); + }, "InstallWAD"); + installWADThread.start(); } }