mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-01-15 16:33:15 -03:00
Android: Remove CompletableFuture
We only use this class in one in one single function since its introduction with 12aa1071cb in 2021. If we do need it elsewhere we can always bring it back.
This commit is contained in:
@@ -26,7 +26,6 @@ import org.dolphinemu.dolphinemu.model.GameFileCache
|
||||
import org.dolphinemu.dolphinemu.services.GameFileCacheManager
|
||||
import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner
|
||||
import org.dolphinemu.dolphinemu.utils.BooleanSupplier
|
||||
import org.dolphinemu.dolphinemu.utils.CompletableFuture
|
||||
import org.dolphinemu.dolphinemu.utils.ContentHandler
|
||||
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization
|
||||
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper
|
||||
@@ -34,7 +33,8 @@ import org.dolphinemu.dolphinemu.utils.PermissionsHandler
|
||||
import org.dolphinemu.dolphinemu.utils.ThreadUtil
|
||||
import org.dolphinemu.dolphinemu.utils.WiiUtils
|
||||
import java.util.Arrays
|
||||
import java.util.concurrent.ExecutionException
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
class MainPresenter(private val mainView: MainView, private val activity: FragmentActivity) {
|
||||
private var dirToAdd: String? = null
|
||||
@@ -265,33 +265,34 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
|
||||
}
|
||||
|
||||
fun importWiiSave(path: String?) {
|
||||
val canOverwriteFuture = CompletableFuture<Boolean>()
|
||||
ThreadUtil.runOnThreadAndShowResult(
|
||||
activity,
|
||||
R.string.import_in_progress,
|
||||
0,
|
||||
{
|
||||
val canOverwrite = BooleanSupplier {
|
||||
val latch = CountDownLatch(1)
|
||||
val decision = AtomicReference<Boolean>()
|
||||
activity.runOnUiThread {
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setMessage(R.string.wii_save_exists)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.yes) { _: DialogInterface?, _: Int ->
|
||||
canOverwriteFuture.complete(true)
|
||||
decision.set(true)
|
||||
latch.countDown()
|
||||
}
|
||||
.setNegativeButton(R.string.no) { _: DialogInterface?, _: Int ->
|
||||
canOverwriteFuture.complete(false)
|
||||
decision.set(false)
|
||||
latch.countDown()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
try {
|
||||
return@BooleanSupplier canOverwriteFuture.get()
|
||||
} catch (e: ExecutionException) {
|
||||
// Shouldn't happen
|
||||
throw RuntimeException(e)
|
||||
latch.await()
|
||||
} catch (e: InterruptedException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
decision.get() ?: false
|
||||
}
|
||||
|
||||
val message: Int = when (WiiUtils.importWiiSave(path!!, canOverwrite)) {
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.utils;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* Simplified re-implementation of a subset of {@link java.util.concurrent.CompletableFuture}.
|
||||
* Replace this class with that class once we have full Java 8 support (once we require API 24).
|
||||
*/
|
||||
public class CompletableFuture<T> implements Future<T>
|
||||
{
|
||||
private final Lock lock = new ReentrantLock();
|
||||
private final Condition done = lock.newCondition();
|
||||
|
||||
private boolean isDone = false;
|
||||
private T result = null;
|
||||
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone()
|
||||
{
|
||||
return isDone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() throws ExecutionException, InterruptedException
|
||||
{
|
||||
lock.lock();
|
||||
try
|
||||
{
|
||||
while (!isDone)
|
||||
done.await();
|
||||
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(long timeout, TimeUnit unit)
|
||||
throws ExecutionException, InterruptedException, TimeoutException
|
||||
{
|
||||
lock.lock();
|
||||
try
|
||||
{
|
||||
while (!isDone)
|
||||
{
|
||||
if (!done.await(timeout, unit))
|
||||
throw new TimeoutException();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean complete(T value)
|
||||
{
|
||||
lock.lock();
|
||||
try
|
||||
{
|
||||
boolean wasDone = isDone;
|
||||
result = value;
|
||||
isDone = true;
|
||||
done.signalAll();
|
||||
return !wasDone;
|
||||
}
|
||||
finally
|
||||
{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user