summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java
diff options
context:
space:
mode:
authorMai <mai.iam2048@gmail.com>2023-12-07 16:48:02 -0500
committerGitHub <noreply@github.com>2023-12-07 16:48:02 -0500
commite0f41115612d0d4279c9037f3f79b68e50809052 (patch)
tree90d460da7510b251488321efb81f603fc1c7c0ec /Source/Android/app/src/main/java
parent3a4cf579ff03d872cb64183923e18e17e9a37de6 (diff)
parent4203632c93f4b73c8fd1159272f08ca022063b2b (diff)
Merge pull request #11663 from JosJuice/android-config-change-callback
Android: Use config changed callback for tracking recursive scan setting
Diffstat (limited to 'Source/Android/app/src/main/java')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/ConfigChangedCallback.kt33
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.kt9
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheManager.java28
3 files changed, 59 insertions, 11 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/ConfigChangedCallback.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/ConfigChangedCallback.kt
new file mode 100644
index 0000000000..4415efa9e8
--- /dev/null
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/ConfigChangedCallback.kt
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package org.dolphinemu.dolphinemu.features.settings.model
+
+import androidx.annotation.Keep
+
+/**
+ * Calls the passed-in Runnable when Dolphin's config changes.
+ *
+ * Please note: The Runnable may be called from any thread.
+ */
+class ConfigChangedCallback(runnable: Runnable) {
+ @Keep
+ private var pointer: Long = initialize(runnable)
+
+ /**
+ * Stops the callback from being called in the future.
+ */
+ fun unregister() {
+ if (pointer != 0L) {
+ deinitialize(pointer)
+ pointer = 0L
+ }
+ }
+
+ companion object {
+ @JvmStatic
+ private external fun initialize(runnable: Runnable): Long
+
+ @JvmStatic
+ private external fun deinitialize(pointer: Long)
+ }
+}
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.kt
index 27291718dc..c5c1851e5d 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.kt
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.kt
@@ -8,7 +8,6 @@ import android.widget.Toast
import org.dolphinemu.dolphinemu.NativeLibrary
import org.dolphinemu.dolphinemu.R
import org.dolphinemu.dolphinemu.features.input.model.MappingCommon
-import org.dolphinemu.dolphinemu.services.GameFileCacheManager
import java.io.Closeable
class Settings : Closeable {
@@ -19,7 +18,6 @@ class Settings : Closeable {
private set
private var settingsLoaded = false
- private var loadedRecursiveIsoPathsValue = false
private val isGameSpecific: Boolean
get() = !TextUtils.isEmpty(gameId)
@@ -41,8 +39,6 @@ class Settings : Closeable {
check(!NativeLibrary.IsRunning()) { "Attempted to load game INI while emulating" }
NativeConfig.loadGameInis(gameId, revision)
}
-
- loadedRecursiveIsoPathsValue = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.boolean
}
fun loadSettings(gameId: String, revision: Int, isWii: Boolean) {
@@ -65,11 +61,6 @@ class Settings : Closeable {
NativeLibrary.ReloadLoggerConfig()
NativeLibrary.UpdateGCAdapterScanThread()
-
- if (loadedRecursiveIsoPathsValue != BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.boolean) {
- // Refresh game library
- GameFileCacheManager.startRescan()
- }
} else {
// custom game settings
if (context != null) {
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheManager.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheManager.java
index a979ee599f..02b8b15b9f 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheManager.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheManager.java
@@ -2,9 +2,14 @@
package org.dolphinemu.dolphinemu.services;
+import android.os.Handler;
+import android.os.Looper;
+
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
+import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
+import org.dolphinemu.dolphinemu.features.settings.model.ConfigChangedCallback;
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.model.GameFileCache;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
@@ -26,6 +31,7 @@ public final class GameFileCacheManager
new MutableLiveData<>(new GameFile[]{});
private static boolean sFirstLoadDone = false;
private static boolean sRunRescanAfterLoad = false;
+ private static boolean sRecursiveScanEnabled;
private static final ExecutorService sExecutor = Executors.newFixedThreadPool(1);
private static final MutableLiveData<Boolean> sLoadInProgress = new MutableLiveData<>(false);
@@ -154,8 +160,8 @@ public final class GameFileCacheManager
public static GameFile addOrGet(String gamePath)
{
- // Common case: The game is in the cache, so just grab it from there.
- // (Actually, addOrGet already checks for this case, but we want to avoid calling it if possible
+ // Common case: The game is in the cache, so just grab it from there. (GameFileCache.addOrGet
+ // actually already checks for this case, but we want to avoid calling it if possible
// because the executor thread may hold a lock on sGameFileCache for extended periods of time.)
GameFile[] allGames = sGameFiles.getValue();
for (GameFile game : allGames)
@@ -182,6 +188,7 @@ public final class GameFileCacheManager
if (!sFirstLoadDone)
{
sFirstLoadDone = true;
+ setUpAutomaticRescan();
sGameFileCache.load();
if (sGameFileCache.getSize() != 0)
{
@@ -191,6 +198,8 @@ public final class GameFileCacheManager
if (sRunRescanAfterLoad)
{
+ // Without this, there will be a short blip where the loading indicator in the GUI disappears
+ // because neither sLoadInProgress nor sRescanInProgress is true
sRescanInProgress.postValue(true);
}
@@ -258,4 +267,19 @@ public final class GameFileCacheManager
sGameFileCache = new GameFileCache();
}
}
+
+ private static void setUpAutomaticRescan()
+ {
+ sRecursiveScanEnabled = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.getBoolean();
+ new ConfigChangedCallback(() ->
+ new Handler(Looper.getMainLooper()).post(() ->
+ {
+ boolean recursiveScanEnabled = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.getBoolean();
+ if (sRecursiveScanEnabled != recursiveScanEnabled)
+ {
+ sRecursiveScanEnabled = recursiveScanEnabled;
+ startRescan();
+ }
+ }));
+ }
}