|
|
|
@ -32,9 +32,6 @@ import androidx.drawerlayout.widget.DrawerLayout
|
|
|
|
|
import androidx.drawerlayout.widget.DrawerLayout.DrawerListener
|
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
|
import androidx.fragment.app.activityViewModels
|
|
|
|
|
import androidx.lifecycle.Lifecycle
|
|
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
|
import androidx.lifecycle.repeatOnLifecycle
|
|
|
|
|
import androidx.navigation.findNavController
|
|
|
|
|
import androidx.navigation.fragment.navArgs
|
|
|
|
|
import androidx.window.layout.FoldingFeature
|
|
|
|
@ -42,9 +39,6 @@ import androidx.window.layout.WindowInfoTracker
|
|
|
|
|
import androidx.window.layout.WindowLayoutInfo
|
|
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
|
|
import com.google.android.material.slider.Slider
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
import kotlinx.coroutines.flow.collectLatest
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import org.yuzu.yuzu_emu.HomeNavigationDirections
|
|
|
|
|
import org.yuzu.yuzu_emu.NativeLibrary
|
|
|
|
|
import org.yuzu.yuzu_emu.R
|
|
|
|
@ -91,14 +85,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
|
if (context is EmulationActivity) {
|
|
|
|
|
emulationActivity = context
|
|
|
|
|
NativeLibrary.setEmulationActivity(context)
|
|
|
|
|
|
|
|
|
|
lifecycleScope.launch(Dispatchers.Main) {
|
|
|
|
|
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
|
|
|
|
WindowInfoTracker.getOrCreate(context)
|
|
|
|
|
.windowLayoutInfo(context)
|
|
|
|
|
.collect { updateFoldableLayout(context, it) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw IllegalStateException("EmulationFragment must have EmulationActivity parent")
|
|
|
|
|
}
|
|
|
|
@ -169,8 +155,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
|
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)
|
|
|
|
|
if (requireActivity().isFinishing) {
|
|
|
|
@ -351,19 +335,11 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
|
binding.loadingTitle.isSelected = true
|
|
|
|
|
binding.loadingText.isSelected = true
|
|
|
|
|
|
|
|
|
|
viewLifecycleOwner.lifecycleScope.apply {
|
|
|
|
|
launch {
|
|
|
|
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
|
|
|
|
WindowInfoTracker.getOrCreate(requireContext())
|
|
|
|
|
.windowLayoutInfo(requireActivity())
|
|
|
|
|
.collect {
|
|
|
|
|
.windowLayoutInfo(requireActivity()).collect(viewLifecycleOwner) {
|
|
|
|
|
updateFoldableLayout(requireActivity() as EmulationActivity, it)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
launch {
|
|
|
|
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
|
|
|
emulationViewModel.shaderProgress.collectLatest {
|
|
|
|
|
emulationViewModel.shaderProgress.collect(viewLifecycleOwner) {
|
|
|
|
|
if (it > 0 && it != emulationViewModel.totalShaders.value) {
|
|
|
|
|
binding.loadingProgressIndicator.isIndeterminate = false
|
|
|
|
|
|
|
|
|
@ -377,36 +353,16 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
|
binding.loadingProgressIndicator.isIndeterminate = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
launch {
|
|
|
|
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
|
|
|
emulationViewModel.totalShaders.collectLatest {
|
|
|
|
|
emulationViewModel.totalShaders.collect(viewLifecycleOwner) {
|
|
|
|
|
binding.loadingProgressIndicator.max = it
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
launch {
|
|
|
|
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
|
|
|
emulationViewModel.shaderMessage.collectLatest {
|
|
|
|
|
emulationViewModel.shaderMessage.collect(viewLifecycleOwner) {
|
|
|
|
|
if (it.isNotEmpty()) {
|
|
|
|
|
binding.loadingText.text = it
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
launch {
|
|
|
|
|
repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
|
|
|
|
driverViewModel.isInteractionAllowed.collect {
|
|
|
|
|
if (it) {
|
|
|
|
|
startEmulation()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
launch {
|
|
|
|
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
|
|
|
emulationViewModel.emulationStarted.collectLatest {
|
|
|
|
|
|
|
|
|
|
emulationViewModel.emulationStarted.collect(viewLifecycleOwner) {
|
|
|
|
|
if (it) {
|
|
|
|
|
binding.drawerLayout.setDrawerLockMode(IntSetting.LOCK_DRAWER.getInt())
|
|
|
|
|
ViewUtils.showView(binding.surfaceInputOverlay)
|
|
|
|
@ -419,11 +375,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
|
updateThermalOverlay()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
launch {
|
|
|
|
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
|
|
|
emulationViewModel.isEmulationStopping.collectLatest {
|
|
|
|
|
emulationViewModel.isEmulationStopping.collect(viewLifecycleOwner) {
|
|
|
|
|
if (it) {
|
|
|
|
|
binding.loadingText.setText(R.string.shutting_down)
|
|
|
|
|
ViewUtils.showView(binding.loadingIndicator)
|
|
|
|
@ -431,11 +383,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
|
ViewUtils.hideView(binding.showFpsText)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
launch {
|
|
|
|
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
|
|
|
emulationViewModel.drawerOpen.collect {
|
|
|
|
|
emulationViewModel.drawerOpen.collect(viewLifecycleOwner) {
|
|
|
|
|
if (it) {
|
|
|
|
|
binding.drawerLayout.open()
|
|
|
|
|
binding.inGameMenu.requestFocus()
|
|
|
|
@ -443,11 +391,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
|
binding.drawerLayout.close()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
launch {
|
|
|
|
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
|
|
|
emulationViewModel.programChanged.collect {
|
|
|
|
|
emulationViewModel.programChanged.collect(viewLifecycleOwner) {
|
|
|
|
|
if (it != 0) {
|
|
|
|
|
emulationViewModel.setEmulationStarted(false)
|
|
|
|
|
binding.drawerLayout.close()
|
|
|
|
@ -457,11 +401,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
|
ViewUtils.showView(binding.loadingIndicator)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
launch {
|
|
|
|
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
|
|
|
emulationViewModel.emulationStopped.collect {
|
|
|
|
|
emulationViewModel.emulationStopped.collect(viewLifecycleOwner) {
|
|
|
|
|
if (it && emulationViewModel.programChanged.value != -1) {
|
|
|
|
|
if (perfStatsUpdater != null) {
|
|
|
|
|
perfStatsUpdateHandler.removeCallbacks(perfStatsUpdater!!)
|
|
|
|
@ -471,8 +411,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
|
emulationViewModel.setEmulationStopped(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
driverViewModel.isInteractionAllowed.collect(viewLifecycleOwner) {
|
|
|
|
|
if (it) startEmulation()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|