Address feedback

This commit is contained in:
PabloG02 2023-06-05 08:39:49 +02:00
parent 3733187c14
commit 409ff26f02
4 changed files with 28 additions and 19 deletions

View file

@ -275,7 +275,8 @@ class HomeSettingsFragment : Fragment() {
private fun shareLog() { private fun shareLog() {
val file = DocumentFile.fromSingleUri( val file = DocumentFile.fromSingleUri(
mainActivity, DocumentsContract.buildDocumentUri( mainActivity,
DocumentsContract.buildDocumentUri(
DocumentProvider.AUTHORITY, DocumentProvider.AUTHORITY,
"${DocumentProvider.ROOT_ID}/log/yuzu_log.txt" "${DocumentProvider.ROOT_ID}/log/yuzu_log.txt"
) )
@ -287,7 +288,11 @@ class HomeSettingsFragment : Fragment() {
.putExtra(Intent.EXTRA_STREAM, file.uri) .putExtra(Intent.EXTRA_STREAM, file.uri)
startActivity(Intent.createChooser(intent, "Share log")) startActivity(Intent.createChooser(intent, "Share log"))
} else { } else {
Toast.makeText(requireContext(), getText(R.string.share_log_missing), Toast.LENGTH_SHORT).show() Toast.makeText(
requireContext(),
getText(R.string.share_log_missing),
Toast.LENGTH_SHORT
).show()
} }
} }

View file

@ -1,22 +1,24 @@
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
package org.yuzu.yuzu_emu.fragments package org.yuzu.yuzu_emu.fragments
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.yuzu.yuzu_emu.databinding.DialogProgressBarBinding import org.yuzu.yuzu_emu.databinding.DialogProgressBarBinding
import org.yuzu.yuzu_emu.model.TaskViewModel import org.yuzu.yuzu_emu.model.TaskViewModel
import java.io.Serializable
class IndeterminateProgressDialogFragment : DialogFragment() { class IndeterminateProgressDialogFragment : DialogFragment() {
private lateinit var taskViewModel: TaskViewModel private val taskViewModel: TaskViewModel by activityViewModels()
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
taskViewModel = ViewModelProvider(requireActivity())[TaskViewModel::class.java]
val titleId = requireArguments().getInt(TITLE) val titleId = requireArguments().getInt(TITLE)
val progressBinding = DialogProgressBarBinding.inflate(layoutInflater) val progressBinding = DialogProgressBarBinding.inflate(layoutInflater)
@ -42,12 +44,8 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
} }
if (taskViewModel.isRunning.value == false) { if (taskViewModel.isRunning.value == false) {
val task = requireArguments().getSerializable(TASK) as? () -> Any
if (task != null) {
taskViewModel.task = task
taskViewModel.runTask() taskViewModel.runTask()
} }
}
return dialog return dialog
} }
@ -55,16 +53,16 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
const val TAG = "IndeterminateProgressDialogFragment" const val TAG = "IndeterminateProgressDialogFragment"
private const val TITLE = "Title" private const val TITLE = "Title"
private const val TASK = "Task"
fun newInstance( fun newInstance(
activity: AppCompatActivity,
titleId: Int, titleId: Int,
task: () -> Any task: () -> Any
): IndeterminateProgressDialogFragment { ): IndeterminateProgressDialogFragment {
val dialog = IndeterminateProgressDialogFragment() val dialog = IndeterminateProgressDialogFragment()
val args = Bundle() val args = Bundle()
ViewModelProvider(activity)[TaskViewModel::class.java].task = task
args.putInt(TITLE, titleId) args.putInt(TITLE, titleId)
args.putSerializable(TASK, task as Serializable)
dialog.arguments = args dialog.arguments = args
return dialog return dialog
} }

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
package org.yuzu.yuzu_emu.model package org.yuzu.yuzu_emu.model
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
@ -30,7 +33,9 @@ class TaskViewModel : ViewModel() {
} }
fun runTask() { fun runTask() {
if (_isRunning.value == true) return if (_isRunning.value == true) {
return
}
_isRunning.value = true _isRunning.value = true
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {

View file

@ -345,15 +345,15 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
FileUtil.unzip(inputZip, cacheFirmwareDir) FileUtil.unzip(inputZip, cacheFirmwareDir)
val unfilteredNumOfFiles = cacheFirmwareDir.list()?.size ?: -1 val unfilteredNumOfFiles = cacheFirmwareDir.list()?.size ?: -1
val filteredNumOfFiles = cacheFirmwareDir.list(filterNCA)?.size ?: -2 val filteredNumOfFiles = cacheFirmwareDir.list(filterNCA)?.size ?: -2
if (unfilteredNumOfFiles != filteredNumOfFiles) { messageToShow = if (unfilteredNumOfFiles != filteredNumOfFiles) {
messageToShow = MessageDialogFragment.newInstance( MessageDialogFragment.newInstance(
R.string.firmware_installed_failure, R.string.firmware_installed_failure,
R.string.firmware_installed_failure_description R.string.firmware_installed_failure_description
) )
} else { } else {
firmwarePath.deleteRecursively() firmwarePath.deleteRecursively()
cacheFirmwareDir.copyRecursively(firmwarePath, true) cacheFirmwareDir.copyRecursively(firmwarePath, true)
messageToShow = getString(R.string.save_file_imported_success) getString(R.string.save_file_imported_success)
} }
} catch (e: Exception) { } catch (e: Exception) {
messageToShow = getString(R.string.fatal_error) messageToShow = getString(R.string.fatal_error)
@ -364,6 +364,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
} }
IndeterminateProgressDialogFragment.newInstance( IndeterminateProgressDialogFragment.newInstance(
this,
R.string.firmware_installing, R.string.firmware_installing,
task task
).show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG) ).show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG)