VERY experimental Nintendo Switch 2 emulator
C++
android: Add button to use global driver value
t895a4bbbed9d50f
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/DriverAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/DriverAdapter.ktindex ca353cea73..d6f17cf29b 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/DriverAdapter.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/DriverAdapter.kt@@ -8,6 +8,7 @@ import android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport org.yuzu.yuzu_emu.databinding.CardDriverOptionBinding+import org.yuzu.yuzu_emu.features.settings.model.StringSettingimport org.yuzu.yuzu_emu.model.Driverimport org.yuzu.yuzu_emu.model.DriverViewModelimport org.yuzu.yuzu_emu.viewholder.AbstractViewHolder@@ -27,13 +28,17 @@ class DriverAdapter(private val driverViewModel: DriverViewModel) :binding.apply {radioButton.isChecked = model.selectedroot.setOnClickListener {- selectItem(bindingAdapterPosition) { driverViewModel.onDriverSelected(it) }+ selectItem(bindingAdapterPosition) {+ driverViewModel.onDriverSelected(it)+ driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global)+ }}buttonDelete.setOnClickListener {removeSelectableItem(bindingAdapterPosition) { removedPosition: Int, selectedPosition: Int ->driverViewModel.onDriverRemoved(removedPosition, selectedPosition)+ driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global)}}diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/DriverManagerFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/DriverManagerFragment.ktindex 82c966954a..c01fdff254 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/DriverManagerFragment.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/DriverManagerFragment.kt@@ -3,6 +3,7 @@package org.yuzu.yuzu_emu.fragments+import android.annotation.SuppressLintimport android.os.Bundleimport android.view.LayoutInflaterimport android.view.View@@ -13,20 +14,26 @@ import androidx.core.view.WindowInsetsCompatimport androidx.core.view.updatePaddingimport androidx.fragment.app.Fragmentimport androidx.fragment.app.activityViewModels+import androidx.lifecycle.Lifecycle+import androidx.lifecycle.lifecycleScope+import androidx.lifecycle.repeatOnLifecycleimport androidx.navigation.findNavControllerimport androidx.navigation.fragment.navArgsimport androidx.recyclerview.widget.GridLayoutManagerimport com.google.android.material.transition.MaterialSharedAxisimport kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.launchimport kotlinx.coroutines.withContextimport org.yuzu.yuzu_emu.Rimport org.yuzu.yuzu_emu.adapters.DriverAdapterimport org.yuzu.yuzu_emu.databinding.FragmentDriverManagerBinding+import org.yuzu.yuzu_emu.features.settings.model.StringSettingimport org.yuzu.yuzu_emu.model.Driver.Companion.toDriverimport org.yuzu.yuzu_emu.model.DriverViewModelimport org.yuzu.yuzu_emu.model.HomeViewModelimport org.yuzu.yuzu_emu.utils.FileUtilimport org.yuzu.yuzu_emu.utils.GpuDriverHelper+import org.yuzu.yuzu_emu.utils.NativeConfigimport java.io.Fileimport java.io.IOException@@ -55,12 +62,43 @@ class DriverManagerFragment : Fragment() {return binding.root}+ // This is using the correct scope, lint is just acting up+ @SuppressLint("UnsafeRepeatOnLifecycleDetector")override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)homeViewModel.setNavigationVisibility(visible = false, animated = true)homeViewModel.setStatusBarShadeVisibility(visible = false)driverViewModel.onOpenDriverManager(args.game)+ if (NativeConfig.isPerGameConfigLoaded()) {+ binding.toolbarDrivers.inflateMenu(R.menu.menu_driver_manager)+ driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global)+ binding.toolbarDrivers.setOnMenuItemClickListener {+ when (it.itemId) {+ R.id.menu_driver_clear -> {+ StringSetting.DRIVER_PATH.global = true+ driverViewModel.updateDriverList()+ (binding.listDrivers.adapter as DriverAdapter)+ .replaceList(driverViewModel.driverList.value)+ driverViewModel.showClearButton(false)+ true+ }++ else -> false+ }+ }++ viewLifecycleOwner.lifecycleScope.apply {+ launch {+ repeatOnLifecycle(Lifecycle.State.STARTED) {+ driverViewModel.showClearButton.collect {+ binding.toolbarDrivers.menu+ .findItem(R.id.menu_driver_clear).isVisible = it+ }+ }+ }+ }+ }if (!driverViewModel.isInteractionAllowed.value) {DriversLoadingDialogFragment().show(@@ -168,6 +206,7 @@ class DriverManagerFragment : Fragment() {val adapter = binding.listDrivers.adapter as DriverAdapteradapter.addItem(driverData.toDriver())adapter.selectItem(adapter.currentList.indices.last)+ driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global)binding.listDrivers.smoothScrollToPosition(adapter.currentList.indices.last)}diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.ktindex a1fee48cc0..15ae3a42b4 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt@@ -9,6 +9,7 @@ import kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.flow.MutableStateFlowimport kotlinx.coroutines.flow.SharingStartedimport kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.asStateFlowimport kotlinx.coroutines.flow.combineimport kotlinx.coroutines.flow.stateInimport kotlinx.coroutines.launch@@ -46,6 +47,9 @@ class DriverViewModel : ViewModel() {private val _selectedDriverTitle = MutableStateFlow("")val selectedDriverTitle: StateFlow<String> get() = _selectedDriverTitle+ private val _showClearButton = MutableStateFlow(false)+ val showClearButton = _showClearButton.asStateFlow()+private val driversToDelete = mutableListOf<String>()init {@@ -60,7 +64,7 @@ class DriverViewModel : ViewModel() {_areDriversLoading.value = false}- private fun updateDriverList() {+ fun updateDriverList() {val selectedDriver = GpuDriverHelper.customDriverSettingDataval newDriverList = mutableListOf(Driver(@@ -81,6 +85,10 @@ class DriverViewModel : ViewModel() {updateDriverList()}+ fun showClearButton(value: Boolean) {+ _showClearButton.value = value+ }+fun onDriverSelected(position: Int) {if (position == 0) {StringSetting.DRIVER_PATH.setString("")diff --git a/src/android/app/src/main/res/menu/menu_driver_manager.xml b/src/android/app/src/main/res/menu/menu_driver_manager.xmlnew file mode 100644index 0000000000..dee5d57b65--- /dev/null+++ b/src/android/app/src/main/res/menu/menu_driver_manager.xml@@ -0,0 +1,11 @@+<?xml version="1.0" encoding="utf-8"?>+<menu xmlns:android="http://schemas.android.com/apk/res/android"+ xmlns:app="http://schemas.android.com/apk/res-auto">++ <item+ android:id="@+id/menu_driver_clear"+ android:icon="@drawable/ic_clear"+ android:title="@string/clear"+ app:showAsAction="always" />++</menu>