mirror of https://git.suyu.dev/suyu/suyu
android: Game loading/shutting down indicators
parent
270f430f70
commit
b0a96d5216
@ -1,31 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.yuzu.yuzu_emu.disk_shader_cache
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class ShaderProgressViewModel : ViewModel() {
|
||||
private val _progress = MutableLiveData(0)
|
||||
val progress: LiveData<Int> get() = _progress
|
||||
|
||||
private val _max = MutableLiveData(0)
|
||||
val max: LiveData<Int> get() = _max
|
||||
|
||||
private val _message = MutableLiveData("")
|
||||
val message: LiveData<String> get() = _message
|
||||
|
||||
fun setProgress(progress: Int) {
|
||||
_progress.postValue(progress)
|
||||
}
|
||||
|
||||
fun setMax(max: Int) {
|
||||
_max.postValue(max)
|
||||
}
|
||||
|
||||
fun setMessage(msg: String) {
|
||||
_message.postValue(msg)
|
||||
}
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.yuzu.yuzu_emu.disk_shader_cache.ui
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import org.yuzu.yuzu_emu.databinding.DialogProgressBarBinding
|
||||
import org.yuzu.yuzu_emu.disk_shader_cache.DiskShaderCacheProgress
|
||||
import org.yuzu.yuzu_emu.disk_shader_cache.ShaderProgressViewModel
|
||||
|
||||
class ShaderProgressDialogFragment : DialogFragment() {
|
||||
private var _binding: DialogProgressBarBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private lateinit var alertDialog: AlertDialog
|
||||
|
||||
private lateinit var shaderProgressViewModel: ShaderProgressViewModel
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
_binding = DialogProgressBarBinding.inflate(layoutInflater)
|
||||
shaderProgressViewModel =
|
||||
ViewModelProvider(requireActivity())[ShaderProgressViewModel::class.java]
|
||||
|
||||
val title = requireArguments().getString(TITLE)
|
||||
val message = requireArguments().getString(MESSAGE)
|
||||
|
||||
isCancelable = false
|
||||
alertDialog = MaterialAlertDialogBuilder(requireActivity())
|
||||
.setView(binding.root)
|
||||
.setTitle(title)
|
||||
.setMessage(message)
|
||||
.create()
|
||||
return alertDialog
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
shaderProgressViewModel.progress.observe(viewLifecycleOwner) { progress ->
|
||||
binding.progressBar.progress = progress
|
||||
setUpdateText()
|
||||
}
|
||||
shaderProgressViewModel.max.observe(viewLifecycleOwner) { max ->
|
||||
binding.progressBar.max = max
|
||||
setUpdateText()
|
||||
}
|
||||
shaderProgressViewModel.message.observe(viewLifecycleOwner) { msg ->
|
||||
alertDialog.setMessage(msg)
|
||||
}
|
||||
synchronized(DiskShaderCacheProgress.finishLock) {
|
||||
DiskShaderCacheProgress.finishLock.notifyAll()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
fun onUpdateProgress(msg: String, progress: Int, max: Int) {
|
||||
shaderProgressViewModel.setProgress(progress)
|
||||
shaderProgressViewModel.setMax(max)
|
||||
shaderProgressViewModel.setMessage(msg)
|
||||
}
|
||||
|
||||
private fun setUpdateText() {
|
||||
binding.progressText.text = String.format(
|
||||
"%d/%d",
|
||||
shaderProgressViewModel.progress.value,
|
||||
shaderProgressViewModel.max.value
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "ProgressDialogFragment"
|
||||
const val TITLE = "title"
|
||||
const val MESSAGE = "message"
|
||||
|
||||
fun newInstance(title: String, message: String): ShaderProgressDialogFragment {
|
||||
val frag = ShaderProgressDialogFragment()
|
||||
val args = Bundle()
|
||||
args.putString(TITLE, title)
|
||||
args.putString(MESSAGE, message)
|
||||
frag.arguments = args
|
||||
return frag
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package org.yuzu.yuzu_emu.model
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class EmulationViewModel : ViewModel() {
|
||||
private val _emulationStarted = MutableLiveData(false)
|
||||
val emulationStarted: LiveData<Boolean> get() = _emulationStarted
|
||||
|
||||
private val _isEmulationStopping = MutableLiveData(false)
|
||||
val isEmulationStopping: LiveData<Boolean> get() = _isEmulationStopping
|
||||
|
||||
private val _shaderProgress = MutableLiveData(0)
|
||||
val shaderProgress: LiveData<Int> get() = _shaderProgress
|
||||
|
||||
private val _totalShaders = MutableLiveData(0)
|
||||
val totalShaders: LiveData<Int> get() = _totalShaders
|
||||
|
||||
private val _shaderMessage = MutableLiveData("")
|
||||
val shaderMessage: LiveData<String> get() = _shaderMessage
|
||||
|
||||
fun setEmulationStarted(started: Boolean) {
|
||||
_emulationStarted.postValue(started)
|
||||
}
|
||||
|
||||
fun setIsEmulationStopping(value: Boolean) {
|
||||
_isEmulationStopping.value = value
|
||||
}
|
||||
|
||||
fun setShaderProgress(progress: Int) {
|
||||
_shaderProgress.value = progress
|
||||
}
|
||||
|
||||
fun setTotalShaders(max: Int) {
|
||||
_totalShaders.value = max
|
||||
}
|
||||
|
||||
fun setShaderMessage(msg: String) {
|
||||
_shaderMessage.value = msg
|
||||
}
|
||||
|
||||
fun updateProgress(msg: String, progress: Int, max: Int) {
|
||||
setShaderMessage(msg)
|
||||
setShaderProgress(progress)
|
||||
setTotalShaders(max)
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
_emulationStarted.value = false
|
||||
_isEmulationStopping.value = false
|
||||
_shaderProgress.value = 0
|
||||
_totalShaders.value = 0
|
||||
_shaderMessage.value = ""
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue