diff options
Diffstat (limited to 'src')
4 files changed, 65 insertions, 2 deletions
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.kt index ca353cea7..d6f17cf29 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.LayoutInflater | |||
| 8 | import android.view.View | 8 | import android.view.View |
| 9 | import android.view.ViewGroup | 9 | import android.view.ViewGroup |
| 10 | import org.yuzu.yuzu_emu.databinding.CardDriverOptionBinding | 10 | import org.yuzu.yuzu_emu.databinding.CardDriverOptionBinding |
| 11 | import org.yuzu.yuzu_emu.features.settings.model.StringSetting | ||
| 11 | import org.yuzu.yuzu_emu.model.Driver | 12 | import org.yuzu.yuzu_emu.model.Driver |
| 12 | import org.yuzu.yuzu_emu.model.DriverViewModel | 13 | import org.yuzu.yuzu_emu.model.DriverViewModel |
| 13 | import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder | 14 | import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder |
| @@ -27,13 +28,17 @@ class DriverAdapter(private val driverViewModel: DriverViewModel) : | |||
| 27 | binding.apply { | 28 | binding.apply { |
| 28 | radioButton.isChecked = model.selected | 29 | radioButton.isChecked = model.selected |
| 29 | root.setOnClickListener { | 30 | root.setOnClickListener { |
| 30 | selectItem(bindingAdapterPosition) { driverViewModel.onDriverSelected(it) } | 31 | selectItem(bindingAdapterPosition) { |
| 32 | driverViewModel.onDriverSelected(it) | ||
| 33 | driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global) | ||
| 34 | } | ||
| 31 | } | 35 | } |
| 32 | buttonDelete.setOnClickListener { | 36 | buttonDelete.setOnClickListener { |
| 33 | removeSelectableItem( | 37 | removeSelectableItem( |
| 34 | bindingAdapterPosition | 38 | bindingAdapterPosition |
| 35 | ) { removedPosition: Int, selectedPosition: Int -> | 39 | ) { removedPosition: Int, selectedPosition: Int -> |
| 36 | driverViewModel.onDriverRemoved(removedPosition, selectedPosition) | 40 | driverViewModel.onDriverRemoved(removedPosition, selectedPosition) |
| 41 | driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global) | ||
| 37 | } | 42 | } |
| 38 | } | 43 | } |
| 39 | 44 | ||
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.kt index 82c966954..c01fdff25 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 @@ | |||
| 3 | 3 | ||
| 4 | package org.yuzu.yuzu_emu.fragments | 4 | package org.yuzu.yuzu_emu.fragments |
| 5 | 5 | ||
| 6 | import android.annotation.SuppressLint | ||
| 6 | import android.os.Bundle | 7 | import android.os.Bundle |
| 7 | import android.view.LayoutInflater | 8 | import android.view.LayoutInflater |
| 8 | import android.view.View | 9 | import android.view.View |
| @@ -13,20 +14,26 @@ import androidx.core.view.WindowInsetsCompat | |||
| 13 | import androidx.core.view.updatePadding | 14 | import androidx.core.view.updatePadding |
| 14 | import androidx.fragment.app.Fragment | 15 | import androidx.fragment.app.Fragment |
| 15 | import androidx.fragment.app.activityViewModels | 16 | import androidx.fragment.app.activityViewModels |
| 17 | import androidx.lifecycle.Lifecycle | ||
| 18 | import androidx.lifecycle.lifecycleScope | ||
| 19 | import androidx.lifecycle.repeatOnLifecycle | ||
| 16 | import androidx.navigation.findNavController | 20 | import androidx.navigation.findNavController |
| 17 | import androidx.navigation.fragment.navArgs | 21 | import androidx.navigation.fragment.navArgs |
| 18 | import androidx.recyclerview.widget.GridLayoutManager | 22 | import androidx.recyclerview.widget.GridLayoutManager |
| 19 | import com.google.android.material.transition.MaterialSharedAxis | 23 | import com.google.android.material.transition.MaterialSharedAxis |
| 20 | import kotlinx.coroutines.Dispatchers | 24 | import kotlinx.coroutines.Dispatchers |
| 25 | import kotlinx.coroutines.launch | ||
| 21 | import kotlinx.coroutines.withContext | 26 | import kotlinx.coroutines.withContext |
| 22 | import org.yuzu.yuzu_emu.R | 27 | import org.yuzu.yuzu_emu.R |
| 23 | import org.yuzu.yuzu_emu.adapters.DriverAdapter | 28 | import org.yuzu.yuzu_emu.adapters.DriverAdapter |
| 24 | import org.yuzu.yuzu_emu.databinding.FragmentDriverManagerBinding | 29 | import org.yuzu.yuzu_emu.databinding.FragmentDriverManagerBinding |
| 30 | import org.yuzu.yuzu_emu.features.settings.model.StringSetting | ||
| 25 | import org.yuzu.yuzu_emu.model.Driver.Companion.toDriver | 31 | import org.yuzu.yuzu_emu.model.Driver.Companion.toDriver |
| 26 | import org.yuzu.yuzu_emu.model.DriverViewModel | 32 | import org.yuzu.yuzu_emu.model.DriverViewModel |
| 27 | import org.yuzu.yuzu_emu.model.HomeViewModel | 33 | import org.yuzu.yuzu_emu.model.HomeViewModel |
| 28 | import org.yuzu.yuzu_emu.utils.FileUtil | 34 | import org.yuzu.yuzu_emu.utils.FileUtil |
| 29 | import org.yuzu.yuzu_emu.utils.GpuDriverHelper | 35 | import org.yuzu.yuzu_emu.utils.GpuDriverHelper |
| 36 | import org.yuzu.yuzu_emu.utils.NativeConfig | ||
| 30 | import java.io.File | 37 | import java.io.File |
| 31 | import java.io.IOException | 38 | import java.io.IOException |
| 32 | 39 | ||
| @@ -55,12 +62,43 @@ class DriverManagerFragment : Fragment() { | |||
| 55 | return binding.root | 62 | return binding.root |
| 56 | } | 63 | } |
| 57 | 64 | ||
| 65 | // This is using the correct scope, lint is just acting up | ||
| 66 | @SuppressLint("UnsafeRepeatOnLifecycleDetector") | ||
| 58 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | 67 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
| 59 | super.onViewCreated(view, savedInstanceState) | 68 | super.onViewCreated(view, savedInstanceState) |
| 60 | homeViewModel.setNavigationVisibility(visible = false, animated = true) | 69 | homeViewModel.setNavigationVisibility(visible = false, animated = true) |
| 61 | homeViewModel.setStatusBarShadeVisibility(visible = false) | 70 | homeViewModel.setStatusBarShadeVisibility(visible = false) |
| 62 | 71 | ||
| 63 | driverViewModel.onOpenDriverManager(args.game) | 72 | driverViewModel.onOpenDriverManager(args.game) |
| 73 | if (NativeConfig.isPerGameConfigLoaded()) { | ||
| 74 | binding.toolbarDrivers.inflateMenu(R.menu.menu_driver_manager) | ||
| 75 | driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global) | ||
| 76 | binding.toolbarDrivers.setOnMenuItemClickListener { | ||
| 77 | when (it.itemId) { | ||
| 78 | R.id.menu_driver_clear -> { | ||
| 79 | StringSetting.DRIVER_PATH.global = true | ||
| 80 | driverViewModel.updateDriverList() | ||
| 81 | (binding.listDrivers.adapter as DriverAdapter) | ||
| 82 | .replaceList(driverViewModel.driverList.value) | ||
| 83 | driverViewModel.showClearButton(false) | ||
| 84 | true | ||
| 85 | } | ||
| 86 | |||
| 87 | else -> false | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | viewLifecycleOwner.lifecycleScope.apply { | ||
| 92 | launch { | ||
| 93 | repeatOnLifecycle(Lifecycle.State.STARTED) { | ||
| 94 | driverViewModel.showClearButton.collect { | ||
| 95 | binding.toolbarDrivers.menu | ||
| 96 | .findItem(R.id.menu_driver_clear).isVisible = it | ||
| 97 | } | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | } | ||
| 64 | 102 | ||
| 65 | if (!driverViewModel.isInteractionAllowed.value) { | 103 | if (!driverViewModel.isInteractionAllowed.value) { |
| 66 | DriversLoadingDialogFragment().show( | 104 | DriversLoadingDialogFragment().show( |
| @@ -168,6 +206,7 @@ class DriverManagerFragment : Fragment() { | |||
| 168 | val adapter = binding.listDrivers.adapter as DriverAdapter | 206 | val adapter = binding.listDrivers.adapter as DriverAdapter |
| 169 | adapter.addItem(driverData.toDriver()) | 207 | adapter.addItem(driverData.toDriver()) |
| 170 | adapter.selectItem(adapter.currentList.indices.last) | 208 | adapter.selectItem(adapter.currentList.indices.last) |
| 209 | driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global) | ||
| 171 | binding.listDrivers | 210 | binding.listDrivers |
| 172 | .smoothScrollToPosition(adapter.currentList.indices.last) | 211 | .smoothScrollToPosition(adapter.currentList.indices.last) |
| 173 | } | 212 | } |
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.kt index a1fee48cc..15ae3a42b 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.Dispatchers | |||
| 9 | import kotlinx.coroutines.flow.MutableStateFlow | 9 | import kotlinx.coroutines.flow.MutableStateFlow |
| 10 | import kotlinx.coroutines.flow.SharingStarted | 10 | import kotlinx.coroutines.flow.SharingStarted |
| 11 | import kotlinx.coroutines.flow.StateFlow | 11 | import kotlinx.coroutines.flow.StateFlow |
| 12 | import kotlinx.coroutines.flow.asStateFlow | ||
| 12 | import kotlinx.coroutines.flow.combine | 13 | import kotlinx.coroutines.flow.combine |
| 13 | import kotlinx.coroutines.flow.stateIn | 14 | import kotlinx.coroutines.flow.stateIn |
| 14 | import kotlinx.coroutines.launch | 15 | import kotlinx.coroutines.launch |
| @@ -46,6 +47,9 @@ class DriverViewModel : ViewModel() { | |||
| 46 | private val _selectedDriverTitle = MutableStateFlow("") | 47 | private val _selectedDriverTitle = MutableStateFlow("") |
| 47 | val selectedDriverTitle: StateFlow<String> get() = _selectedDriverTitle | 48 | val selectedDriverTitle: StateFlow<String> get() = _selectedDriverTitle |
| 48 | 49 | ||
| 50 | private val _showClearButton = MutableStateFlow(false) | ||
| 51 | val showClearButton = _showClearButton.asStateFlow() | ||
| 52 | |||
| 49 | private val driversToDelete = mutableListOf<String>() | 53 | private val driversToDelete = mutableListOf<String>() |
| 50 | 54 | ||
| 51 | init { | 55 | init { |
| @@ -60,7 +64,7 @@ class DriverViewModel : ViewModel() { | |||
| 60 | _areDriversLoading.value = false | 64 | _areDriversLoading.value = false |
| 61 | } | 65 | } |
| 62 | 66 | ||
| 63 | private fun updateDriverList() { | 67 | fun updateDriverList() { |
| 64 | val selectedDriver = GpuDriverHelper.customDriverSettingData | 68 | val selectedDriver = GpuDriverHelper.customDriverSettingData |
| 65 | val newDriverList = mutableListOf( | 69 | val newDriverList = mutableListOf( |
| 66 | Driver( | 70 | Driver( |
| @@ -81,6 +85,10 @@ class DriverViewModel : ViewModel() { | |||
| 81 | updateDriverList() | 85 | updateDriverList() |
| 82 | } | 86 | } |
| 83 | 87 | ||
| 88 | fun showClearButton(value: Boolean) { | ||
| 89 | _showClearButton.value = value | ||
| 90 | } | ||
| 91 | |||
| 84 | fun onDriverSelected(position: Int) { | 92 | fun onDriverSelected(position: Int) { |
| 85 | if (position == 0) { | 93 | if (position == 0) { |
| 86 | StringSetting.DRIVER_PATH.setString("") | 94 | 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.xml new file mode 100644 index 000000000..dee5d57b6 --- /dev/null +++ b/src/android/app/src/main/res/menu/menu_driver_manager.xml | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | <menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
| 4 | |||
| 5 | <item | ||
| 6 | android:id="@+id/menu_driver_clear" | ||
| 7 | android:icon="@drawable/ic_clear" | ||
| 8 | android:title="@string/clear" | ||
| 9 | app:showAsAction="always" /> | ||
| 10 | |||
| 11 | </menu> | ||