android: Re-fixed runtime settings not being editable after closing game

This commit is contained in:
Ishan09811 2024-05-26 14:27:12 +05:30 committed by OpenSauce04
parent 849a3046ac
commit c5472c3a9c
3 changed files with 27 additions and 2 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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()