Skip to content

Commit

Permalink
Android: fix non runtime runnable settings bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan09811 authored and Gamer64ytb committed Jul 26, 2024
1 parent 724d713 commit 1ec5277
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class EmulationActivity : AppCompatActivity() {
private lateinit var screenAdjustmentUtil: ScreenAdjustmentUtil
private lateinit var hotkeyUtility: HotkeyUtility

private var isEmulationRunning: Boolean = false

private val emulationFragment: EmulationFragment
get() {
val navHostFragment =
Expand Down Expand Up @@ -94,6 +96,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
Expand All @@ -114,9 +119,21 @@ 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() {
NativeLibrary.enableAdrenoTurboMode(false)
EmulationLifecycleUtil.clear()
isEmulationRunning = false
instance = null
super.onDestroy()
}

Expand Down Expand Up @@ -458,4 +475,12 @@ class EmulationActivity : AppCompatActivity() {

OnFilePickerResult(result.toString())
}

companion object {
private var instance: EmulationActivity? = null

fun isRunning(): Boolean {
return instance?.isEmulationRunning ?: false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package org.citra.citra_emu.features.settings.model.view

import org.citra.citra_emu.NativeLibrary
import org.citra.citra_emu.features.settings.model.AbstractSetting
import org.citra.citra_emu.activities.EmulationActivity

/**
* ViewModel abstraction for an Item in the RecyclerView powering SettingsFragments.
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.citra.citra_emu.databinding.ListItemSettingBinding
import org.citra.citra_emu.features.settings.model.view.RunnableSetting
import org.citra.citra_emu.features.settings.model.view.SettingsItem
import org.citra.citra_emu.features.settings.ui.SettingsAdapter
import org.citra.citra_emu.activities.EmulationActivity

class RunnableViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAdapter) :
SettingViewHolder(binding.root, adapter) {
Expand Down Expand Up @@ -58,10 +59,10 @@ class RunnableViewHolder(val binding: ListItemSettingBinding, adapter: SettingsA
}

override fun onClick(clicked: View) {
if (!setting.isRuntimeRunnable && !NativeLibrary.isRunning()) {
setting.runnable.invoke()
} else {
if (!setting.isRuntimeRunnable && EmulationActivity.isRunning()) {
adapter.onClickDisabledSetting()
} else {
setting.runnable.invoke()
}
}

Expand Down

0 comments on commit 1ec5277

Please sign in to comment.