diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/activities/EmulationActivity.kt b/src/android/app/src/main/java/io/github/lime3ds/android/activities/EmulationActivity.kt index 30ccc552d..4e88fa450 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/activities/EmulationActivity.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/activities/EmulationActivity.kt @@ -57,6 +57,8 @@ class EmulationActivity : AppCompatActivity() { private lateinit var screenAdjustmentUtil: ScreenAdjustmentUtil private lateinit var hotkeyUtility: HotkeyUtility + private var isEmulationRunning: Boolean = false + override fun onCreate(savedInstanceState: Bundle?) { ThemeUtil.setTheme(this) @@ -86,6 +88,9 @@ class EmulationActivity : AppCompatActivity() { ) EmulationLifecycleUtil.addShutdownHook(hook = { this.finish() }) + + isEmulationRunning = true + instance = this } // On some devices, the system bars will not disappear on first boot or after some @@ -106,8 +111,20 @@ class EmulationActivity : AppCompatActivity() { NativeLibrary.reloadCameraDevices() } + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + outState.putBoolean("isEmulationRunning", isEmulationRunning) + } + + override fun onRestoreInstanceState(savedInstanceState: Bundle) { + super.onRestoreInstanceState(savedInstanceState) + isEmulationRunning = savedInstanceState.getBoolean("isEmulationRunning", false) + } + override fun onDestroy() { EmulationLifecycleUtil.clear() + isEmulationRunning = false + instance = null super.onDestroy() } @@ -450,6 +467,12 @@ class EmulationActivity : AppCompatActivity() { } companion object { + private var instance: EmulationActivity? = null + + fun isRunning(): Boolean { + return instance?.isEmulationRunning ?: false + } + fun stopForegroundService(activity: Activity) { val startIntent = Intent(activity, ForegroundService::class.java) startIntent.action = ForegroundService.ACTION_STOP diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/model/view/SettingsItem.kt b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/model/view/SettingsItem.kt index 46a7ffbb0..86cb6368e 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/model/view/SettingsItem.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/model/view/SettingsItem.kt @@ -6,6 +6,7 @@ package io.github.lime3ds.android.features.settings.model.view import io.github.lime3ds.android.NativeLibrary import io.github.lime3ds.android.features.settings.model.AbstractSetting +import io.github.lime3ds.android.activities.EmulationActivity /** * ViewModel abstraction for an Item in the RecyclerView powering SettingsFragments. @@ -23,7 +24,7 @@ abstract class SettingsItem( val isEditable: Boolean get() { - if (!NativeLibrary.isRunning()) return true + if (!EmulationActivity.isRunning()) return true return setting?.isRuntimeEditable ?: false } diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/viewholder/RunnableViewHolder.kt b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/viewholder/RunnableViewHolder.kt index 4ea8202f7..617899d06 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/viewholder/RunnableViewHolder.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/viewholder/RunnableViewHolder.kt @@ -10,6 +10,7 @@ import io.github.lime3ds.android.databinding.ListItemSettingBinding import io.github.lime3ds.android.features.settings.model.view.RunnableSetting import io.github.lime3ds.android.features.settings.model.view.SettingsItem import io.github.lime3ds.android.features.settings.ui.SettingsAdapter +import io.github.lime3ds.android.activities.EmulationActivity class RunnableViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAdapter) : SettingViewHolder(binding.root, adapter) { @@ -44,7 +45,7 @@ class RunnableViewHolder(val binding: ListItemSettingBinding, adapter: SettingsA } override fun onClick(clicked: View) { - if (!setting.isRuntimeRunnable && NativeLibrary.isRunning()) { + if (!setting.isRuntimeRunnable && EmulationActivity.isRunning()) { adapter.onClickDisabledSetting() } else { setting.runnable.invoke()