Android: Run installWAD on separate thread

This commit is contained in:
Ryan Meredith
2020-04-23 19:31:41 -04:00
parent 2d6d0c86cc
commit c5c080b235
3 changed files with 29 additions and 12 deletions

View File

@ -511,7 +511,7 @@ public final class NativeLibrary
} }
// Show the AlertDialog on the main thread. // 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. // Wait for the lock to notify that it is complete.
synchronized (lock) synchronized (lock)

View File

@ -262,7 +262,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
} }
private final String[] mGamePaths; private final String[] mGamePaths;
private Thread mEmulationThread;
private State state; private State state;
private Surface mSurface; private Surface mSurface;
private boolean mRunWhenSurfaceIsValid; private boolean mRunWhenSurfaceIsValid;
@ -399,7 +398,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
mRunWhenSurfaceIsValid = false; mRunWhenSurfaceIsValid = false;
if (state == State.STOPPED) if (state == State.STOPPED)
{ {
mEmulationThread = new Thread(() -> Thread emulationThread = new Thread(() ->
{ {
NativeLibrary.SurfaceChanged(mSurface); NativeLibrary.SurfaceChanged(mSurface);
if (loadPreviousTemporaryState) if (loadPreviousTemporaryState)
@ -413,8 +412,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
NativeLibrary.Run(mGamePaths); NativeLibrary.Run(mGamePaths);
} }
}, "NativeEmulation"); }, "NativeEmulation");
mEmulationThread.start(); emulationThread.start();
} }
else if (state == State.PAUSED) else if (state == State.PAUSED)
{ {

View File

@ -1,11 +1,13 @@
package org.dolphinemu.dolphinemu.ui.main; package org.dolphinemu.dolphinemu.ui.main;
import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import org.dolphinemu.dolphinemu.BuildConfig; import org.dolphinemu.dolphinemu.BuildConfig;
@ -121,13 +123,30 @@ public final class MainPresenter
public void installWAD(String file) 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(); if (NativeLibrary.InstallWAD(file))
} {
else mainPresenterActivity.runOnUiThread(
{ () -> Toast.makeText(mContext, R.string.wad_install_success, Toast.LENGTH_SHORT)
Toast.makeText(mContext, R.string.wad_install_failure, Toast.LENGTH_SHORT).show(); .show());
} }
else
{
mainPresenterActivity.runOnUiThread(
() -> Toast.makeText(mContext, R.string.wad_install_failure, Toast.LENGTH_SHORT)
.show());
}
mainPresenterActivity.runOnUiThread(dialog::dismiss);
}, "InstallWAD");
installWADThread.start();
} }
} }