|
|
@ -19,12 +19,13 @@ import androidx.lifecycle.repeatOnLifecycle
|
|
|
|
import androidx.navigation.fragment.NavHostFragment
|
|
|
|
import androidx.navigation.fragment.NavHostFragment
|
|
|
|
import androidx.navigation.navArgs
|
|
|
|
import androidx.navigation.navArgs
|
|
|
|
import com.google.android.material.color.MaterialColors
|
|
|
|
import com.google.android.material.color.MaterialColors
|
|
|
|
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.flow.collectLatest
|
|
|
|
import kotlinx.coroutines.flow.collectLatest
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import java.io.IOException
|
|
|
|
import java.io.IOException
|
|
|
|
import org.yuzu.yuzu_emu.R
|
|
|
|
import org.yuzu.yuzu_emu.R
|
|
|
|
import org.yuzu.yuzu_emu.databinding.ActivitySettingsBinding
|
|
|
|
import org.yuzu.yuzu_emu.databinding.ActivitySettingsBinding
|
|
|
|
import org.yuzu.yuzu_emu.features.settings.model.Settings
|
|
|
|
|
|
|
|
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
|
|
|
|
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
|
|
|
|
import org.yuzu.yuzu_emu.fragments.ResetSettingsDialogFragment
|
|
|
|
import org.yuzu.yuzu_emu.fragments.ResetSettingsDialogFragment
|
|
|
|
import org.yuzu.yuzu_emu.model.SettingsViewModel
|
|
|
|
import org.yuzu.yuzu_emu.model.SettingsViewModel
|
|
|
@ -53,10 +54,6 @@ class SettingsActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
|
|
|
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
|
|
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
|
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
|
|
|
|
settingsViewModel.shouldSave = savedInstanceState.getBoolean(KEY_SHOULD_SAVE)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (InsetsHelper.getSystemGestureType(applicationContext) !=
|
|
|
|
if (InsetsHelper.getSystemGestureType(applicationContext) !=
|
|
|
|
InsetsHelper.GESTURE_NAVIGATION
|
|
|
|
InsetsHelper.GESTURE_NAVIGATION
|
|
|
|
) {
|
|
|
|
) {
|
|
|
@ -127,12 +124,6 @@ class SettingsActivity : AppCompatActivity() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onSaveInstanceState(outState: Bundle) {
|
|
|
|
|
|
|
|
// Critical: If super method is not called, rotations will be busted.
|
|
|
|
|
|
|
|
super.onSaveInstanceState(outState)
|
|
|
|
|
|
|
|
outState.putBoolean(KEY_SHOULD_SAVE, settingsViewModel.shouldSave)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onStart() {
|
|
|
|
override fun onStart() {
|
|
|
|
super.onStart()
|
|
|
|
super.onStart()
|
|
|
|
// TODO: Load custom settings contextually
|
|
|
|
// TODO: Load custom settings contextually
|
|
|
@ -141,16 +132,10 @@ class SettingsActivity : AppCompatActivity() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* If this is called, the user has left the settings screen (potentially through the
|
|
|
|
|
|
|
|
* home button) and will expect their changes to be persisted. So we kick off an
|
|
|
|
|
|
|
|
* IntentService which will do so on a background thread.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
override fun onStop() {
|
|
|
|
override fun onStop() {
|
|
|
|
super.onStop()
|
|
|
|
super.onStop()
|
|
|
|
if (isFinishing && settingsViewModel.shouldSave) {
|
|
|
|
CoroutineScope(Dispatchers.IO).launch {
|
|
|
|
Log.debug("[SettingsActivity] Settings activity stopping. Saving settings to INI...")
|
|
|
|
NativeConfig.saveSettings()
|
|
|
|
Settings.saveSettings()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -160,9 +145,6 @@ class SettingsActivity : AppCompatActivity() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun onSettingsReset() {
|
|
|
|
fun onSettingsReset() {
|
|
|
|
// Prevents saving to a non-existent settings file
|
|
|
|
|
|
|
|
settingsViewModel.shouldSave = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Delete settings file because the user may have changed values that do not exist in the UI
|
|
|
|
// Delete settings file because the user may have changed values that do not exist in the UI
|
|
|
|
NativeConfig.unloadConfig()
|
|
|
|
NativeConfig.unloadConfig()
|
|
|
|
val settingsFile = SettingsFile.getSettingsFile(SettingsFile.FILE_NAME_CONFIG)
|
|
|
|
val settingsFile = SettingsFile.getSettingsFile(SettingsFile.FILE_NAME_CONFIG)
|
|
|
@ -194,8 +176,4 @@ class SettingsActivity : AppCompatActivity() {
|
|
|
|
windowInsets
|
|
|
|
windowInsets
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
private const val KEY_SHOULD_SAVE = "should_save"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|